Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

ntx.h

Go to the documentation of this file.
00001 /* $Id: ntx.h,v 1.9 2003/08/16 19:59:39 gkunkel 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 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 xdb-devel@lists.sourceforge.net 00038 xdb-users@lists.sourceforge.net 00039 00040 See our website at: 00041 00042 xdb.sourceforge.net 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 { /* 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 { 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; /* pointer to node chain of index nodes */ 00130 xbNodeLink * FreeNodeChain; /* pointer to chain of free index nodes */ 00131 xbNodeLink * CurNode; /* pointer to current node */ 00132 xbNodeLink * DeleteChain; /* pointer to chain to delete */ 00133 xbNodeLink * CloneChain; /* pointer to node chain copy (add dup) */ 00134 00135 NtxItem PushItem; 00136 00137 /* private functions */ 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 // xbNodeLink * LeftSiblingHasSpace( xbNodeLink * ); 00177 // xbNodeLink * RightSiblingHasSpace( xbNodeLink * ); 00178 // xbShort DeleteSibling( xbNodeLink * ); 00179 // xbShort MoveToLeftNode( xbNodeLink *, xbNodeLink * ); 00180 // xbShort MoveToRightNode( xbNodeLink *, xbNodeLink * ); 00181 xbShort FindKey( const char *, xbLong ); /* for a specific dbf no */ 00182 00183 xbShort CloneNodeChain( void ); /* test */ 00184 xbShort UncloneNodeChain( void ); /* test */ 00185 00186 public: 00187 xbNtx(); 00188 xbNtx(xbDbf *); 00189 virtual ~xbNtx(); 00190 00191 /* note to gak - don't uncomment next line - it causes seg faults */ 00192 // ~NTX() { if( NtxStatus ) CloseIndex(); } 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 /* __XB_NTX_H__ */

Generated on Sat Sep 11 04:01:10 2004 for Xbase Class Library by doxygen 1.3.7