00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
#ifndef __XB_NTX_H__
00047
#define __XB_NTX_H__
00048
00049
#ifdef __GNUG__
00050
#pragma interface
00051
#endif
00052
00053
#include <xbase/xbase.h>
00054
#include <string.h>
00055
00059 #define XB_NTX_NODE_SIZE 1024
00060
00062
00065 struct NtxHeadNode {
00066 xbUShort Signature;
00067 xbUShort Version;
00068
00069 xbLong StartNode;
00070 xbULong UnusedOffset;
00071 xbUShort KeySize;
00072 xbUShort KeyLen;
00073 xbUShort DecimalCount;
00074 xbUShort KeysPerNode;
00075 xbUShort HalfKeysPerNode;
00076 char KeyExpression[256];
00077 unsigned Unique;
00078 char NotUsed[745];
00079 };
00080
00082
00085 struct NtxLeafNode {
00086 xbUShort NoOfKeysThisNode;
00087 char KeyRecs[
XB_NTX_NODE_SIZE];
00088 };
00089
00090
00092
00095 struct NtxItem
00096 {
00097 xbULong Node;
00098 xbULong RecordNumber;
00099 char Key[256];
00100 };
00101
00103
00106 struct xbNodeLink {
00107 xbNodeLink *
PrevNode;
00108 xbNodeLink *
NextNode;
00109 xbUShort CurKeyNo;
00110 xbLong NodeNo;
00111 struct NtxLeafNode Leaf;
00112 xbUShort *
offsets;
00113 };
00114
00116
00119 class XBDLLEXPORT xbNtx :
public xbIndex
00120 {
00121
protected:
00122 NtxHeadNode HeadNode;
00123 NtxLeafNode LeafNode;
00124 xbLong NodeLinkCtr;
00125 xbLong ReusedNodeLinks;
00126
00127 char Node[
XB_NTX_NODE_SIZE];
00128
00129 xbNodeLink * NodeChain;
00130 xbNodeLink * FreeNodeChain;
00131 xbNodeLink * CurNode;
00132 xbNodeLink * DeleteChain;
00133 xbNodeLink * CloneChain;
00134
00135 NtxItem PushItem;
00136
00137
00138
xbLong GetLeftNodeNo(
xbShort,
xbNodeLink * );
00139
xbShort CompareKey(
const char *,
const char *, xbShort );
00140
xbShort CompareKey(
const char *,
const char * );
00141
xbLong GetDbfNo( xbShort,
xbNodeLink * );
00142
char * GetKeyData( xbShort,
xbNodeLink * );
00143
xbUShort GetItemOffset ( xbShort,
xbNodeLink *, xbShort );
00144
xbUShort InsertKeyOffset ( xbShort,
xbNodeLink * );
00145
xbUShort GetKeysPerNode(
void );
00146
xbShort GetHeadNode(
void );
00147
xbShort GetLeafNode( xbLong, xbShort );
00148
xbNodeLink * GetNodeMemory(
void );
00149
xbLong GetNextNodeNo(
void );
00150
void ReleaseNodeMemory(
xbNodeLink *n,
bool doFree =
false);
00151
xbULong GetLeafFromInteriorNode(
const char *, xbShort );
00152
xbShort CalcKeyLen(
void );
00153
xbShort PutKeyData( xbShort,
xbNodeLink * );
00154
xbShort PutLeftNodeNo( xbShort,
xbNodeLink *, xbLong );
00155
xbShort PutLeafNode( xbLong,
xbNodeLink * );
00156
xbShort PutHeadNode(
NtxHeadNode *, FILE *, xbShort );
00157
xbShort TouchIndex(
void );
00158
xbShort PutDbfNo( xbShort,
xbNodeLink *, xbLong );
00159
xbShort PutKeyInNode(
xbNodeLink *, xbShort, xbLong, xbLong, xbShort );
00160
xbShort SplitLeafNode(
xbNodeLink *,
xbNodeLink *, xbShort, xbLong );
00161
xbShort SplitINode(
xbNodeLink *,
xbNodeLink *, xbLong );
00162
xbShort AddToIxList(
void );
00163
xbShort RemoveFromIxList(
void );
00164
xbShort RemoveKeyFromNode( xbShort,
xbNodeLink * );
00165
xbShort DeleteKeyFromNode( xbShort,
xbNodeLink * );
00166
xbShort JoinSiblings(
xbNodeLink *, xbShort,
xbNodeLink *,
xbNodeLink *);
00167
xbUShort DeleteKeyOffset( xbShort,
xbNodeLink *);
00168
xbShort FindKey(
const char *, xbShort, xbShort );
00169
xbShort UpdateParentKey(
xbNodeLink * );
00170
xbShort GetFirstKey( xbShort );
00171
xbShort GetNextKey( xbShort );
00172
xbShort GetLastKey( xbLong, xbShort );
00173
xbShort GetPrevKey( xbShort );
00174
void UpdateDeleteList(
xbNodeLink * );
00175
void ProcessDeleteList(
void );
00176
00177
00178
00179
00180
00181
xbShort FindKey(
const char *, xbLong );
00182
00183
xbShort CloneNodeChain(
void );
00184
xbShort UncloneNodeChain(
void );
00185
00186
public:
00187 xbNtx();
00188 xbNtx(
xbDbf *);
00189
virtual ~xbNtx();
00190
00191
00192
00193
00194
xbShort OpenIndex (
const char * );
00195
xbShort CloseIndex(
void );
00196
void DumpHdrNode (
void );
00197
void DumpNodeRec ( xbLong );
00198
xbShort CreateIndex(
const char *,
const char *, xbShort, xbShort );
00199
xbLong GetTotalNodes(
void );
00200 xbULong GetCurDbfRec(
void ) {
return CurDbfRec; }
00201
void DumpNodeChain(
void );
00202
xbShort CreateKey( xbShort, xbShort );
00203
xbShort GetCurrentKey(
char *key);
00204
xbShort AddKey( xbLong );
00205 xbShort UniqueIndex(
void ) {
return HeadNode.Unique; }
00206
xbShort DeleteKey( xbLong DbfRec );
00207
xbShort KeyWasChanged(
void );
00208
xbShort FindKey(
const char * );
00209
xbShort FindKey(
void );
00210
xbShort FindKey( xbDouble );
00211
#ifdef XBASE_DEBUG
00212
xbShort CheckIndexIntegrity(
const xbShort Option );
00213
#endif
00214 xbShort GetNextKey(
void ) {
return GetNextKey( 1 ); }
00215 xbShort GetLastKey(
void ) {
return GetLastKey( 0, 1 ); }
00216 xbShort GetFirstKey(
void ) {
return GetFirstKey( 1 ); }
00217 xbShort GetPrevKey(
void ) {
return GetPrevKey( 1 ); }
00218
xbShort ReIndex(
void (*statusFunc)(xbLong itemNum, xbLong numItems) = 0) ;
00219 xbShort KeyExists(
char * Key ) {
return FindKey( Key, strlen( Key ), 0 ); }
00220
xbShort KeyExists( xbDouble );
00221
00222
xbShort xbNtx::AllocKeyBufs(
void);
00223
00224
virtual void GetExpression(
char *buf,
int len);
00225 };
00226
#endif