|
Xbase Class Library 2.0.0
|
00001 /* $Id: ntx.h,v 1.5 2000/11/10 19:04:17 dbryson Exp $ 00002 00003 Xbase 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 StarTech, Gary A. Kunkel 00009 00010 This library is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU Lesser General Public 00012 License as published by the Free Software Foundation; either 00013 version 2.1 of the License, or (at your option) any later version. 00014 00015 This library 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 GNU 00018 Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public 00021 License along with this library; if not, write to the Free Software 00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 00024 Contact: 00025 00026 Mail: 00027 00028 Technology Associates, Inc. 00029 XBase Project 00030 1455 Deming Way #11 00031 Sparks, NV 89434 00032 USA 00033 00034 Email: 00035 00036 xbase@techass.com 00037 00038 See our website at: 00039 00040 xdb.sourceforge.net 00041 00042 00043 V 1.0 10/10/97 - Initial release of software 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 { /* ntx header on disk */ 00066 xbUShort Signature; /* Clipper 5.x or Clipper 87 */ 00067 xbUShort Version; /* Compiler Version */ 00068 /* Also turns out to be a last modified counter */ 00069 xbLong StartNode; /* Offset in file for first index */ 00070 xbULong UnusedOffset; /* First free page offset */ 00071 xbUShort KeySize; /* Size of items (KeyLen + 8) */ 00072 xbUShort KeyLen; /* Size of the Key */ 00073 xbUShort DecimalCount; /* Number of decimal positions */ 00074 xbUShort KeysPerNode; /* Max number of keys per page */ 00075 xbUShort HalfKeysPerNode; /* Min number of keys per page */ 00076 char KeyExpression[256]; /* Null terminated key expression */ 00077 unsigned Unique; /* Unique Flag */ 00078 char NotUsed[745]; 00079 }; 00080 00082 00085 struct NtxLeafNode { /* ndx node on disk */ 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 { /* ndx node memory */ 00107 xbNodeLink * PrevNode; 00108 xbNodeLink * NextNode; 00109 xbUShort CurKeyNo; /* 0 - KeysPerNode-1 */ 00110 xbLong NodeNo; 00111 struct NtxLeafNode Leaf; 00112 xbUShort *offsets; 00113 }; 00114 00116 00119 class XBDLLEXPORT xbNtx : public xbIndex { 00120 public: 00121 NtxHeadNode HeadNode; 00122 NtxLeafNode LeafNode; 00123 xbLong NodeLinkCtr; 00124 xbLong ReusedNodeLinks; 00125 00126 char Node[XB_NTX_NODE_SIZE]; 00127 00128 xbNodeLink * NodeChain; /* pointer to node chain of index nodes */ 00129 xbNodeLink * FreeNodeChain; /* pointer to chain of free index nodes */ 00130 xbNodeLink * CurNode; /* pointer to current node */ 00131 xbNodeLink * DeleteChain; /* pointer to chain to delete */ 00132 xbNodeLink * CloneChain; /* pointer to node chain copy (add dup) */ 00133 00134 NtxItem PushItem; 00135 00136 /* private functions */ 00137 xbLong GetLeftNodeNo( xbShort, xbNodeLink * ); 00138 xbShort CompareKey( const char *, const char *, xbShort ); 00139 xbShort CompareKey( const char *, const char * ); 00140 xbLong GetDbfNo( xbShort, xbNodeLink * ); 00141 char * GetKeyData( xbShort, xbNodeLink * ); 00142 xbUShort GetItemOffset ( xbShort, xbNodeLink *, xbShort ); 00143 xbUShort InsertKeyOffset ( xbShort, xbNodeLink * ); 00144 xbUShort GetKeysPerNode( void ); 00145 xbShort GetHeadNode( void ); 00146 xbShort GetLeafNode( xbLong, xbShort ); 00147 xbNodeLink * GetNodeMemory( void ); 00148 xbLong GetNextNodeNo( void ); 00149 void ReleaseNodeMemory( xbNodeLink * ); 00150 xbULong GetLeafFromInteriorNode( const char *, xbShort ); 00151 xbShort CalcKeyLen( void ); 00152 xbShort PutKeyData( xbShort, xbNodeLink * ); 00153 xbShort PutLeftNodeNo( xbShort, xbNodeLink *, xbLong ); 00154 xbShort PutLeafNode( xbLong, xbNodeLink * ); 00155 xbShort PutHeadNode( NtxHeadNode *, FILE *, xbShort ); 00156 xbShort TouchIndex( void ); 00157 xbShort PutDbfNo( xbShort, xbNodeLink *, xbLong ); 00158 xbShort PutKeyInNode( xbNodeLink *, xbShort, xbLong, xbLong, xbShort ); 00159 xbShort SplitLeafNode( xbNodeLink *, xbNodeLink *, xbShort, xbLong ); 00160 xbShort SplitINode( xbNodeLink *, xbNodeLink *, xbLong ); 00161 xbShort AddToIxList( void ); 00162 xbShort RemoveFromIxList( void ); 00163 xbShort RemoveKeyFromNode( xbShort, xbNodeLink * ); 00164 xbShort DeleteKeyFromNode( xbShort, xbNodeLink * ); 00165 xbShort JoinSiblings(xbNodeLink *, xbShort, xbNodeLink *, xbNodeLink *); 00166 xbUShort DeleteKeyOffset( xbShort, xbNodeLink *); 00167 xbShort FindKey( const char *, xbShort, xbShort ); 00168 xbShort UpdateParentKey( xbNodeLink * ); 00169 xbShort GetFirstKey( xbShort ); 00170 xbShort GetNextKey( xbShort ); 00171 xbShort GetLastKey( xbLong, xbShort ); 00172 xbShort GetPrevKey( xbShort ); 00173 void UpdateDeleteList( xbNodeLink * ); 00174 void ProcessDeleteList( void ); 00175 // xbNodeLink * LeftSiblingHasSpace( xbNodeLink * ); 00176 // xbNodeLink * RightSiblingHasSpace( xbNodeLink * ); 00177 // xbShort DeleteSibling( xbNodeLink * ); 00178 // xbShort MoveToLeftNode( xbNodeLink *, xbNodeLink * ); 00179 // xbShort MoveToRightNode( xbNodeLink *, xbNodeLink * ); 00180 xbShort FindKey( const char *, xbLong ); /* for a specific dbf no */ 00181 00182 xbShort CloneNodeChain( void ); /* test */ 00183 xbShort UncloneNodeChain( void ); /* test */ 00184 00185 00186 00187 xbNtx() : xbIndex() {} 00188 xbNtx( xbDbf * ); 00189 00190 /* note to gak - don't uncomment next line - it causes seg faults */ 00191 // ~NTX() { if( NtxStatus ) CloseIndex(); } 00192 00193 xbShort OpenIndex ( const char * ); 00194 xbShort CloseIndex( void ); 00195 void DumpHdrNode ( void ); 00196 void DumpNodeRec ( xbLong ); 00197 xbShort CreateIndex( const char *, const char *, xbShort, xbShort ); 00198 xbLong GetTotalNodes( void ); 00199 xbLong GetCurDbfRec( void ) { return CurDbfRec; } 00200 void DumpNodeChain( void ); 00201 xbShort CreateKey( xbShort, xbShort ); 00202 xbShort GetCurrentKey(char *key); 00203 xbShort AddKey( xbLong ); 00204 xbShort UniqueIndex( void ) { return HeadNode.Unique; } 00205 xbShort DeleteKey( xbLong DbfRec ); 00206 xbShort KeyWasChanged( void ); 00207 xbShort FindKey( const char * ); 00208 xbShort FindKey( void ); 00209 xbShort FindKey( xbDouble ); 00210 #ifdef XBASE_DEBUG 00211 xbShort CheckIndexIntegrity( const xbShort Option ); 00212 #endif 00213 xbShort GetNextKey( void ) { return GetNextKey( 1 ); } 00214 xbShort GetLastKey( void ) { return GetLastKey( 0, 1 ); } 00215 xbShort GetFirstKey( void ) { return GetFirstKey( 1 ); } 00216 xbShort GetPrevKey( void ) { return GetPrevKey( 1 ); } 00217 xbShort ReIndex(void (*statusFunc)(xbLong itemNum, xbLong numItems) = 0) ; 00218 xbShort KeyExists( char * Key ) { return FindKey( Key, strlen( Key ), 0 ); } 00219 xbShort KeyExists( xbDouble ); 00220 00221 xbShort AllocKeyBufs(void); 00222 00223 virtual void GetExpression(char *buf, int len); 00224 }; 00225 #endif /* __XB_NTX_H__ */
1.7.3