symbol-tree
Advanced tools
Comparing version 3.1.4 to 3.2.0
80
api.md
@@ -47,3 +47,3 @@ <a name="module_symbol-tree"></a> | ||
#### symbolTree.initialize(object) ⇒ <code>Object</code> | ||
You can optionally initialize an object after its creation, | ||
You can use this function to (optionally) initialize an object right after its creation, | ||
to take advantage of V8's fast properties. Also useful if you would like to | ||
@@ -65,3 +65,3 @@ freeze your object. | ||
`O(1)` | ||
* `O(1)` | ||
@@ -76,5 +76,5 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
#### symbolTree.firstChild(object) ⇒ <code>Object</code> | ||
Return the first child of the given object. | ||
Returns the first child of the given object. | ||
`O(1)` | ||
* `O(1)` | ||
@@ -89,5 +89,5 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
#### symbolTree.lastChild(object) ⇒ <code>Object</code> | ||
Return the last child of the given object. | ||
Returns the last child of the given object. | ||
`O(1)` | ||
* `O(1)` | ||
@@ -102,5 +102,5 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
#### symbolTree.previousSibling(object) ⇒ <code>Object</code> | ||
Return the previous sibling of the given object. | ||
Returns the previous sibling of the given object. | ||
`O(1)` | ||
* `O(1)` | ||
@@ -115,5 +115,5 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
#### symbolTree.nextSibling(object) ⇒ <code>Object</code> | ||
Return the nextSibling sibling of the given object. | ||
Returns the next sibling of the given object. | ||
`O(1)` | ||
* `O(1)` | ||
@@ -130,3 +130,3 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(1)` | ||
* `O(1)` | ||
@@ -143,3 +143,3 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(n)` (worst case) where n is the depth of the subtree of `object` | ||
* `O(n)` (worst case) where `n` is the depth of the subtree of `object` | ||
@@ -158,4 +158,4 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(n)` (worst case) <br> | ||
`O(1)` (amortized when walking the entire tree) | ||
* `O(n)` (worst case) | ||
* `O(1)` (amortized when walking the entire tree) | ||
@@ -176,4 +176,4 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(n)` (worst case) where n is the amount of objects in the entire tree<br> | ||
`O(1)` (amortized when walking the entire tree) | ||
* `O(n)` (worst case) where `n` is the amount of objects in the entire tree | ||
* `O(1)` (amortized when walking the entire tree) | ||
@@ -193,3 +193,3 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(n)` where n is the amount of children of the given `parent` | ||
* `O(n)` where `n` is the amount of children of the given `parent` | ||
@@ -210,3 +210,3 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(n)` where n is the amount of ancestors of the given `object` | ||
* `O(n)` where `n` is the amount of ancestors of the given `object` | ||
@@ -227,3 +227,3 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(n)` where n is the amount of objects in the sub-tree of the given `object` | ||
* `O(n)` where `n` is the amount of objects in the sub-tree of the given `object` | ||
@@ -244,3 +244,3 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(1)` for a single iteration | ||
* `O(1)` for a single iteration | ||
@@ -260,3 +260,3 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(1)` for a single iteration | ||
* `O(1)` for a single iteration | ||
@@ -274,3 +274,3 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(1)` for a single iteration | ||
* `O(1)` for a single iteration | ||
@@ -288,3 +288,3 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(1)` for a single iteration | ||
* `O(1)` for a single iteration | ||
@@ -302,6 +302,7 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
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)<br> | ||
Where `n` is the amount of objects in the sub-tree of the given `root`: | ||
* `O(n)` (worst case for a single iteration) | ||
* `O(n)` (amortized, when completing the iterator) | ||
**Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
@@ -320,4 +321,4 @@ **Returns**: <code>Object</code> - An iterable iterator (ES6) | ||
`O(n)` where n is the amount of preceding siblings<br> | ||
`O(1)` (amortized, if the tree is not modified) | ||
* `O(n)` where `n` is the amount of preceding siblings | ||
* `O(1)` (amortized, if the tree is not modified) | ||
@@ -335,4 +336,4 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(n)` where n is the amount of children<br> | ||
`O(1)` (amortized, if the tree is not modified) | ||
* `O(n)` where `n` is the amount of children | ||
* `O(1)` (amortized, if the tree is not modified) | ||
@@ -360,7 +361,8 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
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) | ||
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 <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
@@ -378,3 +380,3 @@ | ||
`O(1)` | ||
* `O(1)` | ||
@@ -393,3 +395,3 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(1)` | ||
* `O(1)` | ||
@@ -413,3 +415,3 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(1)` | ||
* `O(1)` | ||
@@ -433,3 +435,3 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(1)` | ||
* `O(1)` | ||
@@ -453,3 +455,3 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> | ||
`O(1)` | ||
* `O(1)` | ||
@@ -456,0 +458,0 @@ **Kind**: instance method of <code>[SymbolTree](#exp_module_symbol-tree--SymbolTree)</code> |
@@ -25,3 +25,3 @@ 'use strict'; | ||
* @alias module:symbol-tree | ||
* @param [description='SymbolTree data'] Description used for the Symbol | ||
* @param {string} [description='SymbolTree data'] Description used for the Symbol | ||
*/ | ||
@@ -33,3 +33,3 @@ constructor(description) { | ||
/** | ||
* You can optionally initialize an object after its creation, | ||
* You can use this function to (optionally) initialize an object right after its creation, | ||
* to take advantage of V8's fast properties. Also useful if you would like to | ||
@@ -68,3 +68,3 @@ * freeze your object. | ||
* | ||
* `O(1)` | ||
* * `O(1)` | ||
* | ||
@@ -81,5 +81,5 @@ * @method hasChildren | ||
/** | ||
* Return the first child of the given object. | ||
* Returns the first child of the given object. | ||
* | ||
* `O(1)` | ||
* * `O(1)` | ||
* | ||
@@ -96,5 +96,5 @@ * @method firstChild | ||
/** | ||
* Return the last child of the given object. | ||
* Returns the last child of the given object. | ||
* | ||
* `O(1)` | ||
* * `O(1)` | ||
* | ||
@@ -111,5 +111,5 @@ * @method lastChild | ||
/** | ||
* Return the previous sibling of the given object. | ||
* Returns the previous sibling of the given object. | ||
* | ||
* `O(1)` | ||
* * `O(1)` | ||
* | ||
@@ -126,5 +126,5 @@ * @method previousSibling | ||
/** | ||
* Return the nextSibling sibling of the given object. | ||
* Returns the next sibling of the given object. | ||
* | ||
* `O(1)` | ||
* * `O(1)` | ||
* | ||
@@ -143,3 +143,3 @@ * @method nextSibling | ||
* | ||
* `O(1)` | ||
* * `O(1)` | ||
* | ||
@@ -158,3 +158,3 @@ * @method parent | ||
* | ||
* `O(n)` (worst case) where n is the depth of the subtree of `object` | ||
* * `O(n)` (worst case) where `n` is the depth of the subtree of `object` | ||
* | ||
@@ -168,8 +168,9 @@ * @method lastInclusiveDescendant | ||
let lastChild; | ||
let current = object; | ||
while ( (lastChild = this._node(object).lastChild) ) { | ||
object = lastChild; | ||
while ((lastChild = this._node(current).lastChild)) { | ||
current = lastChild; | ||
} | ||
return object; | ||
return current; | ||
} | ||
@@ -182,4 +183,4 @@ | ||
* | ||
* `O(n)` (worst case) <br> | ||
* `O(1)` (amortized when walking the entire tree) | ||
* * `O(n)` (worst case) | ||
* * `O(1)` (amortized when walking the entire tree) | ||
* | ||
@@ -192,4 +193,4 @@ * @method preceding | ||
* of the return value (or else null is returned). This check _assumes_ | ||
* that `root` is also an inclusive ancestor of the given `node` | ||
* @returns {?Object} | ||
* that `root` is also an inclusive ancestor of the given `object` | ||
* @return {?Object} | ||
*/ | ||
@@ -218,4 +219,4 @@ preceding(object, options) { | ||
* | ||
* `O(n)` (worst case) where n is the amount of objects in the entire tree<br> | ||
* `O(1)` (amortized when walking the entire tree) | ||
* * `O(n)` (worst case) where `n` is the amount of objects in the entire tree | ||
* * `O(1)` (amortized when walking the entire tree) | ||
* | ||
@@ -228,5 +229,5 @@ * @method following | ||
* of the return value (or else null is returned). This check _assumes_ | ||
* that `root` is also an inclusive ancestor of the given `node` | ||
* that `root` is also an inclusive ancestor of the given `object` | ||
* @param {Boolean} [options.skipChildren=false] If set, ignore the children of `object` | ||
* @returns {?Object} | ||
* @return {?Object} | ||
*/ | ||
@@ -243,8 +244,10 @@ following(object, options) { | ||
let current = object; | ||
do { | ||
if (object === treeRoot) { | ||
if (current === treeRoot) { | ||
return null; | ||
} | ||
const nextSibling = this._node(object).nextSibling; | ||
const nextSibling = this._node(current).nextSibling; | ||
@@ -255,7 +258,4 @@ if (nextSibling) { | ||
object = this._node(object).parent; | ||
// https://github.com/jscs-dev/node-jscs/commit/07d30b77388a2e182a40b00891c7ac1837281016 | ||
// jscs:disable requirePaddingNewlinesBeforeKeywords | ||
} while (object); | ||
// jscs:enable requirePaddingNewlinesBeforeKeywords | ||
current = this._node(current).parent; | ||
} while (current); | ||
@@ -268,3 +268,3 @@ return null; | ||
* | ||
* `O(n)` where n is the amount of children of the given `parent` | ||
* * `O(n)` where `n` is the amount of children of the given `parent` | ||
* | ||
@@ -283,4 +283,4 @@ * @method childrenToArray | ||
childrenToArray(parent, options) { | ||
const array = (options && options.array ) || []; | ||
const filter = (options && options.filter ) || returnTrue; | ||
const array = (options && options.array) || []; | ||
const filter = (options && options.filter) || returnTrue; | ||
const thisArg = (options && options.thisArg) || undefined; | ||
@@ -310,3 +310,3 @@ | ||
* | ||
* `O(n)` where n is the amount of ancestors of the given `object` | ||
* * `O(n)` where `n` is the amount of ancestors of the given `object` | ||
* | ||
@@ -325,4 +325,4 @@ * @method ancestorsToArray | ||
ancestorsToArray(object, options) { | ||
const array = (options && options.array ) || []; | ||
const filter = (options && options.filter ) || returnTrue; | ||
const array = (options && options.array) || []; | ||
const filter = (options && options.filter) || returnTrue; | ||
const thisArg = (options && options.thisArg) || undefined; | ||
@@ -345,3 +345,3 @@ | ||
* | ||
* `O(n)` where n is the amount of objects in the sub-tree of the given `object` | ||
* * `O(n)` where `n` is the amount of objects in the sub-tree of the given `object` | ||
* | ||
@@ -360,4 +360,4 @@ * @method treeToArray | ||
treeToArray(root, options) { | ||
const array = (options && options.array ) || []; | ||
const filter = (options && options.filter ) || returnTrue; | ||
const array = (options && options.array) || []; | ||
const filter = (options && options.filter) || returnTrue; | ||
const thisArg = (options && options.thisArg) || undefined; | ||
@@ -380,3 +380,3 @@ | ||
* | ||
* `O(1)` for a single iteration | ||
* * `O(1)` for a single iteration | ||
* | ||
@@ -405,3 +405,3 @@ * @method childrenIterator | ||
* | ||
* `O(1)` for a single iteration | ||
* * `O(1)` for a single iteration | ||
* | ||
@@ -425,3 +425,3 @@ * @method previousSiblingsIterator | ||
* | ||
* `O(1)` for a single iteration | ||
* * `O(1)` for a single iteration | ||
* | ||
@@ -445,3 +445,3 @@ * @method nextSiblingsIterator | ||
* | ||
* `O(1)` for a single iteration | ||
* * `O(1)` for a single iteration | ||
* | ||
@@ -465,6 +465,7 @@ * @method ancestorsIterator | ||
* | ||
* 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)<br> | ||
* Where `n` is the amount of objects in the sub-tree of the given `root`: | ||
* | ||
* * `O(n)` (worst case for a single iteration) | ||
* * `O(n)` (amortized, when completing the iterator) | ||
* | ||
* @method treeIterator | ||
@@ -491,4 +492,4 @@ * @memberOf module:symbol-tree# | ||
* | ||
* `O(n)` where n is the amount of preceding siblings<br> | ||
* `O(1)` (amortized, if the tree is not modified) | ||
* * `O(n)` where `n` is the amount of preceding siblings | ||
* * `O(1)` (amortized, if the tree is not modified) | ||
* | ||
@@ -546,4 +547,4 @@ * @method index | ||
* | ||
* `O(n)` where n is the amount of children<br> | ||
* `O(1)` (amortized, if the tree is not modified) | ||
* * `O(n)` where `n` is the amount of children | ||
* * `O(1)` (amortized, if the tree is not modified) | ||
* | ||
@@ -579,7 +580,8 @@ * @method childrenCount | ||
* | ||
* 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) | ||
* 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) | ||
* | ||
* @method compareTreePosition | ||
@@ -643,3 +645,3 @@ * @memberOf module:symbol-tree# | ||
for (let i = 0; i < ancestorsMinLength; ++i) { | ||
const leftAncestor = reverseArrayIndex(leftAncestors , i); | ||
const leftAncestor = reverseArrayIndex(leftAncestors, i); | ||
const rightAncestor = reverseArrayIndex(rightAncestors, i); | ||
@@ -655,3 +657,3 @@ | ||
// indexes within the common ancestor | ||
const leftIndex = this.index(reverseArrayIndex(leftAncestors , commonAncestorIndex + 1)); | ||
const leftIndex = this.index(reverseArrayIndex(leftAncestors, commonAncestorIndex + 1)); | ||
const rightIndex = this.index(reverseArrayIndex(rightAncestors, commonAncestorIndex + 1)); | ||
@@ -668,3 +670,3 @@ | ||
* | ||
* `O(1)` | ||
* * `O(1)` | ||
* | ||
@@ -715,3 +717,3 @@ * @method remove | ||
* | ||
* `O(1)` | ||
* * `O(1)` | ||
* | ||
@@ -759,3 +761,3 @@ * @method insertBefore | ||
* | ||
* `O(1)` | ||
* * `O(1)` | ||
* | ||
@@ -803,3 +805,3 @@ * @method insertAfter | ||
* | ||
* `O(1)` | ||
* * `O(1)` | ||
* | ||
@@ -838,3 +840,3 @@ * @method prependChild | ||
* | ||
* `O(1)` | ||
* * `O(1)` | ||
* | ||
@@ -841,0 +843,0 @@ * @method appendChild |
@@ -24,7 +24,7 @@ 'use strict'; | ||
get isAttached() { | ||
return !!(this.parent || this.previousSibling || this.nextSibling); | ||
return Boolean(this.parent || this.previousSibling || this.nextSibling); | ||
} | ||
get hasChildren() { | ||
return !!this.firstChild; | ||
return Boolean(this.firstChild); | ||
} | ||
@@ -31,0 +31,0 @@ |
@@ -23,4 +23,4 @@ 'use strict'; | ||
return { | ||
done : true, | ||
value : root | ||
done: true, | ||
value: root, | ||
}; | ||
@@ -43,3 +43,3 @@ } | ||
} | ||
else /*if (iterateFunc === 5)*/ { | ||
else /* if (iterateFunc === 5)*/ { | ||
this[NEXT] = tree.following(value, {root: root}); | ||
@@ -49,4 +49,4 @@ } | ||
return { | ||
done : false, | ||
value : value | ||
done: false, | ||
value: value, | ||
}; | ||
@@ -57,6 +57,6 @@ } | ||
Object.defineProperty(TreeIterator.prototype, Symbol.iterator, { | ||
writable : false, | ||
value : function() { | ||
value: function() { | ||
return this; | ||
} | ||
}, | ||
writable: false, | ||
}); | ||
@@ -63,0 +63,0 @@ |
'use strict'; | ||
/* eslint-disable sort-keys */ | ||
module.exports = Object.freeze({ | ||
// same as DOM DOCUMENT_POSITION_ | ||
DISCONNECTED : 1, | ||
PRECEDING : 2, | ||
FOLLOWING : 4, | ||
CONTAINS : 8, | ||
CONTAINED_BY : 16 | ||
DISCONNECTED: 1, | ||
PRECEDING: 2, | ||
FOLLOWING: 4, | ||
CONTAINS: 8, | ||
CONTAINED_BY: 16, | ||
}); |
{ | ||
"name": "symbol-tree", | ||
"version": "3.1.4", | ||
"version": "3.2.0", | ||
"description": "Turn any collection of objects into its own efficient tree or linked list using Symbol", | ||
"main": "lib/SymbolTree.js", | ||
"scripts": { | ||
"lint": "eslint lib test", | ||
"test": "istanbul cover test/SymbolTree.js", | ||
"posttest": "jshint lib test && jscs lib test", | ||
"posttest": "npm run lint", | ||
"documentation": "jsdoc2md --src lib/SymbolTree.js > ./jsdoc/api.md" | ||
@@ -25,2 +26,6 @@ }, | ||
], | ||
"files": [ | ||
"lib", | ||
"api.md" | ||
], | ||
"author": "Joris van der Wel <joris@jorisvanderwel.com>", | ||
@@ -33,31 +38,9 @@ "license": "MIT", | ||
"devDependencies": { | ||
"babel-eslint": "^7.1.1", | ||
"eslint": "^3.12.0", | ||
"eslint-plugin-import": "^2.2.0", | ||
"istanbul": "^0.3.17", | ||
"jscs": "^1.13.1", | ||
"jsdoc-to-markdown": "^1.1.1", | ||
"jshint": "^2.8.0", | ||
"tape": "^4.0.0" | ||
}, | ||
"jshintConfig": { | ||
"esnext": true, | ||
"node": true, | ||
"bitwise": true, | ||
"camelcase": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"forin": true, | ||
"freeze": true, | ||
"immed": true, | ||
"indent": 8, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"nonbsp": true, | ||
"nonew": true, | ||
"quotmark": "single", | ||
"undef": true, | ||
"unused": "vars", | ||
"strict": true, | ||
"laxbreak": true, | ||
"varstmt": true | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56236
6
8
828