Constructor
new SetTree(data)
Initiate setTree.
Get parameter as null or compare function or other set tree.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
data |
null | function | SetTree |
null
|
Methods
begin() → {null|TreeNode}
Return the first iterator node of tree.
Returns:
- Type
- null | TreeNode
end() → {TreeNode}
this express the end of iterating.
we can start from front with begin(), end with rbegin() and eventually meet end()
At the end, if we use getNext() method, we get false.
But, if we use getPrev() method, we get maximum node.
Returns:
- endnode of tree iterator.
- Type
- TreeNode
rbegin() → {null|TreeNode}
return the last node of tree iterator.
Returns:
- Type
- null | TreeNode
rend() → {TreeNode}
this express the front end of iterating.
we can start from front with begin(), end with rbegin() and eventually meet end()
At the end, if we use getNext() method, we get false.
But, if we use getPrev() method, we get maximum node.
Returns:
- endnode of tree iterator.
- Type
- TreeNode
empty() → {boolean}
make sure tree is empty.
Returns:
- Type
- boolean
size() → {number}
the number of nodes in tree.
Returns:
- Type
- number
clear()
initiate the tree.
insert(key)
insert new node in tree with key.
If key already exists, return false.
Parameters:
Name | Type | Description |
---|---|---|
key |
* | Should not TreeNode. |
erase(data) → {false|TreeNode}
If erase() get key value as param, we erase all nodes with that key.
But if erase() get TreeNode as param, we erase only that node.
Parameters:
Name | Type | Description |
---|---|---|
data |
* | TreeNode | Data can be key or Node of tree. |
Returns:
- next node of erased data. if cannot find the key, return falase.
- Type
- false | TreeNode
count(key) → {number}
count the number of nodes which match the key.
It should be 0 or 1.
Parameters:
Name | Type | Description |
---|---|---|
key |
* | Should not TreeNode. |
Returns:
- Type
- number
find(key) → {TreeNode}
return node which matches the key.
Parameters:
Name | Type | Description |
---|---|---|
key |
* | Should not TreeNode. |
Returns:
- Type
- TreeNode
contains(key) → {boolean}
make sure the key is in tree.
Parameters:
Name | Type | Description |
---|---|---|
key |
* | Should not TreeNode. |
Returns:
- Type
- boolean
equalRange(key) → {Array}
return the start node and end node of given key.
end node is next node of last match node.
if no key in tree, return [endnode,endnode]
Parameters:
Name | Type | Description |
---|---|---|
key |
* | Should not TreeNode. |
Returns:
- [TreeNode,TreeNode]
- Type
- Array
lowerBound(key) → {TreeNode}
Find the first not less node.
It don't need to be same with given key.
Parameters:
Name | Type | Description |
---|---|---|
key |
* | the target key to find. |
Returns:
- Type
- TreeNode
upperBound(key) → {TreeNode}
Find the first upper node.
Parameters:
Name | Type | Description |
---|---|---|
key |
* | the target key to find. |
Returns:
- Type
- TreeNode
keyComp() → {function}
return the key compare function.
Returns:
- Type
- function
toString() → {string}
show information of object
Returns:
- Type
- string
copy() → {MapTree}
return copy of this object
Returns:
- Type
- MapTree