Class comb.collections.Tree
Extends
comb.collections.Collection, comb.collections.Iterable.
Defined in: Tree.js.
Constructor Attributes | Constructor Name and Description |
---|---|
comb.collections.Tree(options)
Base Class for all tree implementations
|
Field Attributes | Field Name and Description |
---|---|
<static> |
comb.collections.Tree.IN_ORDER
In Order
|
<static> |
comb.collections.Tree.POST_ORDER
Post Order
|
<static> |
comb.collections.Tree.PRE_ORDER
Pre Order
|
<static> |
comb.collections.Tree.REVERSE_ORDER
Reverse Order
|
Method Attributes | Method Name and Description |
---|---|
clear()
Clear all items from a tree
|
|
contains(value)
Determines if a value is contained in the tree
|
|
every(cb, scope, order)
Determines if every item meets the condition returned by the callback.
|
|
filter(cb, scope, order)
Filters a tree, only returning items that result in true being returned from the callback
|
|
find(value)
Finds a value in the tree
|
|
findGreaterThan(value, exclusive)
Find all greater than a value
|
|
findLessThan(value, exclusive)
Find all values less than a value
|
|
forEach(cb, scope, order)
Loop through each item in the tree
|
|
insert(data)
Inserts an item into the tree
|
|
isEmpty()
Test if a tree is empty
|
|
map(cb, scope, order)
Loop through each item in the tree, collecting the value returned by the callback funciton.
|
|
print()
Prints a tree to the console.
|
|
reduce(cb, accumulator, order)
Reduces a tree
|
|
reduceRight(cb, accumulator, order)
Reduces from right to left
|
|
remove(data)
Removes an item from the tree
|
|
some(cb, scope, order)
Determines if some item meet the condition returned by the callback.
|
|
toArray(order)
Converts a tree into an array based on the specified order
|
|
traverse(node, order, callback)
Traverse a tree
Not typically used directly |
|
traverseWithCondition(node, order, callback)
Traverse a tree until the callback function returns false
Not typically used directly |
- Methods borrowed from class comb.collections.Collection:
- concat, indexOf, join, lastIndexOf, slice, toString
Class Detail
comb.collections.Tree(options)
Base Class for all tree implementations
- Parameters:
- {Object} options
- options to initialize the tree
- {Function} options.compare
- function used to compare items in a tree must return an integer
-
-1 for less than
0 for equal
1 for greater than
Field Detail
<static>
comb.collections.Tree.IN_ORDER
In Order
<static>
comb.collections.Tree.POST_ORDER
Post Order
<static>
comb.collections.Tree.PRE_ORDER
Pre Order
<static>
comb.collections.Tree.REVERSE_ORDER
Reverse Order
Method Detail
clear()
Clear all items from a tree
{Boolean}
contains(value)
Determines if a value is contained in the tree
- Parameters:
- {*} value
- the value to find
- Returns:
- {Boolean} true if the tree contains the item false otherwise.
{Boolean}
every(cb, scope, order)
Determines if every item meets the condition returned by the callback.
- Parameters:
- {Function} cb
- called for each item in the tree
- {Object} scope Optional, Default: this
- scope to call the function in
- {Tree.PRE_ORDER|Tree.POST_ORDER|Tree.IN_ORDER|Tree.REVERSE_ORDER} order Optional, Default: Tree.IN_ORDER
- the traversal scheme
- Returns:
- {Boolean} True if every item passed false otherwise
{comb.collections.Tree}
filter(cb, scope, order)
Filters a tree, only returning items that result in true being returned from the callback
- Parameters:
- {Function} cb
- called for each item in the tree
- {Object} scope Optional, Default: this
- scope to call the function in
- {Tree.PRE_ORDER|Tree.POST_ORDER|Tree.IN_ORDER|Tree.REVERSE_ORDER} order Optional, Default: Tree.IN_ORDER
- the traversal scheme
- Returns:
- {comb.collections.Tree} the tree with items that resulted in true being returned from the callback
find(value)
Finds a value in the tree
- Parameters:
- {*} value
- the value to find
- Returns:
- the value of the node that matched
{Array}
findGreaterThan(value, exclusive)
Find all greater than a value
- Parameters:
- {*} value
- the value to find nodes greater than
- {Boolean} exclusive Optional, Default: false
- if true the value will NOT be included in the return array
- Returns:
- {Array} the array containing all values greater than
{Array}
findLessThan(value, exclusive)
Find all values less than a value
- Parameters:
- {*} value
- the value to find nodes less than
- {Boolean} exclusive Optional, Default: false
- if true the value will NOT be included in the return array
- Returns:
- {Array} the array containing all values less than
forEach(cb, scope, order)
Loop through each item in the tree
- Parameters:
- {Function} cb
- called for each item in the tree
- {Object} scope Optional, Default: this
- scope to call the function in
- {Tree.PRE_ORDER|Tree.POST_ORDER|Tree.IN_ORDER|Tree.REVERSE_ORDER} order Optional, Default: Tree.IN_ORDER
- the traversal scheme
insert(data)
Inserts an item into the tree
- Parameters:
- {*} data
- the item to insert
{Boolean}
isEmpty()
Test if a tree is empty
- Returns:
- {Boolean} true if empty false otherwise
{comb.collections.Tree}
map(cb, scope, order)
Loop through each item in the tree, collecting the value returned by the callback funciton.
- Parameters:
- {Function} cb
- called for each item in the tree. Whatever the function returns is inserted into the return tree
- {Object} scope Optional, Default: this
- scope to call the function in
- {Tree.PRE_ORDER|Tree.POST_ORDER|Tree.IN_ORDER|Tree.REVERSE_ORDER} order Optional, Default: Tree.IN_ORDER
- the traversal scheme
- Returns:
- {comb.collections.Tree} the tree with the mapped items
print()
Prints a tree to the console.
reduce(cb, accumulator, order)
Reduces a tree
- Parameters:
- {Function} cb
- called for each item in the tree
- accumulator Optional, Default: First item in tree(Order dependant)
- scope to call the function in
- {Tree.PRE_ORDER|Tree.POST_ORDER|Tree.IN_ORDER|Tree.REVERSE_ORDER} order Optional, Default: Tree.IN_ORDER
- the traversal scheme
- Returns:
- the result of the reduce function
reduceRight(cb, accumulator, order)
Reduces from right to left
- Parameters:
- {Function} cb
- called for each item in the tree
- accumulator Optional, Default: First item in tree(Order dependant)
- scope to call the function in
- {Tree.PRE_ORDER|Tree.POST_ORDER|Tree.IN_ORDER|Tree.REVERSE_ORDER} order Optional, Default: Tree.IN_ORDER
- the traversal scheme
- Returns:
- the result of the reduce function
remove(data)
Removes an item from the tree
- Parameters:
- {*} data
- the item to insert
{Boolean}
some(cb, scope, order)
Determines if some item meet the condition returned by the callback. Traversal ends the first time true is found.
- Parameters:
- {Function} cb
- called for each item in the tree
- {Object} scope Optional, Default: this
- scope to call the function in
- {Tree.PRE_ORDER|Tree.POST_ORDER|Tree.IN_ORDER|Tree.REVERSE_ORDER} order Optional, Default: Tree.IN_ORDER
- the traversal scheme
- Returns:
- {Boolean} True if every item passed false otherwise
{Array}
toArray(order)
Converts a tree into an array based on the specified order
- Parameters:
- {Tree.PRE_ORDER|Tree.POST_ORDER|Tree.IN_ORDER|Tree.REVERSE_ORDER} order Optional, Default: Tree.IN_ORDER
- the traversal scheme
- Returns:
- {Array} array of all items in the order specified.
traverse(node, order, callback)
Traverse a tree
Not typically used directly
- Parameters:
- {Object} node
- the node to start at
- {Tree.PRE_ORDER|Tree.POST_ORDER|Tree.IN_ORDER|Tree.REVERSE_ORDER} order Optional, Default: Tree.IN_ORDER
- the traversal scheme
- {Function} callback
- called for each item
traverseWithCondition(node, order, callback)
Traverse a tree until the callback function returns false
Not typically used directly
- Parameters:
- {Object} node
- the node to start at
- {Tree.PRE_ORDER|Tree.POST_ORDER|Tree.IN_ORDER|Tree.REVERSE_ORDER} order Optional, Default: Tree.IN_ORDER
- the traversal scheme
- {Function} callback
- called for each item, traversal continues until the function returns false