AvlTree
Extends:
Constructor Summary
Public Constructor | ||
public |
constructor(compFn: *) Example -
|
Member Summary
Public Members | ||
public |
root: * |
Method Summary
Public Methods | ||
public |
checkAVLProperty(node: *): * |
|
public |
checkInvariants(node: *) Validates the tree starting at given node (root otherwise) Validates BST as well as AVL properties. |
|
public |
delete(key: *) Delete a key value pair from the Map. |
|
public |
Insert a key value. |
Private Methods | ||
private |
_nodeHeight(node: *): * |
|
private |
rebalance(vError: *) |
|
private |
Rotate a node |
Inherited Summary
From class BinarySearchTree | ||
public |
root: * |
|
public |
|
|
public |
checkInvariants(node: *) |
|
public |
delete(item: *) Delete a key value pair from the Map. |
|
public |
entrySet(): * |
|
public |
get(key: *): * |
|
public |
getKeyValue(key: *): Object Get value for a key |
|
public |
has(key: *): * |
|
public |
inspect(): * |
|
public |
keys(): * |
|
public |
keysAsArray(): * |
|
public |
Insert a key value pair |
|
public |
reCalcHeight(pNode: *) |
|
public |
set(key: *, value: *): * |
|
public |
traverse(node: *, fn: *) Inorder traversal, apply provided function on each visited node |
Public Constructors
public constructor(compFn: *) source
Example -
var AVLTree = require("dsjslib").AVLTree
var avl=new AVLTree(function(k1,k2){...})
Override:
BinarySearchTree#constructorParams:
Name | Type | Attribute | Description |
compFn | * | {userCompareFn=} external compare function for ordering keys |
Public Members
Public Methods
public checkInvariants(node: *) source
Validates the tree starting at given node (root otherwise) Validates BST as well as AVL properties.
Override:
BinarySearchTree#checkInvariantsParams:
Name | Type | Attribute | Description |
node | * | {Object=} Starting node, if not provided start at root |
public delete(key: *) source
Delete a key value pair from the Map. Also re-balances the tree
Override:
BinarySearchTree#deleteParams:
Name | Type | Attribute | Description |
key | * | {*} |
public put(key: *, value: *): Object source
Insert a key value. It also re-balances the tree
Override:
BinarySearchTree#putParams:
Name | Type | Attribute | Description |
key | * | {*} |
|
value | * | {*} |
Return:
Object | A closure on the the tree. Calling put() again on this object will insert key value pair in the tree. This is to support easy chaining of put() method. tree.put(k1,v1).put(k2,v2) ... |
Private Methods
private rebalance(vError: *) source
Params:
Name | Type | Attribute | Description |
vError | * |