1 |
root |
1.1 |
// Mode: -*- C++ -*- |
2 |
|
|
|
3 |
|
|
// GiSTcursor.cpp |
4 |
|
|
// |
5 |
|
|
// Copyright (c) 1996, Regents of the University of California |
6 |
|
|
// $Header: /usr/local/devel/GiST/libGiST/libGiST/GiSTcursor.cpp,v 1.1.1.1 1996/08/06 23:47:20 jmh Exp $ |
7 |
|
|
|
8 |
|
|
#include "GiST.h" |
9 |
|
|
|
10 |
|
|
GiSTcursor::GiSTcursor(const GiST& gist, const GiSTpredicate& query): gist(gist) |
11 |
|
|
{ |
12 |
|
|
this->query=(GiSTpredicate*) query.Copy(); |
13 |
|
|
first=1; |
14 |
|
|
lastlevel=-1; |
15 |
|
|
} |
16 |
|
|
|
17 |
|
|
GiSTentry* |
18 |
|
|
GiSTcursor::Next() |
19 |
|
|
{ |
20 |
|
|
GiSTpage page; |
21 |
|
|
|
22 |
|
|
while(first||!stack.IsEmpty()) { |
23 |
|
|
if(first) { |
24 |
|
|
page=GiSTRootPage; |
25 |
|
|
first=0; |
26 |
|
|
} |
27 |
|
|
else { |
28 |
|
|
assert(lastlevel>=0); |
29 |
|
|
GiSTentry *entry=stack.RemoveFront(); |
30 |
|
|
|
31 |
|
|
if(entry->IsLeaf()) return entry; |
32 |
|
|
// Pop off the stack |
33 |
|
|
for(int i=0; i<entry->Level()-lastlevel; i++) path.MakeParent(); |
34 |
|
|
page=entry->Ptr(); |
35 |
|
|
delete entry; |
36 |
|
|
} |
37 |
|
|
// Entry was a pointer to another node |
38 |
|
|
path.MakeChild(page); |
39 |
|
|
|
40 |
|
|
GiSTnode *node=gist.ReadNode(path); |
41 |
|
|
|
42 |
|
|
lastlevel=node->Level(); |
43 |
|
|
|
44 |
|
|
GiSTlist<GiSTentry*> list=node->Search(*query); |
45 |
|
|
|
46 |
|
|
while(!list.IsEmpty()) { |
47 |
|
|
GiSTentry *entry=list.RemoveRear(); |
48 |
|
|
stack.Prepend(entry); |
49 |
|
|
} |
50 |
|
|
delete node; |
51 |
|
|
} |
52 |
|
|
// The search is over... |
53 |
|
|
return NULL; |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
GiSTcursor::~GiSTcursor() |
57 |
|
|
{ |
58 |
|
|
if(query!=NULL) delete query; |
59 |
|
|
while(!stack.IsEmpty()) delete stack.RemoveFront(); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
const GiSTpath& |
63 |
|
|
GiSTcursor::Path() const |
64 |
|
|
{ |
65 |
|
|
return path; |
66 |
|
|
} |