forked from Bishop92/JavaScript-Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrieIterator.js
More file actions
67 lines (58 loc) · 1.14 KB
/
TrieIterator.js
File metadata and controls
67 lines (58 loc) · 1.14 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
/**
* Created by Stefano on 06/04/2014.
*/
TrieIterator.prototype = new Iterator();
TrieIterator.prototype.constructor = TrieIterator;
/**
* Class that implements the iterator for a trie.
* @param aggregate {Trie} The aggregate to scan.
* @constructor
*/
function TrieIterator(aggregate) {
/**
* The aggregate relates to this iterator.
* @type {Trie}
*/
this.aggregate = aggregate;
/**
* The pointer to the position.
* @type {TNode|null}
*/
this.pointer = null;
}
/**
* @inheritDoc
*/
TrieIterator.prototype.first = function () {
this.pointer = this.aggregate.minimum();
};
/**
* @inheritDoc
*/
TrieIterator.prototype.next = function () {
this.pointer = this.aggregate.successor(this.pointer);
};
/**
* @inheritDoc
*/
TrieIterator.prototype.last = function () {
this.pointer = this.aggregate.maximum();
};
/**
* @inheritDoc
*/
TrieIterator.prototype.previous = function () {
this.pointer = this.aggregate.predecessor(this.pointer);
};
/**
* @inheritDoc
*/
TrieIterator.prototype.isDone = function () {
return !this.pointer;
};
/**
* @inheritDoc
*/
TrieIterator.prototype.getItem = function () {
return this.pointer.item;
};