Xbase64 Class Library  3.1.2
xbntx.h
Go to the documentation of this file.
1 /* xbntx.h
2 
3  Xbase64 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,2003 Bob Cotton
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program 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
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 
24 
25  Contact:
26 
27  Email:
28 
29  xdb-devel@lists.sourceforge.net
30  xdb-users@lists.sourceforge.net
31 
32 
33  Regular Mail:
34 
35  XBase Support
36  149C South Main St
37  Keller Texas, 76248
38  USA
39 
40 */
41 
42 #ifndef __XB_NTX_H__
43 #define __XB_NTX_H__
44 
45 #ifdef __GNU_LesserG__
46 #pragma interface
47 #endif
48 
49 #include <xbase64/xbase64.h>
50 #include <string.h>
51 
55 #define XB_NTX_NODE_SIZE 1024
56 
58 
61 struct NtxHeadNode { /* ntx header on disk */
62  xbUShort Signature; /* Clipper 5.x or Clipper 87 */
63  xbUShort Version; /* Compiler Version */
64  /* Also turns out to be a last modified counter */
65  xbLong StartNode; /* Offset in file for first index */
66  xbULong UnusedOffset; /* First free page offset */
67  xbUShort KeySize; /* Size of items (KeyLen + 8) */
68  xbUShort KeyLen; /* Size of the Key */
69  xbUShort DecimalCount; /* Number of decimal positions */
70  xbUShort KeysPerNode; /* Max number of keys per page */
71  xbUShort HalfKeysPerNode; /* Min number of keys per page */
72  char KeyExpression[256]; /* Null terminated key expression */
73  unsigned Unique; /* Unique Flag */
74  char NotUsed[745];
75 };
76 
78 
81 struct NtxLeafNode { /* ndx node on disk */
84 };
85 
86 
88 
91 struct NtxItem
92 {
95  char Key[256];
96 };
97 
99 
102 struct xbNodeLink { /* ndx node memory */
105  xbUShort CurKeyNo; /* 0 - KeysPerNode-1 */
109 };
110 
112 
115 class XBDLLEXPORT xbNtx : public xbIndex
116 {
117 protected:
122  char Node[XB_NTX_NODE_SIZE];
123  xbNodeLink * NodeChain; /* pointer to node chain of index nodes */
124  xbNodeLink * FreeNodeChain; /* pointer to chain of free index nodes */
125  xbNodeLink * CurNode; /* pointer to current node */
126  xbNodeLink * DeleteChain; /* pointer to chain to delete */
127 // xbNodeLink * CloneChain; /* pointer to node chain copy (add dup) */
129 
130 /* private functions */
131  xbLong GetLeftNodeNo( xbShort, xbNodeLink * );
132  xbShort CompareKey( const char *, const char *, xbShort );
133  xbShort CompareKey( const char *, const char * );
134  xbLong GetDbfNo( xbShort, xbNodeLink * );
135  char * GetKeyData( xbShort, xbNodeLink * );
136  xbUShort GetItemOffset ( xbShort, xbNodeLink *, xbShort );
137  xbUShort InsertKeyOffset ( xbShort, xbNodeLink * );
138  xbUShort GetKeysPerNode();
139  virtual xbShort GetHeadNode();
140  xbShort GetLeafNode( xbLong, xbShort );
141  xbNodeLink * GetNodeMemory();
142  xbLong GetNextNodeNo();
143  void ReleaseNodeMemory(xbNodeLink *n, xbBool doFree = false);
144  xbULong GetLeafFromInteriorNode( const char *, xbShort );
145  xbShort CalcKeyLen();
146  xbShort PutKeyData( xbShort, xbNodeLink * );
147  xbShort PutLeftNodeNo( xbShort, xbNodeLink *, xbLong );
148  xbShort PutLeafNode( xbLong, xbNodeLink * );
149  xbShort PutHeadNode( NtxHeadNode *, FILE *, xbShort );
151  xbShort PutDbfNo( xbShort, xbNodeLink *, xbLong );
152  xbShort PutKeyInNode( xbNodeLink *, xbShort, xbLong, xbLong, xbShort );
153  xbShort SplitLeafNode( xbNodeLink *, xbNodeLink *, xbShort, xbLong );
154  xbShort SplitINode( xbNodeLink *, xbNodeLink *, xbLong );
155  xbShort AddToIxList();
156  xbShort RemoveFromIxList();
157  xbShort RemoveKeyFromNode( xbShort, xbNodeLink * );
158  xbShort DeleteKeyFromNode( xbShort, xbNodeLink * );
159  xbShort JoinSiblings(xbNodeLink *, xbShort, xbNodeLink *, xbNodeLink *);
160  xbUShort DeleteKeyOffset( xbShort, xbNodeLink *);
161  xbShort FindKey( const char *, xbShort, xbShort );
162  xbShort UpdateParentKey( xbNodeLink * );
167  void UpdateDeleteList( xbNodeLink * );
168  void ProcessDeleteList();
169  xbShort FindKey( const char *, xbLong ); /* for a specific dbf no */
170 
171 public:
172  xbNtx();
173  xbNtx(xbDbf *);
174  virtual ~xbNtx();
175 
176 /* note to gak - don't uncomment next line - it causes seg faults */
177 // ~NTX() { if( NtxStatus ) CloseIndex(); }
178 
179  void DumpHdrNode ( xbShort Option );
180  void DumpNodeRec ( xbLong );
181  xbShort CreateIndex( const char *, const char *, xbShort, xbShort );
184  void DumpNodeChain();
186  xbShort GetCurrentKey(char *key);
187  xbShort AddKey( xbLong );
188  xbShort UniqueIndex() { return HeadNode.Unique; }
189  xbShort DeleteKey( xbLong DbfRec );
191  xbShort FindKey( const char * );
192  xbShort FindKey();
194  xbShort GetNextKey() { return GetNextKey( 1 ); }
195  xbShort GetLastKey() { return GetLastKey( 0, 1 ); }
196  xbShort GetFirstKey() { return GetFirstKey( 1 ); }
197  xbShort GetPrevKey() { return GetPrevKey( 1 ); }
198  xbShort ReIndex(void (*statusFunc)(xbLong itemNum, xbLong numItems) = 0) ;
199  xbShort KeyExists( char * Key ) { return FindKey( Key, strlen( Key ), 0 ); }
201  virtual void GetExpression(char *buf, int len);
202 #ifdef XBASE_DEBUG
203  xbShort CheckIndexIntegrity( xbShort Option );
204 #endif
205 
206  virtual const char* GetExtWithDot(bool lower);
207 
208  protected:
209  virtual xbUShort GetKeyLen();
210  virtual const char* GetKeyExpression();
211  virtual void FreeNodesMemory();
212 };
213 #endif /* __XB_NTX_H__ */
NtxHeadNode HeadNode
Definition: xbntx.h:118
xbNodeLink * NodeChain
Definition: xbntx.h:123
virtual xbShort GetCurrentKey(char *key)=0
virtual xbShort CreateIndex(const char *, const char *, xbShort, xbShort)=0
xbNtxItem struct
Definition: xbntx.h:91
virtual xbShort TouchIndex()
Definition: xbindex.h:91
virtual void FreeNodesMemory()=0
char NotUsed[745]
Definition: xbntx.h:74
short int xbBool
xbBool type
Definition: xbtypes.h:78
xbULong CurDbfRec
Definition: xbindex.h:126
virtual const char * GetKeyExpression()=0
unsigned Unique
Definition: xbntx.h:73
virtual const char * GetExtWithDot(bool lower)=0
xbNtxHeadNode struct
Definition: xbntx.h:61
xbNtx class
Definition: xbntx.h:115
virtual xbShort KeyExists(xbDouble)=0
#define XBDLLEXPORT
Definition: xbase64.h:87
xbShort GetLastKey()
Definition: xbntx.h:195
xbLong ReusedNodeLinks
Definition: xbntx.h:121
long xbLong
Definition: xbtypes.h:61
#define XB_NTX_NODE_SIZE
Definition: xbntx.h:55
xbULong GetCurDbfRec()
Definition: xbntx.h:183
short int xbShort
xbShort type
Definition: xbtypes.h:60
NtxItem PushItem
Definition: xbntx.h:128
virtual xbShort GetLastKey()=0
xbUShort Signature
Definition: xbntx.h:62
xbLong NodeLinkCtr
Definition: xbntx.h:120
virtual xbShort GetNextKey()=0
unsigned long int xbULong
xbULong type
Definition: xbtypes.h:50
double xbDouble
xbDouble type
Definition: xbtypes.h:73
virtual xbShort FindKey()=0
char KeyExpression[256]
Definition: xbntx.h:72
xbNtxLeafNode struct
Definition: xbntx.h:81
xbShort GetNextKey()
Definition: xbntx.h:194
xbShort GetPrevKey()
Definition: xbntx.h:197
xbUShort DecimalCount
Definition: xbntx.h:69
virtual xbShort ReIndex(void(*statusFunc)(xbLong itemNum, xbLong numItems)=0)=0
xbULong RecordNumber
Definition: xbntx.h:94
virtual xbShort KeyWasChanged()=0
xbIndex class
Definition: xbindex.h:62
virtual xbShort GetFirstKey()=0
unsigned short int xbUShort
xbUShort type
Definition: xbtypes.h:55
xbUShort KeysPerNode
Definition: xbntx.h:70
char Key[256]
Definition: xbntx.h:95
xbULong Node
Definition: xbntx.h:93
xbShort KeyExists(char *Key)
Definition: xbntx.h:199
xbULong UnusedOffset
Definition: xbntx.h:66
xbUShort KeySize
Definition: xbntx.h:67
xbUShort HalfKeysPerNode
Definition: xbntx.h:71
virtual xbShort AddKey(xbLong)=0
xbUShort KeyLen
Definition: xbntx.h:68
xbNodeLink * CurNode
Definition: xbntx.h:125
virtual xbShort GetPrevKey()=0
xbNodeLink * FreeNodeChain
Definition: xbntx.h:124
virtual xbShort CreateKey(xbShort, xbShort)=0
xbNodeLink * DeleteChain
Definition: xbntx.h:126
virtual xbShort DeleteKey(xbLong)=0
xbShort GetFirstKey()
Definition: xbntx.h:196
xbShort UniqueIndex()
Definition: xbntx.h:188
virtual xbLong GetTotalNodes()=0
xbUShort NoOfKeysThisNode
Definition: xbntx.h:82
xbUShort Version
Definition: xbntx.h:63
NtxLeafNode LeafNode
Definition: xbntx.h:119
xbMH struct
Definition: xbdbf.h:190
xbLong StartNode
Definition: xbntx.h:65
virtual xbUShort GetKeyLen()=0
virtual void GetExpression(char *buf, int len)=0
char KeyRecs[XB_NTX_NODE_SIZE]
Definition: xbntx.h:83
virtual xbShort GetHeadNode()=0