@@ -147,7 +147,7 @@ class SymbolTree {
147
147
/**
148
148
* Find the inclusive descendant that is last in tree order of the given object.
149
149
*
150
- * `O(n)` (worst case)
150
+ * `O(n)` (worst case) where n is the depth of the subtree of `object`
151
151
*
152
152
* @method lastInclusiveDescendant
153
153
* @memberOf module:symbol-tree#
@@ -169,7 +169,8 @@ class SymbolTree {
169
169
* An object A is preceding an object B if A and B are in the same tree
170
170
* and A comes before B in tree order.
171
171
*
172
- * `O(n)` (worst case)
172
+ * `O(n)` (worst case) <br>
173
+ * `O(1)` (amortized when walking the entire tree)
173
174
*
174
175
* @method preceding
175
176
* @memberOf module:symbol-tree#
@@ -202,7 +203,8 @@ class SymbolTree {
202
203
* An object A is following an object B if A and B are in the same tree
203
204
* and A comes after B in tree order.
204
205
*
205
- * `O(n)` (worst case)
206
+ * `O(n)` (worst case) where n is the amount of objects in the entire tree<br>
207
+ * `O(1)` (amortized when walking the entire tree)
206
208
*
207
209
* @method following
208
210
* @memberOf module:symbol-tree#
@@ -247,7 +249,7 @@ class SymbolTree {
247
249
/**
248
250
* Append all children of the given object to an array.
249
251
*
250
- * `O(n)`
252
+ * `O(n)` where n is the amount of children of the given `parent`
251
253
*
252
254
* @method childrenToArray
253
255
* @memberOf module:symbol-tree#
@@ -287,7 +289,7 @@ class SymbolTree {
287
289
/**
288
290
* Append all inclusive ancestors of the given object to an array.
289
291
*
290
- * `O(n)`
292
+ * `O(n)` where n is the amount of ancestors of the given `object`
291
293
*
292
294
* @method ancestorsToArray
293
295
* @memberOf module:symbol-tree#
@@ -320,7 +322,7 @@ class SymbolTree {
320
322
/**
321
323
* Append all descendants of the given object to an array (in tree order).
322
324
*
323
- * `O(n)`
325
+ * `O(n)` where n is the amount of objects in the sub-tree of the given `object`
324
326
*
325
327
* @method treeToArray
326
328
* @memberOf module:symbol-tree#
@@ -434,8 +436,9 @@ class SymbolTree {
434
436
/**
435
437
* Iterate over all descendants of the given object (in tree order).
436
438
*
437
- * `O(n)` for the entire iteration<br>
438
- * `O(n)` for a single iteration (worst case)
439
+ * where n is the amount of objects in the sub-tree of the given `root`:
440
+ * `O(n)` (worst case for a single iterator)
441
+ * `O(n)` (amortized, when completing the iterator)<br>
439
442
*
440
443
* @method treeIterator
441
444
* @memberOf module:symbol-tree#
@@ -458,8 +461,8 @@ class SymbolTree {
458
461
/**
459
462
* Find the index of the given object (the number of preceding siblings).
460
463
*
461
- * `O(n)`<br>
462
- * `O(1)` (cached )
464
+ * `O(n)` where n is the amount of preceding siblings <br>
465
+ * `O(1)` (amortized, if the tree is not modified )
463
466
*
464
467
* @method index
465
468
* @memberOf module:symbol-tree#
@@ -512,8 +515,8 @@ class SymbolTree {
512
515
/**
513
516
* Calculate the number of children.
514
517
*
515
- * `O(n)`<br>
516
- * `O(1)` (cached )
518
+ * `O(n)` where n is the amount of children <br>
519
+ * `O(1)` (amortized, if the tree is not modified )
517
520
*
518
521
* @method childrenCount
519
522
* @memberOf module:symbol-tree#
@@ -544,7 +547,10 @@ class SymbolTree {
544
547
* The semantics are the same as compareDocumentPosition in DOM, with the exception that
545
548
* DISCONNECTED never occurs with any other bit.
546
549
*
547
- * `O(n)` (worst case)
550
+ * where n and m are the amount of ancestors of `left` and `right`;
551
+ * where o is the amount of children of the lowest common ancestor of `left` and `right`:
552
+ * `O(n + m + o)` (worst case)
553
+ * `O(n + m) (amortized, if the tree is not modified)
548
554
*
549
555
* @method compareTreePosition
550
556
* @memberOf module:symbol-tree#
@@ -599,6 +605,7 @@ class SymbolTree {
599
605
return TreePosition . DISCONNECTED ;
600
606
}
601
607
608
+ // find the lowest common ancestor
602
609
let commonAncestorIndex = 0 ;
603
610
const ancestorsMinLength = Math . min ( leftAncestors . length , rightAncestors . length ) ;
604
611
0 commit comments