diff --git a/btree.cpp b/btree.cpp index 59cc457..fc91806 100644 --- a/btree.cpp +++ b/btree.cpp @@ -1,3 +1,4 @@ +#include #include "btree.h" bool @@ -18,6 +19,22 @@ return ((sizeof(uPtr) + keyLength + 7) >> 3) << 3; } // bTree::align +int +bTree::calcSize(TbNode * node) { + int size; + TbNodeData * dataNode; + + if (node == NULL) return 0; + dataNode = &node->data; + size = (int)dataNode - (int)node; + + for (unsigned int curNode = 1; curNode <= node->numKeys; curNode++) { + size += align(keySize(&dataNode->key)); +//mjikaboom dataNode += align(keySize(&dataNode->key))); + } // for curNode + return size; +} // bTree::calcSize + void bTree::InstallUserFunctions(compareKeyFunc cmpFunc, copyKeyProc copyProc, keySizeFunc ksFunc) { compareKey = cmpFunc; @@ -30,4 +47,3 @@ return; } // bTree::~bTree -/* BTREE SEE PEE PEE */ diff --git a/btree.h b/btree.h index 582fd28..017aa68 100644 --- a/btree.h +++ b/btree.h @@ -7,13 +7,13 @@ enum treeTypes { BT_CUSTOM, BT_PCHAR, BT_STRING, BT_SINGLE, BT_DOUBLE, BT_INT32, BT_INT64 }; -typedef struct blockRun_t { +typedef struct TblockRun { int32 AG; uInt16 start; uInt16 len; } __attribute__((__packed__)); -typedef blockRun_t inodeAddr; +typedef TblockRun inodeAddr; typedef union { int32 i; @@ -25,17 +25,6 @@ int64 offset; } uPtr; -typedef struct bNodeData_t { - uPtr link; - union { - char str[1]; - float f; - double d; - int32 i; - int64 x; - } key; -} __attribute__((__packed__)); - typedef struct bTreeSearch { uPtr value; void * key; @@ -53,6 +42,29 @@ treeTypes treeType; } __attribute__((__packed__)); +typedef struct TbNodeData { + uPtr link; + union { + char str[1]; + float f; + double d; + int32 i; + int64 x; + } key; +} __attribute__((__packed__)); + +typedef struct TbNode { + uInt32 magic; + uInt32 tag; + uInt32 numKeys; + uInt32 size; + uPtr left; + uPtr right; + uPtr parent; + uPtr reserved; + TbNodeData data; +} __attribute__((__packed__)); + class bTree { protected: compareKeyFunc compareKey; @@ -64,6 +76,7 @@ bool treeChanged; int align(int); + int calcSize(TbNode *); public: bTree(char *, uInt32, treeTypes, bTreeVFS *); void InstallUserFunctions(compareKeyFunc, copyKeyProc, keySizeFunc); diff --git a/lists.pas b/lists.pas index 033f5f0..6375ede 100755 --- a/lists.pas +++ b/lists.pas @@ -27,24 +27,24 @@ uPtr = packed record case integer of - 0: (i : int32); - 1: (u : uInt32); - 2: (s : single); - 3: (d : double); - 4: (p : pointer); - 5: (bPtr : PbNode); - 6: (offset : int64); - 7: (iAddr : inodeAddr); + 0: (i : int32); + 1: (u : uInt32); + 2: (s : single); + 3: (d : double); + 4: (p : pointer); + 5: (bPtr : PbNode); + 6: (offset : int64); + 7: (iAddr : inodeAddr); end; PQueue = ^TQueue; TQueue = object private - queue:pointer; - elements:uInt32; - maxElements:uInt32; - size:uInt32; - head, tail:uInt32; + queue : pointer; + elements : uInt32; + maxElements : uInt32; + size : uInt32; + head, tail : uInt32; public constructor init(elementCount, elementSize:uInt32); function dequeue(var item):boolean; @@ -66,22 +66,10 @@ function fWrite(var buf; size:uInt32):boolean; virtual; destructor done; virtual; end; // TBTreeVFS - - TbNode = packed record - magic : uInt32; - tag : uInt32; - numKeys : uInt32; - size : uInt32; - left : uPtr; - right : uPtr; - parent : uPtr; - reserved : uPtr; - data : array[0..0] of byte; - end; - + TbNodeData = packed record - link : uPtr; - key : record + link : uPtr; + key : record case treeTypes of BT_PCHAR, BT_STRING: (str:string[1]); @@ -89,14 +77,27 @@ BT_DOUBLE: (d:double); BT_INT32 : (i:int32); BT_INT64 : (x:int64); - end; {record} - end; {TbNode} + end; // record + end; // TbNodeData + + TbNode = packed record + magic : uInt32; + tag : uInt32; + numKeys : uInt32; + size : uInt32; + left : uPtr; + right : uPtr; + parent : uPtr; + reserved : uPtr; + data : TbNodeData; + end; // TbNode + type BTreeSearchRec = record - value : uPtr; - key : pointer; - keySize:integer; + value : uPtr; + key : pointer; + keySize : integer; end; {BTreeSearchRec} type