diff options
author | Mike Buland <eichlan@xagasoft.com> | 2008-09-15 20:03:56 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2008-09-15 20:03:56 +0000 |
commit | 597a1487c716b799428f4b4a4903e65df4c93ba9 (patch) | |
tree | c743b0d4dfc3bacbffc196589543ec4e9abf1aaf /src/nids.cpp | |
parent | 3c6cb7f2347aed974543f9082a0ccd297577db41 (diff) | |
download | libbu++-597a1487c716b799428f4b4a4903e65df4c93ba9.tar.gz libbu++-597a1487c716b799428f4b4a4903e65df4c93ba9.tar.bz2 libbu++-597a1487c716b799428f4b4a4903e65df4c93ba9.tar.xz libbu++-597a1487c716b799428f4b4a4903e65df4c93ba9.zip |
Whoa! Loads of NIDS work. It actually compiles, runs, and I'm optimizing the
hell out of it. Good times, everyone. This is a major chunk for congo, and
the new optimizations should be good.
Diffstat (limited to 'src/nids.cpp')
-rw-r--r-- | src/nids.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/nids.cpp b/src/nids.cpp index b8ea13b..41c4dc1 100644 --- a/src/nids.cpp +++ b/src/nids.cpp | |||
@@ -1,8 +1,30 @@ | |||
1 | #include "bu/nids.h" | 1 | #include "bu/nids.h" |
2 | #include "bu/stream.h" | ||
3 | #include "bu/nidsstream.h" | ||
4 | #include <stdio.h> | ||
2 | 5 | ||
3 | Bu::Nids::Nids( Bu::Stream &sStore ) : | 6 | Bu::Nids::Nids( Bu::Stream &sStore ) : |
4 | sStore( sStore ) | 7 | sStore( sStore ) |
5 | { | 8 | { |
9 | printf("Stream caps:\n" | ||
10 | " canRead: %s\n" | ||
11 | " canWrite: %s\n" | ||
12 | " isReadable: %s\n" | ||
13 | " isWritable: %s\n" | ||
14 | " isSeekable: %s\n" | ||
15 | " isBlocking: %s\n" | ||
16 | " isEOS: %s\n" | ||
17 | " isOpen: %s\n", | ||
18 | sStore.canRead()?"yes":"no", | ||
19 | sStore.canWrite()?"yes":"no", | ||
20 | sStore.isReadable()?"yes":"no", | ||
21 | sStore.isWritable()?"yes":"no", | ||
22 | sStore.isSeekable()?"yes":"no", | ||
23 | sStore.isBlocking()?"yes":"no", | ||
24 | sStore.isEOS()?"yes":"no", | ||
25 | sStore.isOpen()?"yes":"no" | ||
26 | ); | ||
27 | printf("sizeof(Block) = %db\n", sizeof(Block) ); | ||
6 | } | 28 | } |
7 | 29 | ||
8 | Bu::Nids::~Nids() | 30 | Bu::Nids::~Nids() |
@@ -11,11 +33,82 @@ Bu::Nids::~Nids() | |||
11 | 33 | ||
12 | void Bu::Nids::initialize( int iBlockSize, int iPreAllocate ) | 34 | void Bu::Nids::initialize( int iBlockSize, int iPreAllocate ) |
13 | { | 35 | { |
36 | char cBuf = 0; | ||
37 | int iBuf = 0; | ||
38 | |||
39 | // Magic number | ||
40 | sStore.write( "\xFF\xC3\x99\xBD", 4 ); | ||
41 | |||
42 | // Version (0) | ||
43 | sStore.write( &cBuf, 1 ); | ||
44 | |||
45 | // Bytes per int | ||
46 | cBuf = 4; | ||
47 | sStore.write( &cBuf, 1 ); | ||
48 | |||
49 | // The size of each block and the number of blocks we're pre-allocating | ||
50 | sStore.write( &iBlockSize, 4 ); | ||
51 | sStore.write( &iPreAllocate, 4 ); | ||
52 | |||
53 | // The number of used blocks | ||
54 | sStore.write( &iBuf, 4 ); | ||
55 | |||
56 | // Reserved space | ||
57 | sStore.write( "\x00\x00\x00\x00\x00\x00\x00", 7 ); | ||
58 | |||
59 | this->iBlockSize = iBlockSize; | ||
60 | this->iBlocks = iPreAllocate; | ||
61 | this->iBlockStart = sStore.tell(); | ||
62 | bsBlockUsed.setSize( iPreAllocate, true ); | ||
63 | |||
64 | printf("%d blocks, %db each, %db block offset\n", | ||
65 | iBlocks, iBlockSize, iBlockStart ); | ||
66 | |||
67 | char *block = new char[iBlockSize]; | ||
68 | memset( block, 0, iBlockSize ); | ||
69 | for( int j = 0; j < iPreAllocate; j++ ) | ||
70 | { | ||
71 | sStore.write( block, iBlockSize ); | ||
72 | } | ||
14 | } | 73 | } |
15 | 74 | ||
16 | int Bu::Nids::createStream( int iPreAllocate ) | 75 | int Bu::Nids::createStream( int iPreAllocate ) |
17 | { | 76 | { |
77 | for( int j = 0; j < iBlocks; j++ ) | ||
78 | { | ||
79 | if( !bsBlockUsed.getBit( j ) ) | ||
80 | { | ||
81 | Block b = { j, blockUnused, blockUnused, 0, 0 }; | ||
82 | bsBlockUsed.setBit( j ); | ||
83 | sStore.setPos( iBlockStart+(iBlockSize*j) ); | ||
84 | sStore.write( &b, sizeof(b) ); | ||
85 | } | ||
86 | } | ||
18 | return 0; | 87 | return 0; |
19 | } | 88 | } |
20 | 89 | ||
90 | void Bu::Nids::deleteStream( int iID ) | ||
91 | { | ||
92 | } | ||
93 | |||
94 | Bu::NidsStream Bu::Nids::openStream( int iID ) | ||
95 | { | ||
96 | return NidsStream( *this ); | ||
97 | } | ||
98 | |||
99 | void Bu::Nids::extendStream( int iID, int iBlockCount ) | ||
100 | { | ||
101 | } | ||
102 | |||
103 | void Bu::Nids::getBlock( int iIndex, Bu::Nids::Block *pBlock ) | ||
104 | { | ||
105 | sStore.setPos( iBlockStart + (iBlockSize*iIndex) ); | ||
106 | sStore.read( pBlock, iBlockSize ); | ||
107 | } | ||
108 | |||
109 | void Bu::Nids::setBlock( int iIndex, Bu::Nids::Block *pBlock ) | ||
110 | { | ||
111 | sStore.setPos( iBlockStart + (iBlockSize*iIndex) ); | ||
112 | sStore.write( pBlock, iBlockSize ); | ||
113 | } | ||
21 | 114 | ||