forked from iam-peekay/JavaScript-Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBTreeIterator.js
More file actions
76 lines (66 loc) · 1.42 KB
/
BTreeIterator.js
File metadata and controls
76 lines (66 loc) · 1.42 KB
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
67
68
69
70
71
72
73
74
75
76
/**
* Created by Stefano on 06/04/2014.
*/
BTreeIterator.prototype = new Iterator();
BTreeIterator.prototype.constructor = BTreeIterator;
/**
* Class that implements the iterator for a binary search tree.
* @param aggregate {BTree} The aggregate to scan.
* @constructor
*/
function BTreeIterator(aggregate) {
/**
* The aggregate relates to this iterator.
* @type {BTree}
*/
this.aggregate = aggregate;
/**
* The pointer to the position.
* @type {number}
*/
this.pointer = null;
}
/**
* @inheritDoc
*/
BTreeIterator.prototype.first = function () {
this.pointer = this.aggregate.minimumKey();
};
/**
* @inheritDoc
*/
BTreeIterator.prototype.next = function () {
this.pointer = this.aggregate.successor(this.pointer);
};
/**
* @inheritDoc
*/
BTreeIterator.prototype.last = function () {
this.pointer = this.aggregate.maximumKey();
};
/**
* @inheritDoc
*/
BTreeIterator.prototype.previous = function () {
this.pointer = this.aggregate.predecessor(this.pointer);
};
/**
* @inheritDoc
*/
BTreeIterator.prototype.isDone = function () {
return this.pointer === null;
};
/**
* @inheritDoc
*/
BTreeIterator.prototype.getItem = function () {
return this.aggregate.search(this.pointer);
};
/**
* Return the key stored at the position pointed by the iterator.
* @abstract
* @return {number} The key stored or null if it's out of the bounds.
*/
BTreeIterator.prototype.getKey = function () {
return this.pointer;
};