## symbol-tree **Author:** Joris van der Wel * [symbol-tree](#module_symbol-tree) * [SymbolTree](#exp_module_symbol-tree--SymbolTree) ⏏ * [new SymbolTree([description])](#new_module_symbol-tree--SymbolTree_new) * [.initialize(object)](#module_symbol-tree--SymbolTree+initialize) ⇒ Object * [.hasChildren(object)](#module_symbol-tree--SymbolTree+hasChildren) ⇒ Boolean * [.firstChild(object)](#module_symbol-tree--SymbolTree+firstChild) ⇒ Object * [.lastChild(object)](#module_symbol-tree--SymbolTree+lastChild) ⇒ Object * [.previousSibling(object)](#module_symbol-tree--SymbolTree+previousSibling) ⇒ Object * [.nextSibling(object)](#module_symbol-tree--SymbolTree+nextSibling) ⇒ Object * [.parent(object)](#module_symbol-tree--SymbolTree+parent) ⇒ Object * [.lastInclusiveDescendant(object)](#module_symbol-tree--SymbolTree+lastInclusiveDescendant) ⇒ Object * [.preceding(object, [options])](#module_symbol-tree--SymbolTree+preceding) ⇒ Object * [.following(object, [options])](#module_symbol-tree--SymbolTree+following) ⇒ Object * [.childrenToArray(parent, [options])](#module_symbol-tree--SymbolTree+childrenToArray) ⇒ Array.<Object> * [.ancestorsToArray(object, [options])](#module_symbol-tree--SymbolTree+ancestorsToArray) ⇒ Array.<Object> * [.treeToArray(root, [options])](#module_symbol-tree--SymbolTree+treeToArray) ⇒ Array.<Object> * [.childrenIterator(parent, [options])](#module_symbol-tree--SymbolTree+childrenIterator) ⇒ Object * [.previousSiblingsIterator(object)](#module_symbol-tree--SymbolTree+previousSiblingsIterator) ⇒ Object * [.nextSiblingsIterator(object)](#module_symbol-tree--SymbolTree+nextSiblingsIterator) ⇒ Object * [.ancestorsIterator(object)](#module_symbol-tree--SymbolTree+ancestorsIterator) ⇒ Object * [.treeIterator(root, options)](#module_symbol-tree--SymbolTree+treeIterator) ⇒ Object * [.index(child)](#module_symbol-tree--SymbolTree+index) ⇒ Number * [.childrenCount(parent)](#module_symbol-tree--SymbolTree+childrenCount) ⇒ Number * [.compareTreePosition(left, right)](#module_symbol-tree--SymbolTree+compareTreePosition) ⇒ Number * [.remove(removeObject)](#module_symbol-tree--SymbolTree+remove) ⇒ Object * [.insertBefore(referenceObject, newObject)](#module_symbol-tree--SymbolTree+insertBefore) ⇒ Object * [.insertAfter(referenceObject, newObject)](#module_symbol-tree--SymbolTree+insertAfter) ⇒ Object * [.prependChild(referenceObject, newObject)](#module_symbol-tree--SymbolTree+prependChild) ⇒ Object * [.appendChild(referenceObject, newObject)](#module_symbol-tree--SymbolTree+appendChild) ⇒ Object ### SymbolTree ⏏ **Kind**: Exported class #### new SymbolTree([description]) | Param | Default | Description | | --- | --- | --- | | [description] | 'SymbolTree data' | Description used for the Symbol | #### symbolTree.initialize(object) ⇒ Object You can optionally initialize an object after its creation, to take advantage of V8's fast properties. Also useful if you would like to freeze your object. `O(1)` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) **Returns**: Object - object | Param | Type | | --- | --- | | object | Object | #### symbolTree.hasChildren(object) ⇒ Boolean Returns `true` if the object has any children. Otherwise it returns `false`. `O(1)` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | | --- | --- | | object | Object | #### symbolTree.firstChild(object) ⇒ Object Return the first child of the given object. `O(1)` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | | --- | --- | | object | Object | #### symbolTree.lastChild(object) ⇒ Object Return the last child of the given object. `O(1)` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | | --- | --- | | object | Object | #### symbolTree.previousSibling(object) ⇒ Object Return the previous sibling of the given object. `O(1)` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | | --- | --- | | object | Object | #### symbolTree.nextSibling(object) ⇒ Object Return the nextSibling sibling of the given object. `O(1)` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | | --- | --- | | object | Object | #### symbolTree.parent(object) ⇒ Object Return the parent of the given object. `O(1)` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | | --- | --- | | object | Object | #### symbolTree.lastInclusiveDescendant(object) ⇒ Object Find the inclusive descendant that is last in tree order of the given object. `O(n)` (worst case) where n is the depth of the subtree of `object` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | | --- | --- | | object | Object | #### symbolTree.preceding(object, [options]) ⇒ Object Find the preceding object (A) of the given object (B). An object A is preceding an object B if A and B are in the same tree and A comes before B in tree order. `O(n)` (worst case)
`O(1)` (amortized when walking the entire tree) **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | Description | | --- | --- | --- | | object | Object | | | [options] | Object | | | [options.root] | Object | If set, `root` must be an inclusive ancestor of the return value (or else null is returned). This check _assumes_ that `root` is also an inclusive ancestor of the given `node` | #### symbolTree.following(object, [options]) ⇒ Object Find the following object (A) of the given object (B). An object A is following an object B if A and B are in the same tree and A comes after B in tree order. `O(n)` (worst case) where n is the amount of objects in the entire tree
`O(1)` (amortized when walking the entire tree) **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | Default | Description | | --- | --- | --- | --- | | object | Object | | | | [options] | Object | | | | [options.root] | Object | | If set, `root` must be an inclusive ancestor of the return value (or else null is returned). This check _assumes_ that `root` is also an inclusive ancestor of the given `node` | | [options.skipChildren] | Boolean | false | If set, ignore the children of `object` | #### symbolTree.childrenToArray(parent, [options]) ⇒ Array.<Object> Append all children of the given object to an array. `O(n)` where n is the amount of children of the given `parent` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | Default | Description | | --- | --- | --- | --- | | parent | Object | | | | [options] | Object | | | | [options.array] | Array.<Object> | [] | | | [options.filter] | function | | Function to test each object before it is added to the array. Invoked with arguments (object). Should return `true` if an object is to be included. | | [options.thisArg] | \* | | Value to use as `this` when executing `filter`. | #### symbolTree.ancestorsToArray(object, [options]) ⇒ Array.<Object> Append all inclusive ancestors of the given object to an array. `O(n)` where n is the amount of ancestors of the given `object` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | Default | Description | | --- | --- | --- | --- | | object | Object | | | | [options] | Object | | | | [options.array] | Array.<Object> | [] | | | [options.filter] | function | | Function to test each object before it is added to the array. Invoked with arguments (object). Should return `true` if an object is to be included. | | [options.thisArg] | \* | | Value to use as `this` when executing `filter`. | #### symbolTree.treeToArray(root, [options]) ⇒ Array.<Object> Append all descendants of the given object to an array (in tree order). `O(n)` where n is the amount of objects in the sub-tree of the given `object` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | Default | Description | | --- | --- | --- | --- | | root | Object | | | | [options] | Object | | | | [options.array] | Array.<Object> | [] | | | [options.filter] | function | | Function to test each object before it is added to the array. Invoked with arguments (object). Should return `true` if an object is to be included. | | [options.thisArg] | \* | | Value to use as `this` when executing `filter`. | #### symbolTree.childrenIterator(parent, [options]) ⇒ Object Iterate over all children of the given object `O(1)` for a single iteration **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) **Returns**: Object - An iterable iterator (ES6) | Param | Type | Default | | --- | --- | --- | | parent | Object | | | [options] | Object | | | [options.reverse] | Boolean | false | #### symbolTree.previousSiblingsIterator(object) ⇒ Object Iterate over all the previous siblings of the given object. (in reverse tree order) `O(1)` for a single iteration **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) **Returns**: Object - An iterable iterator (ES6) | Param | Type | | --- | --- | | object | Object | #### symbolTree.nextSiblingsIterator(object) ⇒ Object Iterate over all the next siblings of the given object. (in tree order) `O(1)` for a single iteration **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) **Returns**: Object - An iterable iterator (ES6) | Param | Type | | --- | --- | | object | Object | #### symbolTree.ancestorsIterator(object) ⇒ Object Iterate over all inclusive ancestors of the given object `O(1)` for a single iteration **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) **Returns**: Object - An iterable iterator (ES6) | Param | Type | | --- | --- | | object | Object | #### symbolTree.treeIterator(root, options) ⇒ Object Iterate over all descendants of the given object (in tree order). where n is the amount of objects in the sub-tree of the given `root`: `O(n)` (worst case for a single iterator) `O(n)` (amortized, when completing the iterator)
**Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) **Returns**: Object - An iterable iterator (ES6) | Param | Type | Default | | --- | --- | --- | | root | Object | | | options | Object | | | [options.reverse] | Boolean | false | #### symbolTree.index(child) ⇒ Number Find the index of the given object (the number of preceding siblings). `O(n)` where n is the amount of preceding siblings
`O(1)` (amortized, if the tree is not modified) **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) **Returns**: Number - The number of preceding siblings, or -1 if the object has no parent | Param | Type | | --- | --- | | child | Object | #### symbolTree.childrenCount(parent) ⇒ Number Calculate the number of children. `O(n)` where n is the amount of children
`O(1)` (amortized, if the tree is not modified) **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | | --- | --- | | parent | Object | #### symbolTree.compareTreePosition(left, right) ⇒ Number Compare the position of an object relative to another object. A bit set is returned: The semantics are the same as compareDocumentPosition in DOM, with the exception that DISCONNECTED never occurs with any other bit. where n and m are the amount of ancestors of `left` and `right`; where o is the amount of children of the lowest common ancestor of `left` and `right`: `O(n + m + o)` (worst case) `O(n + m) (amortized, if the tree is not modified) **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) | Param | Type | | --- | --- | | left | Object | | right | Object | #### symbolTree.remove(removeObject) ⇒ Object Remove the object from this tree. Has no effect if already removed. `O(1)` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) **Returns**: Object - removeObject | Param | Type | | --- | --- | | removeObject | Object | #### symbolTree.insertBefore(referenceObject, newObject) ⇒ Object Insert the given object before the reference object. `newObject` is now the previous sibling of `referenceObject`. `O(1)` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) **Returns**: Object - newObject **Throws**: - Error If the newObject is already present in this SymbolTree | Param | Type | | --- | --- | | referenceObject | Object | | newObject | Object | #### symbolTree.insertAfter(referenceObject, newObject) ⇒ Object Insert the given object after the reference object. `newObject` is now the next sibling of `referenceObject`. `O(1)` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) **Returns**: Object - newObject **Throws**: - Error If the newObject is already present in this SymbolTree | Param | Type | | --- | --- | | referenceObject | Object | | newObject | Object | #### symbolTree.prependChild(referenceObject, newObject) ⇒ Object Insert the given object as the first child of the given reference object. `newObject` is now the first child of `referenceObject`. `O(1)` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) **Returns**: Object - newObject **Throws**: - Error If the newObject is already present in this SymbolTree | Param | Type | | --- | --- | | referenceObject | Object | | newObject | Object | #### symbolTree.appendChild(referenceObject, newObject) ⇒ Object Insert the given object as the last child of the given reference object. `newObject` is now the last child of `referenceObject`. `O(1)` **Kind**: instance method of [SymbolTree](#exp_module_symbol-tree--SymbolTree) **Returns**: Object - newObject **Throws**: - Error If the newObject is already present in this SymbolTree | Param | Type | | --- | --- | | referenceObject | Object | | newObject | Object |