new BinarySearchTree(compareFn)
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
compareFn |
userCompareFn |
<optional> |
, fn(a,b) return 1 if b>a, -1 if b<a, 0 otherwise |
- Source:
Methods
-
delete(item)
-
Delete a key value pair from the Map.
Parameters:
Name Type Description item
* key to deleted
- Source:
-
get(key) → {Object}
-
Get value for a key
Parameters:
Name Type Description key
- Source:
Returns:
{key:key used in query,value:value of the key }, null if key was not found
- Type
- Object
-
max() → {Object}
-
Find max key
- Source:
Returns:
{key:maximum key,value: value}
- Type
- Object
-
min() → {Object}
-
Find min key
- Source:
Returns:
{key:minimum key,value: value}
- Type
- Object
-
predecessor(key) → {Object}
-
Return the predecessor key value pair
Parameters:
Name Type Description key
* key for which predecessor is needed
- Source:
Returns:
{key:predecessor key,value: value}
- Type
- Object
-
put(key, value) → {Object}
-
Insert a key value pair
Parameters:
Name Type Description key
value
- Source:
Returns:
- Type
- Object
-
successor(item) → {Object}
-
Return the successor key value pair
Parameters:
Name Type Description item
* key for which successor is needed
- Source:
Returns:
{key:successor key,value: value}
- Type
- Object
-
traverse(node, fn)
-
Inorder traversal, apply provided function on each visited node
Parameters:
Name Type Argument Description node
Object <optional>
Start at root if not given
fn
function Callback function called for every node visited
- Source: