00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef BLOCKARRAY_H
00022 #define BLOCKARRAY_H
00023
00024 #include <unistd.h>
00025
00026
00027
00028 #define BlockSize (1 << 12)
00029 #define ENTRIES ((BlockSize - sizeof(size_t) ) / sizeof(unsigned char))
00030
00031 struct Block {
00032 Block() { size = 0; }
00033 unsigned char data[ENTRIES];
00034 size_t size;
00035 };
00036
00037
00038
00039 class BlockArray {
00040 public:
00047 BlockArray();
00048
00050 ~BlockArray();
00051
00063 size_t append(Block *block);
00064
00073 const Block *at(size_t index);
00074
00081 bool setHistorySize(size_t newsize);
00082
00083 size_t newBlock();
00084
00085 Block *lastBlock() const;
00086
00091 bool setSize(size_t newsize);
00092
00093 size_t len() const { return length; }
00094
00095 bool has(size_t index) const;
00096
00097 size_t getCurrent() const { return current; }
00098
00099 private:
00100 void unmap();
00101 void increaseBuffer();
00102 void decreaseBuffer(size_t newsize);
00103
00104 size_t size;
00105
00106 size_t current;
00107 size_t index;
00108
00109 Block *lastmap;
00110 size_t lastmap_index;
00111 Block *lastblock;
00112
00113 int ion;
00114 size_t length;
00115
00116 };
00117
00118
00119 #endif