Xbase Class Library  2.0.0
ntx.h
Go to the documentation of this file.
1 /* $Id: ntx.h,v 1.5 2000/11/10 19:04:17 dbryson Exp $
2 
3  Xbase project source code
4 
5  This file contains a header file for the xbNdx object, which is used
6  for handling xbNdx type indices.
7 
8  Copyright (C) 1997 StarTech, Gary A. Kunkel
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 2.1 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 
24  Contact:
25 
26  Mail:
27 
28  Technology Associates, Inc.
29  XBase Project
30  1455 Deming Way #11
31  Sparks, NV 89434
32  USA
33 
34  Email:
35 
36  xbase@techass.com
37 
38  See our website at:
39 
40  xdb.sourceforge.net
41 
42 
43  V 1.0 10/10/97 - Initial release of software
44 */
45 
46 #ifndef __XB_NTX_H__
47 #define __XB_NTX_H__
48 
49 #ifdef __GNUG__
50 #pragma interface
51 #endif
52 
53 #include <xbase/xbase.h>
54 #include <string.h>
55 
59 #define XB_NTX_NODE_SIZE 1024
60 
62 
65 struct NtxHeadNode { /* ntx header on disk */
66  xbUShort Signature; /* Clipper 5.x or Clipper 87 */
67  xbUShort Version; /* Compiler Version */
68  /* Also turns out to be a last modified counter */
69  xbLong StartNode; /* Offset in file for first index */
70  xbULong UnusedOffset; /* First free page offset */
71  xbUShort KeySize; /* Size of items (KeyLen + 8) */
72  xbUShort KeyLen; /* Size of the Key */
73  xbUShort DecimalCount; /* Number of decimal positions */
74  xbUShort KeysPerNode; /* Max number of keys per page */
75  xbUShort HalfKeysPerNode; /* Min number of keys per page */
76  char KeyExpression[256]; /* Null terminated key expression */
77  unsigned Unique; /* Unique Flag */
78  char NotUsed[745];
79 };
80 
82 
85 struct NtxLeafNode { /* ndx node on disk */
88 };
89 
90 
92 
95 struct NtxItem
96 {
99  char Key[256];
100 };
101 
103 
106 struct xbNodeLink { /* ndx node memory */
109  xbUShort CurKeyNo; /* 0 - KeysPerNode-1 */
113 };
114 
116 
119 class XBDLLEXPORT xbNtx : public xbIndex {
120  public:
125 
126  char Node[XB_NTX_NODE_SIZE];
127 
128  xbNodeLink * NodeChain; /* pointer to node chain of index nodes */
129  xbNodeLink * FreeNodeChain; /* pointer to chain of free index nodes */
130  xbNodeLink * CurNode; /* pointer to current node */
131  xbNodeLink * DeleteChain; /* pointer to chain to delete */
132  xbNodeLink * CloneChain; /* pointer to node chain copy (add dup) */
133 
135 
136 /* private functions */
137  xbLong GetLeftNodeNo( xbShort, xbNodeLink * );
138  xbShort CompareKey( const char *, const char *, xbShort );
139  xbShort CompareKey( const char *, const char * );
140  xbLong GetDbfNo( xbShort, xbNodeLink * );
141  char * GetKeyData( xbShort, xbNodeLink * );
142  xbUShort GetItemOffset ( xbShort, xbNodeLink *, xbShort );
143  xbUShort InsertKeyOffset ( xbShort, xbNodeLink * );
144  xbUShort GetKeysPerNode( void );
145  xbShort GetHeadNode( void );
146  xbShort GetLeafNode( xbLong, xbShort );
147  xbNodeLink * GetNodeMemory( void );
148  xbLong GetNextNodeNo( void );
149  void ReleaseNodeMemory( xbNodeLink * );
150  xbULong GetLeafFromInteriorNode( const char *, xbShort );
151  xbShort CalcKeyLen( void );
152  xbShort PutKeyData( xbShort, xbNodeLink * );
153  xbShort PutLeftNodeNo( xbShort, xbNodeLink *, xbLong );
154  xbShort PutLeafNode( xbLong, xbNodeLink * );
155  xbShort PutHeadNode( NtxHeadNode *, FILE *, xbShort );
156  xbShort TouchIndex( void );
157  xbShort PutDbfNo( xbShort, xbNodeLink *, xbLong );
158  xbShort PutKeyInNode( xbNodeLink *, xbShort, xbLong, xbLong, xbShort );
159  xbShort SplitLeafNode( xbNodeLink *, xbNodeLink *, xbShort, xbLong );
160  xbShort SplitINode( xbNodeLink *, xbNodeLink *, xbLong );
161  xbShort AddToIxList( void );
162  xbShort RemoveFromIxList( void );
163  xbShort RemoveKeyFromNode( xbShort, xbNodeLink * );
164  xbShort DeleteKeyFromNode( xbShort, xbNodeLink * );
165  xbShort JoinSiblings(xbNodeLink *, xbShort, xbNodeLink *, xbNodeLink *);
166  xbUShort DeleteKeyOffset( xbShort, xbNodeLink *);
167  xbShort FindKey( const char *, xbShort, xbShort );
168  xbShort UpdateParentKey( xbNodeLink * );
173  void UpdateDeleteList( xbNodeLink * );
174  void ProcessDeleteList( void );
175 // xbNodeLink * LeftSiblingHasSpace( xbNodeLink * );
176 // xbNodeLink * RightSiblingHasSpace( xbNodeLink * );
177 // xbShort DeleteSibling( xbNodeLink * );
178 // xbShort MoveToLeftNode( xbNodeLink *, xbNodeLink * );
179 // xbShort MoveToRightNode( xbNodeLink *, xbNodeLink * );
180  xbShort FindKey( const char *, xbLong ); /* for a specific dbf no */
181 
182  xbShort CloneNodeChain( void ); /* test */
183  xbShort UncloneNodeChain( void ); /* test */
184 
185 
186 
187  xbNtx() : xbIndex() {}
188  xbNtx( xbDbf * );
189 
190 /* note to gak - don't uncomment next line - it causes seg faults */
191 // ~NTX() { if( NtxStatus ) CloseIndex(); }
192 
193  xbShort OpenIndex ( const char * );
194  xbShort CloseIndex( void );
195  void DumpHdrNode ( void );
196  void DumpNodeRec ( xbLong );
197  xbShort CreateIndex( const char *, const char *, xbShort, xbShort );
198  xbLong GetTotalNodes( void );
199  xbLong GetCurDbfRec( void ) { return CurDbfRec; }
200  void DumpNodeChain( void );
202  xbShort GetCurrentKey(char *key);
203  xbShort AddKey( xbLong );
204  xbShort UniqueIndex( void ) { return HeadNode.Unique; }
205  xbShort DeleteKey( xbLong DbfRec );
206  xbShort KeyWasChanged( void );
207  xbShort FindKey( const char * );
208  xbShort FindKey( void );
210 #ifdef XBASE_DEBUG
211  xbShort CheckIndexIntegrity( const xbShort Option );
212 #endif
213  xbShort GetNextKey( void ) { return GetNextKey( 1 ); }
214  xbShort GetLastKey( void ) { return GetLastKey( 0, 1 ); }
215  xbShort GetFirstKey( void ) { return GetFirstKey( 1 ); }
216  xbShort GetPrevKey( void ) { return GetPrevKey( 1 ); }
217  xbShort ReIndex(void (*statusFunc)(xbLong itemNum, xbLong numItems) = 0) ;
218  xbShort KeyExists( char * Key ) { return FindKey( Key, strlen( Key ), 0 ); }
220 
221  xbShort AllocKeyBufs(void);
222 
223  virtual void GetExpression(char *buf, int len);
224 };
225 #endif /* __XB_NTX_H__ */
NtxHeadNode HeadNode
Definition: ntx.h:121
xbNodeLink * NodeChain
Definition: ntx.h:128
virtual xbShort GetCurrentKey(char *key)=0
virtual xbShort CreateIndex(const char *, const char *, xbShort, xbShort)=0
xbNtxItem struct
Definition: ntx.h:95
xbShort GetPrevKey(void)
Definition: ntx.h:216
#define XB_NTX_NODE_SIZE
Definition: ntx.h:59
double xbDouble
xbDouble type
Definition: xtypes.h:76
char NotUsed[745]
Definition: ntx.h:78
virtual xbShort OpenIndex(const char *)=0
unsigned Unique
Definition: ntx.h:77
xbNtxHeadNode struct
Definition: ntx.h:65
xbNtx class
Definition: ntx.h:119
virtual xbShort KeyExists(xbDouble)=0
#define XBDLLEXPORT
Definition: xbase.h:101
xbLong ReusedNodeLinks
Definition: ntx.h:124
NtxItem PushItem
Definition: ntx.h:134
virtual xbShort GetLastKey()=0
xbUShort Signature
Definition: ntx.h:66
xbLong NodeLinkCtr
Definition: ntx.h:123
xbShort GetFirstKey(void)
Definition: ntx.h:215
virtual xbShort GetNextKey()=0
xbShort GetLastKey(void)
Definition: ntx.h:214
virtual xbShort FindKey()=0
char KeyExpression[256]
Definition: ntx.h:76
xbNtxLeafNode struct
Definition: ntx.h:85
xbUShort DecimalCount
Definition: ntx.h:73
virtual xbShort ReIndex(void(*statusFunc)(xbLong itemNum, xbLong numItems)=0)=0
xbULong RecordNumber
Definition: ntx.h:98
virtual xbShort KeyWasChanged()=0
unsigned long int xbULong
xbULong type
Definition: xtypes.h:57
xbIndex class
Definition: index.h:67
virtual xbShort GetFirstKey()=0
xbUShort KeysPerNode
Definition: ntx.h:74
char Key[256]
Definition: ntx.h:99
xbULong Node
Definition: ntx.h:97
xbShort KeyExists(char *Key)
Definition: ntx.h:218
xbULong UnusedOffset
Definition: ntx.h:70
xbUShort KeySize
Definition: ntx.h:71
xbUShort HalfKeysPerNode
Definition: ntx.h:75
virtual xbShort AddKey(xbLong)=0
#define xbLong
Definition: xtypes.h:67
xbNodeLink * CloneChain
Definition: ntx.h:132
virtual xbShort CloseIndex()=0
short int xbShort
xbShort type
Definition: xtypes.h:65
xbUShort KeyLen
Definition: ntx.h:72
xbNodeLink * CurNode
Definition: ntx.h:130
virtual xbShort GetPrevKey()=0
xbLong CurDbfRec
Definition: index.h:79
xbNodeLink * FreeNodeChain
Definition: ntx.h:129
virtual xbShort CreateKey(xbShort, xbShort)=0
xbNodeLink * DeleteChain
Definition: ntx.h:131
virtual xbShort DeleteKey(xbLong)=0
virtual xbLong GetTotalNodes()=0
xbNtx()
Definition: ntx.h:187
xbUShort NoOfKeysThisNode
Definition: ntx.h:86
xbUShort Version
Definition: ntx.h:67
virtual xbShort TouchIndex(void)
Definition: index.h:131
xbLong GetCurDbfRec(void)
Definition: ntx.h:199
NtxLeafNode LeafNode
Definition: ntx.h:122
xbMH struct
Definition: dbf.h:201
xbLong StartNode
Definition: ntx.h:69
unsigned short int xbUShort
xbUShort type
Definition: xtypes.h:61
virtual void GetExpression(char *buf, int len)=0
xbShort GetNextKey(void)
Definition: ntx.h:213
char KeyRecs[XB_NTX_NODE_SIZE]
Definition: ntx.h:87
xbShort UniqueIndex(void)
Definition: ntx.h:204