Xbase64 Class Library 3.1.2
|
00001 /* xbntx.h 00002 00003 Xbase64 project source code 00004 00005 This file contains a header file for the xbNdx object, which is used 00006 for handling xbNdx type indices. 00007 00008 Copyright (C) 1997,2003 Bob Cotton 00009 00010 This program is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU Lesser General Public License as published by 00012 the Free Software Foundation; either version 2 of the License, or 00013 (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 00024 00025 Contact: 00026 00027 Email: 00028 00029 xdb-devel@lists.sourceforge.net 00030 xdb-users@lists.sourceforge.net 00031 00032 00033 Regular Mail: 00034 00035 XBase Support 00036 149C South Main St 00037 Keller Texas, 76248 00038 USA 00039 00040 */ 00041 00042 #ifndef __XB_NTX_H__ 00043 #define __XB_NTX_H__ 00044 00045 #ifdef __GNU LesserG__ 00046 #pragma interface 00047 #endif 00048 00049 #include <xbase64/xbase64.h> 00050 #include <string.h> 00051 00055 #define XB_NTX_NODE_SIZE 1024 00056 00058 00061 struct NtxHeadNode { /* ntx header on disk */ 00062 xbUShort Signature; /* Clipper 5.x or Clipper 87 */ 00063 xbUShort Version; /* Compiler Version */ 00064 /* Also turns out to be a last modified counter */ 00065 xbLong StartNode; /* Offset in file for first index */ 00066 xbULong UnusedOffset; /* First free page offset */ 00067 xbUShort KeySize; /* Size of items (KeyLen + 8) */ 00068 xbUShort KeyLen; /* Size of the Key */ 00069 xbUShort DecimalCount; /* Number of decimal positions */ 00070 xbUShort KeysPerNode; /* Max number of keys per page */ 00071 xbUShort HalfKeysPerNode; /* Min number of keys per page */ 00072 char KeyExpression[256]; /* Null terminated key expression */ 00073 unsigned Unique; /* Unique Flag */ 00074 char NotUsed[745]; 00075 }; 00076 00078 00081 struct NtxLeafNode { /* ndx node on disk */ 00082 xbUShort NoOfKeysThisNode; 00083 char KeyRecs[XB_NTX_NODE_SIZE]; 00084 }; 00085 00086 00088 00091 struct NtxItem 00092 { 00093 xbULong Node; 00094 xbULong RecordNumber; 00095 char Key[256]; 00096 }; 00097 00099 00102 struct xbNodeLink { /* ndx node memory */ 00103 xbNodeLink * PrevNode; 00104 xbNodeLink * NextNode; 00105 xbUShort CurKeyNo; /* 0 - KeysPerNode-1 */ 00106 xbLong NodeNo; 00107 struct NtxLeafNode Leaf; 00108 xbUShort * offsets; 00109 }; 00110 00112 00115 class XBDLLEXPORT xbNtx : public xbIndex 00116 { 00117 protected: 00118 NtxHeadNode HeadNode; 00119 NtxLeafNode LeafNode; 00120 xbLong NodeLinkCtr; 00121 xbLong ReusedNodeLinks; 00122 char Node[XB_NTX_NODE_SIZE]; 00123 xbNodeLink * NodeChain; /* pointer to node chain of index nodes */ 00124 xbNodeLink * FreeNodeChain; /* pointer to chain of free index nodes */ 00125 xbNodeLink * CurNode; /* pointer to current node */ 00126 xbNodeLink * DeleteChain; /* pointer to chain to delete */ 00127 // xbNodeLink * CloneChain; /* pointer to node chain copy (add dup) */ 00128 NtxItem PushItem; 00129 00130 /* private functions */ 00131 xbLong GetLeftNodeNo( xbShort, xbNodeLink * ); 00132 xbShort CompareKey( const char *, const char *, xbShort ); 00133 xbShort CompareKey( const char *, const char * ); 00134 xbLong GetDbfNo( xbShort, xbNodeLink * ); 00135 char * GetKeyData( xbShort, xbNodeLink * ); 00136 xbUShort GetItemOffset ( xbShort, xbNodeLink *, xbShort ); 00137 xbUShort InsertKeyOffset ( xbShort, xbNodeLink * ); 00138 xbUShort GetKeysPerNode(); 00139 virtual xbShort GetHeadNode(); 00140 xbShort GetLeafNode( xbLong, xbShort ); 00141 xbNodeLink * GetNodeMemory(); 00142 xbLong GetNextNodeNo(); 00143 void ReleaseNodeMemory(xbNodeLink *n, xbBool doFree = false); 00144 xbULong GetLeafFromInteriorNode( const char *, xbShort ); 00145 xbShort CalcKeyLen(); 00146 xbShort PutKeyData( xbShort, xbNodeLink * ); 00147 xbShort PutLeftNodeNo( xbShort, xbNodeLink *, xbLong ); 00148 xbShort PutLeafNode( xbLong, xbNodeLink * ); 00149 xbShort PutHeadNode( NtxHeadNode *, FILE *, xbShort ); 00150 xbShort TouchIndex(); 00151 xbShort PutDbfNo( xbShort, xbNodeLink *, xbLong ); 00152 xbShort PutKeyInNode( xbNodeLink *, xbShort, xbLong, xbLong, xbShort ); 00153 xbShort SplitLeafNode( xbNodeLink *, xbNodeLink *, xbShort, xbLong ); 00154 xbShort SplitINode( xbNodeLink *, xbNodeLink *, xbLong ); 00155 xbShort AddToIxList(); 00156 xbShort RemoveFromIxList(); 00157 xbShort RemoveKeyFromNode( xbShort, xbNodeLink * ); 00158 xbShort DeleteKeyFromNode( xbShort, xbNodeLink * ); 00159 xbShort JoinSiblings(xbNodeLink *, xbShort, xbNodeLink *, xbNodeLink *); 00160 xbUShort DeleteKeyOffset( xbShort, xbNodeLink *); 00161 xbShort FindKey( const char *, xbShort, xbShort ); 00162 xbShort UpdateParentKey( xbNodeLink * ); 00163 xbShort GetFirstKey( xbShort ); 00164 xbShort GetNextKey( xbShort ); 00165 xbShort GetLastKey( xbLong, xbShort ); 00166 xbShort GetPrevKey( xbShort ); 00167 void UpdateDeleteList( xbNodeLink * ); 00168 void ProcessDeleteList(); 00169 xbShort FindKey( const char *, xbLong ); /* for a specific dbf no */ 00170 00171 public: 00172 xbNtx(); 00173 xbNtx(xbDbf *); 00174 virtual ~xbNtx(); 00175 00176 /* note to gak - don't uncomment next line - it causes seg faults */ 00177 // ~NTX() { if( NtxStatus ) CloseIndex(); } 00178 00179 void DumpHdrNode ( xbShort Option ); 00180 void DumpNodeRec ( xbLong ); 00181 xbShort CreateIndex( const char *, const char *, xbShort, xbShort ); 00182 xbLong GetTotalNodes(); 00183 xbULong GetCurDbfRec() { return CurDbfRec; } 00184 void DumpNodeChain(); 00185 xbShort CreateKey( xbShort, xbShort ); 00186 xbShort GetCurrentKey(char *key); 00187 xbShort AddKey( xbLong ); 00188 xbShort UniqueIndex() { return HeadNode.Unique; } 00189 xbShort DeleteKey( xbLong DbfRec ); 00190 xbShort KeyWasChanged(); 00191 xbShort FindKey( const char * ); 00192 xbShort FindKey(); 00193 xbShort FindKey( xbDouble ); 00194 xbShort GetNextKey() { return GetNextKey( 1 ); } 00195 xbShort GetLastKey() { return GetLastKey( 0, 1 ); } 00196 xbShort GetFirstKey() { return GetFirstKey( 1 ); } 00197 xbShort GetPrevKey() { return GetPrevKey( 1 ); } 00198 xbShort ReIndex(void (*statusFunc)(xbLong itemNum, xbLong numItems) = 0) ; 00199 xbShort KeyExists( char * Key ) { return FindKey( Key, strlen( Key ), 0 ); } 00200 xbShort KeyExists( xbDouble ); 00201 virtual void GetExpression(char *buf, int len); 00202 #ifdef XBASE_DEBUG 00203 xbShort CheckIndexIntegrity( xbShort Option ); 00204 #endif 00205 00206 virtual const char* GetExtWithDot(bool lower); 00207 00208 protected: 00209 virtual xbUShort GetKeyLen(); 00210 virtual const char* GetKeyExpression(); 00211 virtual void FreeNodesMemory(); 00212 }; 00213 #endif /* __XB_NTX_H__ */