1 |
// -*- Mode: C++ -*- |
2 |
|
3 |
// GiST.h |
4 |
// |
5 |
// Copyright (c) 1996, Regents of the University of California |
6 |
// $Header: /cvsroot/Tree-M/GiST/GiST.h,v 1.1 2001/05/06 00:45:51 root Exp $ |
7 |
|
8 |
#ifndef GIST_H |
9 |
#define GIST_H |
10 |
|
11 |
#ifndef BOOL |
12 |
# define BOOL int |
13 |
# ifndef TRUE |
14 |
# define TRUE 1 |
15 |
# endif |
16 |
# ifndef FALSE |
17 |
# define FALSE 0 |
18 |
# endif |
19 |
#endif |
20 |
|
21 |
#ifndef NULL |
22 |
#define NULL 0 |
23 |
#endif |
24 |
|
25 |
#include "GiSTdefs.h" |
26 |
#include "GiSTentry.h" |
27 |
#include "GiSTlist.h" |
28 |
#include "GiSTnode.h" |
29 |
#include "GiSTstore.h" |
30 |
#include "GiSTpredicate.h" |
31 |
#include "GiSTcursor.h" |
32 |
|
33 |
class GiST : public GiSTobject { |
34 |
public: |
35 |
GiST(); |
36 |
|
37 |
// a likely candidate for overloading |
38 |
GiSTobjid IsA() const { return GIST_CLASS; } |
39 |
|
40 |
void Create(const char *filename); |
41 |
void Open(const char *filename); |
42 |
void Close(); |
43 |
|
44 |
GiSTcursor *Search(const GiSTpredicate &query) const; |
45 |
void Insert(const GiSTentry& entry); |
46 |
void Delete(const GiSTpredicate& pred); |
47 |
void Sync(); |
48 |
GiSTstore *Store() { return store; } |
49 |
|
50 |
int IsOpen() { return isOpen; } |
51 |
virtual int IsOrdered() const { return 0; } |
52 |
virtual int ForcedReinsert() const { return 0; } |
53 |
|
54 |
#ifdef PRINTING_OBJECTS |
55 |
void DumpNode(ostream& os, GiSTpath path) const; |
56 |
void Print(ostream& os) const; |
57 |
#endif |
58 |
|
59 |
~GiST(); |
60 |
|
61 |
protected: |
62 |
// The following must be overriden by descendant classes |
63 |
virtual GiSTstore *CreateStore() const = 0; |
64 |
virtual GiSTnode *CreateNode() const = 0; |
65 |
|
66 |
// These are default supports for Forced Reinsert |
67 |
virtual GiSTlist<GiSTentry*> RemoveTop(GiSTnode *node); |
68 |
virtual double RemoveRatio() const { return 0.3; } |
69 |
|
70 |
// Reads/writes nodes |
71 |
GiSTnode *ReadNode(const GiSTpath& path) const; |
72 |
void WriteNode(GiSTnode *node); |
73 |
|
74 |
private: |
75 |
void InsertHelper(const GiSTentry &entry, int level, int *lvl_split = NULL); |
76 |
GiSTnode *ChooseSubtree(GiSTpage page, const GiSTentry &entry, int level); |
77 |
void Split(GiSTnode **node, const GiSTentry& entry); |
78 |
void AdjustKeys(GiSTnode *node, GiSTnode **parent); |
79 |
int CondenseTree(GiSTnode *leaf); |
80 |
void ShortenTree(); |
81 |
void OverflowTreatment(GiSTnode *node, const GiSTentry& entry, int *lvl_split); |
82 |
GiSTnode *NewNode(GiST *tree) const { |
83 |
GiSTnode *retval=CreateNode(); |
84 |
retval->SetTree(tree); |
85 |
return(retval); |
86 |
} |
87 |
|
88 |
GiSTstore *store; |
89 |
int isOpen; |
90 |
int debug; |
91 |
|
92 |
friend class GiSTcursor; |
93 |
}; |
94 |
#endif |