Home Reference Source
public class | source

AvlTree

Extends:

BinarySearchTree → AvlTree

Constructor Summary

Public Constructor
public

constructor(compFn: *)

Example -

var AVLTree = require("dsjslib").AVLTree
var avl=new AVLTree(function(k1,k2){...})

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

put(key: *, value: *): Object

Insert a key value.

Private Methods
private

_nodeHeight(node: *): *

private

rebalance(vError: *)

private

rotate(node: *, rL: *): String

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
public

put(key: *, value: *): Object

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#constructor

Params:

NameTypeAttributeDescription
compFn *

{userCompareFn=} external compare function for ordering keys

Public Members

public root: * source

Override:

BinarySearchTree#root

Public Methods

public checkAVLProperty(node: *): * source

Params:

NameTypeAttributeDescription
node *

Return:

*

public checkInvariants(node: *) source

Validates the tree starting at given node (root otherwise) Validates BST as well as AVL properties.

Override:

BinarySearchTree#checkInvariants

Params:

NameTypeAttributeDescription
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#delete

Params:

NameTypeAttributeDescription
key *

{*}

public put(key: *, value: *): Object source

Insert a key value. It also re-balances the tree

Override:

BinarySearchTree#put

Params:

NameTypeAttributeDescription
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 _nodeHeight(node: *): * source

Params:

NameTypeAttributeDescription
node *

Return:

*

private rebalance(vError: *) source

Params:

NameTypeAttributeDescription
vError *

private rotate(node: *, rL: *): String source

Rotate a node

Params:

NameTypeAttributeDescription
node *
rL *

Return:

String