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 */
107  struct NtxLeafNode Leaf;
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 */
132  xbShort CompareKey( const char *, const char *, xbShort );
133  xbShort CompareKey( const char *, const char * );
139  virtual xbShort GetHeadNode();
143  void ReleaseNodeMemory(xbNodeLink *n, xbBool doFree = false);
161  xbShort FindKey( const char *, xbShort, xbShort );
169  xbShort FindKey( const char *, xbLong ); /* for a specific dbf no */
170 
171 public:
172  xbNtx();
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 );
186  xbShort GetCurrentKey(char *key);
188  xbShort UniqueIndex() { return HeadNode.Unique; }
191  xbShort FindKey( const char * );
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__ */
xbNtx::GetLeftNodeNo
xbLong GetLeftNodeNo(xbShort, xbNodeLink *)
xbNtx::FreeNodesMemory
virtual void FreeNodesMemory()
xbNtx::DumpNodeChain
void DumpNodeChain()
xbNtx::PutHeadNode
xbShort PutHeadNode(NtxHeadNode *, FILE *, xbShort)
xbNtx::GetExtWithDot
virtual const char * GetExtWithDot(bool lower)
xbNtx::GetItemOffset
xbUShort GetItemOffset(xbShort, xbNodeLink *, xbShort)
xbase64.h
xbNtx::DeleteKeyFromNode
xbShort DeleteKeyFromNode(xbShort, xbNodeLink *)
xbNtx::GetFirstKey
xbShort GetFirstKey(xbShort)
xbNtx::GetLeafFromInteriorNode
xbULong GetLeafFromInteriorNode(const char *, xbShort)
xbNtx::GetKeyExpression
virtual const char * GetKeyExpression()
xbNtx::GetNodeMemory
xbNodeLink * GetNodeMemory()
xbNtx::GetLastKey
xbShort GetLastKey()
Definition: xbntx.h:195
NtxHeadNode::StartNode
xbLong StartNode
Definition: xbntx.h:65
NtxHeadNode
xbNtxHeadNode struct
Definition: xbntx.h:61
xbNtx::~xbNtx
virtual ~xbNtx()
xbNtx::ReusedNodeLinks
xbLong ReusedNodeLinks
Definition: xbntx.h:121
xbNtx::HeadNode
NtxHeadNode HeadNode
Definition: xbntx.h:118
xbDbf
xbMH struct
Definition: xbdbf.h:190
NtxLeafNode::KeyRecs
char KeyRecs[XB_NTX_NODE_SIZE]
Definition: xbntx.h:83
xbNtx::GetHeadNode
virtual xbShort GetHeadNode()
xbNtx::DeleteKey
xbShort DeleteKey(xbLong DbfRec)
xbNtx::CompareKey
xbShort CompareKey(const char *, const char *, xbShort)
xbNtx::SplitLeafNode
xbShort SplitLeafNode(xbNodeLink *, xbNodeLink *, xbShort, xbLong)
NtxHeadNode::KeyExpression
char KeyExpression[256]
Definition: xbntx.h:72
XBDLLEXPORT
#define XBDLLEXPORT
Definition: xbase64.h:87
xbNtx::CreateIndex
xbShort CreateIndex(const char *, const char *, xbShort, xbShort)
NtxHeadNode::Unique
unsigned Unique
Definition: xbntx.h:73
xbNtx::RemoveFromIxList
xbShort RemoveFromIxList()
NtxItem::Node
xbULong Node
Definition: xbntx.h:93
xbNtx::CompareKey
xbShort CompareKey(const char *, const char *)
xbDouble
double xbDouble
xbDouble type
Definition: xbtypes.h:73
xbULong
unsigned long int xbULong
xbULong type
Definition: xbtypes.h:50
xbShort
short int xbShort
xbShort type
Definition: xbtypes.h:60
xbNtx::PushItem
NtxItem PushItem
Definition: xbntx.h:128
xbNtx::GetNextKey
xbShort GetNextKey()
Definition: xbntx.h:194
NtxHeadNode::UnusedOffset
xbULong UnusedOffset
Definition: xbntx.h:66
xbBool
short int xbBool
xbBool type
Definition: xbtypes.h:78
xbNtx::GetPrevKey
xbShort GetPrevKey()
Definition: xbntx.h:197
xbLong
long xbLong
Definition: xbtypes.h:61
NtxHeadNode::KeysPerNode
xbUShort KeysPerNode
Definition: xbntx.h:70
xbNtx::PutLeafNode
xbShort PutLeafNode(xbLong, xbNodeLink *)
NtxLeafNode
xbNtxLeafNode struct
Definition: xbntx.h:81
xbNtx::GetCurDbfRec
xbULong GetCurDbfRec()
Definition: xbntx.h:183
xbNtx::GetKeyData
char * GetKeyData(xbShort, xbNodeLink *)
xbNtx::GetPrevKey
xbShort GetPrevKey(xbShort)
xbNtx::GetCurrentKey
xbShort GetCurrentKey(char *key)
xbNtx::ProcessDeleteList
void ProcessDeleteList()
xbNtx::PutKeyInNode
xbShort PutKeyInNode(xbNodeLink *, xbShort, xbLong, xbLong, xbShort)
NtxItem::Key
char Key[256]
Definition: xbntx.h:95
xbNtx::JoinSiblings
xbShort JoinSiblings(xbNodeLink *, xbShort, xbNodeLink *, xbNodeLink *)
xbIndex
xbIndex class
Definition: xbindex.h:63
xbNtx::GetNextNodeNo
xbLong GetNextNodeNo()
NtxHeadNode::Signature
xbUShort Signature
Definition: xbntx.h:62
xbUShort
unsigned short int xbUShort
xbUShort type
Definition: xbtypes.h:55
NtxItem
xbNtxItem struct
Definition: xbntx.h:92
xbNtx::CurNode
xbNodeLink * CurNode
Definition: xbntx.h:125
xbNtx::InsertKeyOffset
xbUShort InsertKeyOffset(xbShort, xbNodeLink *)
xbNtx::KeyExists
xbShort KeyExists(char *Key)
Definition: xbntx.h:199
xbNtx::UpdateParentKey
xbShort UpdateParentKey(xbNodeLink *)
xbNtx::RemoveKeyFromNode
xbShort RemoveKeyFromNode(xbShort, xbNodeLink *)
xbNtx
xbNtx class
Definition: xbntx.h:116
xbNtx::DumpHdrNode
void DumpHdrNode(xbShort Option)
xbNtx::NodeLinkCtr
xbLong NodeLinkCtr
Definition: xbntx.h:120
NtxHeadNode::DecimalCount
xbUShort DecimalCount
Definition: xbntx.h:69
NtxHeadNode::KeySize
xbUShort KeySize
Definition: xbntx.h:67
xbNtx::KeyWasChanged
xbShort KeyWasChanged()
xbNtx::DeleteKeyOffset
xbUShort DeleteKeyOffset(xbShort, xbNodeLink *)
xbNtx::ReIndex
xbShort ReIndex(void(*statusFunc)(xbLong itemNum, xbLong numItems)=0)
xbNtx::UniqueIndex
xbShort UniqueIndex()
Definition: xbntx.h:188
xbNtx::GetTotalNodes
xbLong GetTotalNodes()
xbNtx::AddToIxList
xbShort AddToIxList()
xbNtx::xbNtx
xbNtx()
NtxLeafNode::NoOfKeysThisNode
xbUShort NoOfKeysThisNode
Definition: xbntx.h:82
xbNtx::FindKey
xbShort FindKey()
NtxHeadNode::HalfKeysPerNode
xbUShort HalfKeysPerNode
Definition: xbntx.h:71
xbIndex::CurDbfRec
xbULong CurDbfRec
Definition: xbindex.h:126
xbNtx::KeyExists
xbShort KeyExists(xbDouble)
xbNtx::FreeNodeChain
xbNodeLink * FreeNodeChain
Definition: xbntx.h:124
xbNtx::FindKey
xbShort FindKey(const char *, xbShort, xbShort)
xbNtx::PutDbfNo
xbShort PutDbfNo(xbShort, xbNodeLink *, xbLong)
xbNtx::UpdateDeleteList
void UpdateDeleteList(xbNodeLink *)
xbNtx::GetLeafNode
xbShort GetLeafNode(xbLong, xbShort)
xbIndex::FindKey
virtual xbShort FindKey()=0
xbNtx::GetFirstKey
xbShort GetFirstKey()
Definition: xbntx.h:196
xbNtx::FindKey
xbShort FindKey(const char *)
XB_NTX_NODE_SIZE
#define XB_NTX_NODE_SIZE
Definition: xbntx.h:55
NtxHeadNode::Version
xbUShort Version
Definition: xbntx.h:63
xbNtx::xbNtx
xbNtx(xbDbf *)
xbNtx::DumpNodeRec
void DumpNodeRec(xbLong)
xbNtx::SplitINode
xbShort SplitINode(xbNodeLink *, xbNodeLink *, xbLong)
xbNtx::GetNextKey
xbShort GetNextKey(xbShort)
xbNtx::CalcKeyLen
xbShort CalcKeyLen()
xbNtx::GetDbfNo
xbLong GetDbfNo(xbShort, xbNodeLink *)
xbNtx::PutLeftNodeNo
xbShort PutLeftNodeNo(xbShort, xbNodeLink *, xbLong)
xbNtx::ReleaseNodeMemory
void ReleaseNodeMemory(xbNodeLink *n, xbBool doFree=false)
xbNtx::CreateKey
xbShort CreateKey(xbShort, xbShort)
xbNtx::NodeChain
xbNodeLink * NodeChain
Definition: xbntx.h:123
xbNtx::GetLastKey
xbShort GetLastKey(xbLong, xbShort)
xbNtx::TouchIndex
xbShort TouchIndex()
xbNtx::GetKeyLen
virtual xbUShort GetKeyLen()
NtxItem::RecordNumber
xbULong RecordNumber
Definition: xbntx.h:94
NtxHeadNode::KeyLen
xbUShort KeyLen
Definition: xbntx.h:68
xbNtx::DeleteChain
xbNodeLink * DeleteChain
Definition: xbntx.h:126
xbNtx::FindKey
xbShort FindKey(xbDouble)
xbNtx::LeafNode
NtxLeafNode LeafNode
Definition: xbntx.h:119
NtxHeadNode::NotUsed
char NotUsed[745]
Definition: xbntx.h:74
xbNtx::PutKeyData
xbShort PutKeyData(xbShort, xbNodeLink *)
xbNtx::GetExpression
virtual void GetExpression(char *buf, int len)
xbNtx::GetKeysPerNode
xbUShort GetKeysPerNode()
xbNtx::FindKey
xbShort FindKey(const char *, xbLong)
xbNtx::AddKey
xbShort AddKey(xbLong)