ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Tree-M/GiST/GiSTpath.h
Revision: 1.1
Committed: Sun May 6 00:45:52 2001 UTC (23 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 // -*- Mode: C++ -*-
2    
3     // GiSTpath.h
4     //
5     // Copyright (c) 1996, Regents of the University of California
6     // $Header: /usr/local/devel/GiST/libGiST/libGiST/GiSTpath.h,v 1.1.1.1 1996/08/06 23:47:21 jmh Exp $
7     #ifndef GISTPATH_H
8     #define GISTPATH_H
9    
10     // GiSTpath objects store the path to a node from the root of the tree.
11     // The page number of each node visited is stored. For simplicity,
12     // GiSTpaths are stored as an array with max GIST_MAX_LEVELS elements.
13     // This can be expanded if you want a tree with more than 16 levels
14     // (not likely unless you have big keys, or small pages!)
15    
16     #define GiSTRootPage 1
17    
18     #define GIST_MAX_LEVELS 16
19    
20     class GiSTpath : public GiSTobject {
21     GiSTpage pages[GIST_MAX_LEVELS];
22     int len;
23     public:
24     GiSTpath() { len=0; }
25     GiSTpath(const GiSTpath& path) {
26     len=path.len;
27     for(int i=0; i<path.len; i++) pages[i]=path.pages[i];
28     }
29    
30     #ifdef PRINTING_OBJECTS
31     void Print(ostream& os) const {
32     os << '[';
33     for(int i=0; i<len; i++) {
34     if(i) os << ' ';
35     os << pages[i];
36     }
37     os << ']';
38     }
39     #endif
40    
41     int Level() const {
42     return len-1;
43     }
44     void Clear() { len=0; }
45     void MakeParent() { len--; }
46     void MakeSibling(GiSTpage page) { pages[len-1]=page; }
47     void MakeChild(GiSTpage page) { pages[len++]=page; }
48     void MakeRoot() {
49     len=1;
50     pages[0]=GiSTRootPage;
51     }
52    
53     void SplitRoot(GiSTpage page) {
54     for(int i=len; i>1; i--) pages[i]=pages[i-1];
55     pages[1]=page;
56     pages[0]=GiSTRootPage;
57     }
58    
59     GiSTpath& operator = (const GiSTpath& path) {
60     len=path.len;
61     for(int i=0; i<path.len; i++) pages[i]=path.pages[i];
62     return *this;
63     }
64    
65     int operator==(const GiSTpath& p) const {
66     if(len!=p.len) return(0);
67     for(int i=0; i<p.len; i++) if (pages[i]!=p.pages[i]) return(0);
68     return(1);
69     }
70    
71     GiSTpage Page() const { return pages[len-1]; }
72     GiSTpage Parent() const { return len>=2? pages[len-2]: 0; }
73     int IsRoot() const { return len==1; }
74     };
75    
76     #endif