-
Notifications
You must be signed in to change notification settings - Fork 0
/
bt_scan.cpp
66 lines (55 loc) · 1.02 KB
/
bt_scan.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <unistd.h>
#include "bt_errors.h"
#include "bt_node.h"
#include "bt_scan.h"
BtreeScan::BtreeScan()
{
leaf = NULL;
endKey = 0;
pos = 0;
}
BtreeScan::~BtreeScan()
{
}
BtreeNode* BtreeScan::get_leaf()
{
return leaf;
}
Status BtreeScan::set_leaf( BtreeNode* l )
{
leaf = l;
return OK;
}
int BtreeScan::get_pos()
{
return pos;
}
Status BtreeScan::set_pos( int p )
{
pos = p;
return OK;
}
KeyId BtreeScan::get_endKey()
{
return endKey;
}
Status BtreeScan::set_endKey( KeyId e )
{
endKey = e;
return OK;
}
Status BtreeScan::getNext(KeyId* key) {
// If no more keys on this leaf, move right.
if(get_pos() >= get_leaf()->get_keyCount()) {
set_leaf(get_leaf()->getPtr(MAX_NUM_PTRS - 1));
set_pos(0);
}
// If we ran out of keys...
if(get_leaf() == NULL ||
get_pos() > get_leaf()->get_keyCount() ||
(get_endKey() && get_endKey() < (get_leaf()->getKey(get_pos()))))
return NO_MORE_KEYS; // XXX is this the right code?
*key = get_leaf()->getKey(get_pos());
set_pos(get_pos()+1);
return OK;
}