Class: BinaryTree

BinaryTree

new BinaryTree(val, index)

The binary tree class.
Parameters:
Name Type Description
val Object The object to index.
index Object The index object.
Source:

Methods

(private) _compareFunc(a, b) → {number}

Default compare method. Can be overridden.
Parameters:
Name Type Description
a
b
Source:
Returns:
Type
number

(private) _compareFunc(a, b) → {number}

Default compare method. Can be overridden.
Parameters:
Name Type Description
a
b
Source:
Returns:
Type
number

(private) _hashFunc(obj)

Default hash function. Can be overridden.
Parameters:
Name Type Description
obj
Source:

data(valopt) → {*}

Gets / sets the data this tree node holds.
Parameters:
Name Type Attributes Description
val Object <optional>
The tree node data.
Source:
Returns:
Type
*

decouple(data, copiesopt) → {*}

Returns a non-referenced version of the passed object / array.
Parameters:
Name Type Attributes Description
data Object The object or array to return as a non-referenced version.
copies Number <optional>
Optional number of copies to produce. If specified, the return value will be an array of decoupled objects, each distinct from the other.
Source:
Returns:
Type
*

index(objopt) → {*}

Gets / sets the index object used to determine which fields are indexed in the objects being added to the tree and in what order they are sorted.
Parameters:
Name Type Attributes Description
obj Object <optional>
The index object.
Source:
Returns:
Type
*

inOrder(resultArropt) → {Array}

Returns an array of all items in the tree in ascending order.
Parameters:
Name Type Attributes Description
resultArr Array <optional>
Used internally by the method.
Source:
Returns:
Ascending order results array.
Type
Array

insert(val) → {*}

Inserts a value into the binary tree.
Parameters:
Name Type Description
val String | Number | Array The value to insert.
Source:
Returns:
Type
*

insertLeft(val) → {*}

Inserts an object into the left side of this node's tree, or creates a new tree node on the left and then inserts the object.
Parameters:
Name Type Description
val Object The object to insert.
Source:
Returns:
Type
*

insertMiddle(val) → {*}

Inserts an object into the middle of this node's tree, or creates a new tree node in the middle and then inserts the object.
Parameters:
Name Type Description
val Object The object to insert.
Source:
Returns:
Type
*

insertRight(val) → {*}

Inserts an object into the right side of this node's tree, or creates a new tree node on the right and then inserts the object.
Parameters:
Name Type Description
val Object The object to insert.
Source:
Returns:
Type
*

keys(obj) → {Array}

Scans the passed object and returns an array of objects, each containing the key and the value of each object key.
Parameters:
Name Type Description
obj Object The object to scan keys from.
Source:
Returns:
An array of key/val objects.
Type
Array

left(treeopt) → {*}

Gets / sets the node's left tree node.
Parameters:
Name Type Attributes Description
tree BinaryTree <optional>
The tree node.
Source:
Returns:
Type
*

lookup(query) → {Array}

Retrieves results based on the query object.
Parameters:
Name Type Description
query Object The query object.
Source:
Returns:
The result array.
Type
Array

middle(treeopt) → {*}

Gets / sets the node's middle tree node.
Parameters:
Name Type Attributes Description
tree BinaryTree <optional>
The tree node.
Source:
Returns:
Type
*
Gets / sets the node's right tree node.
Parameters:
Name Type Attributes Description
tree BinaryTree <optional>
The tree node.
Source:
Returns:
Type
*

sortAsc(a, b) → {*}

Sorts the passed value a against the passed value b ascending.
Parameters:
Name Type Description
a * The first value to compare.
b * The second value to compare.
Source:
Returns:
1 if a is sorted after b, -1 if a is sorted before b.
Type
*

sortDesc(a, b) → {*}

Sorts the passed value a against the passed value b descending.
Parameters:
Name Type Description
a * The first value to compare.
b * The second value to compare.
Source:
Returns:
1 if a is sorted after b, -1 if a is sorted before b.
Type
*