collect-your-stuff 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -3241
- package/browser/collect-your-stuff.js +1585 -1193
- package/browser/collect-your-stuff.min.js +1 -1
- package/dist/collections/arrayable/ArrayElement.d.ts +33 -38
- package/dist/collections/arrayable/ArrayElement.js +64 -66
- package/dist/collections/arrayable/Arrayable.d.ts +107 -122
- package/dist/collections/arrayable/Arrayable.js +208 -223
- package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +45 -50
- package/dist/collections/doubly-linked-list/DoubleLinker.js +71 -73
- package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +108 -125
- package/dist/collections/doubly-linked-list/DoublyLinkedList.js +310 -327
- package/dist/collections/linked-list/LinkedList.d.ts +110 -126
- package/dist/collections/linked-list/LinkedList.js +283 -296
- package/dist/collections/linked-list/Linker.d.ts +41 -46
- package/dist/collections/linked-list/Linker.js +82 -84
- package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +140 -159
- package/dist/collections/linked-tree-list/LinkedTreeList.js +274 -294
- package/dist/collections/linked-tree-list/TreeLinker.d.ts +65 -71
- package/dist/collections/linked-tree-list/TreeLinker.js +91 -94
- package/dist/collections/queue/Queue.d.ts +55 -59
- package/dist/collections/queue/Queue.js +114 -119
- package/dist/collections/queue/Queueable.d.ts +74 -83
- package/dist/collections/queue/Queueable.js +142 -146
- package/dist/collections/queue/TaskQueue.d.ts +59 -68
- package/dist/collections/queue/TaskQueue.js +128 -137
- package/dist/collections/scoped-collection/ScopedCollection.d.ts +42 -0
- package/dist/collections/scoped-collection/ScopedCollection.js +81 -0
- package/dist/collections/scoped-collection/ScopedCollection.min.js +1 -0
- package/dist/collections/stack/Stack.d.ts +60 -64
- package/dist/collections/stack/Stack.js +122 -127
- package/dist/collections/stack/Stackable.d.ts +52 -59
- package/dist/collections/stack/Stackable.js +81 -85
- package/dist/collections/stack/TaskStack.d.ts +56 -65
- package/dist/collections/stack/TaskStack.js +98 -107
- package/dist/main.d.ts +4 -5
- package/dist/main.js +9 -5
- package/dist/main.min.js +1 -1
- package/dist/recipes/ArrayIterator.d.ts +20 -20
- package/dist/recipes/ArrayIterator.js +39 -39
- package/dist/recipes/DoubleLinkerIterator.d.ts +18 -18
- package/dist/recipes/DoubleLinkerIterator.js +33 -33
- package/dist/recipes/IsArrayable.d.ts +85 -105
- package/dist/recipes/IsArrayable.js +5 -5
- package/dist/recipes/IsDoubleLinker.d.ts +14 -14
- package/dist/recipes/IsDoubleLinker.js +5 -5
- package/dist/recipes/IsElement.d.ts +14 -14
- package/dist/recipes/IsElement.js +5 -5
- package/dist/recipes/IsLinker.d.ts +10 -10
- package/dist/recipes/IsLinker.js +5 -5
- package/dist/recipes/IsQueue.d.ts +32 -37
- package/dist/recipes/IsQueue.js +5 -5
- package/dist/recipes/IsScopedCollection.d.ts +27 -0
- package/dist/recipes/IsScopedCollection.js +5 -0
- package/dist/recipes/IsScopedCollection.min.js +1 -0
- package/dist/recipes/IsStack.d.ts +31 -36
- package/dist/recipes/IsStack.js +5 -5
- package/dist/recipes/IsTree.d.ts +11 -11
- package/dist/recipes/IsTree.js +5 -5
- package/dist/recipes/IsTreeNode.d.ts +29 -29
- package/dist/recipes/IsTreeNode.js +5 -5
- package/dist/recipes/LinkerIterator.d.ts +18 -18
- package/dist/recipes/LinkerIterator.js +33 -33
- package/dist/recipes/Runnable.d.ts +42 -55
- package/dist/recipes/Runnable.js +63 -69
- package/dist/recipes/TreeLinkerIterator.d.ts +20 -20
- package/dist/recipes/TreeLinkerIterator.js +36 -36
- package/dist/recipes/recipes.d.ts +12 -15
- package/dist/recipes/recipes.js +19 -22
- package/dist/services/parseTree.d.ts +8 -9
- package/dist/services/parseTree.js +23 -24
- package/dist/services/parseTreeNext.d.ts +16 -17
- package/dist/services/parseTreeNext.js +41 -42
- package/dist/services/services.d.ts +10 -13
- package/dist/services/services.js +19 -22
- package/package.json +4 -4
|
@@ -1,294 +1,274 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.LinkedTreeList = void 0
|
|
7
|
-
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
-
require('core-js/modules/esnext.iterator.for-each.js')
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
this.
|
|
38
|
-
/**
|
|
39
|
-
this.
|
|
40
|
-
/**
|
|
41
|
-
this.
|
|
42
|
-
/** The
|
|
43
|
-
this.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*
|
|
77
|
-
*/
|
|
78
|
-
get
|
|
79
|
-
return borrowedGetter('
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*/
|
|
86
|
-
get
|
|
87
|
-
return borrowedGetter('
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
*
|
|
172
|
-
* @param
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* @
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
*
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
* @returns {Iterator}
|
|
276
|
-
*/
|
|
277
|
-
[Symbol.iterator] () {
|
|
278
|
-
// The linkers of this list and everything below them, left-first. It stays within this list: it does not start at,
|
|
279
|
-
// or climb up to, the parents (use the parseTree service to parse a whole tree)
|
|
280
|
-
return new _TreeLinkerIterator.TreeLinkerIterator(this.first, this.parent)
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Convert an array into a LinkedTreeList instance, return the new instance.
|
|
285
|
-
* @param {Array} [values=[]] An array of values which will be converted to nodes in this tree-list
|
|
286
|
-
* @param {TreeLinker} [linkerClass=TreeLinker] The class to use for each node
|
|
287
|
-
* @param {IsArrayable<TreeLinker>} [classType=LinkedTreeList] Provide the type of IsArrayable to use.
|
|
288
|
-
* @returns {LinkedTreeList}
|
|
289
|
-
*/
|
|
290
|
-
exports.LinkedTreeList = LinkedTreeList
|
|
291
|
-
LinkedTreeList.fromArray = (values = [], linkerClass = _TreeLinker.TreeLinker, classType = LinkedTreeList) => {
|
|
292
|
-
const list = new classType(linkerClass)
|
|
293
|
-
return list.initialize(linkerClass.fromArray(values).head)
|
|
294
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.LinkedTreeList = void 0
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
+
require('core-js/modules/esnext.iterator.for-each.js')
|
|
9
|
+
const _TreeLinker = require('./TreeLinker')
|
|
10
|
+
const _TreeLinkerIterator = require('../../recipes/TreeLinkerIterator')
|
|
11
|
+
const _DoublyLinkedList = require('../doubly-linked-list/DoublyLinkedList')
|
|
12
|
+
/**
|
|
13
|
+
* doubly linked tree list.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Use one of the accessors of DoublyLinkedList (which keeps track of the head, tail and length) for a LinkedTreeList.
|
|
18
|
+
* @param name The accessor to use
|
|
19
|
+
* @param list The list to use it on
|
|
20
|
+
*/
|
|
21
|
+
const borrowedGetter = (name, list) => Object.getOwnPropertyDescriptor(_DoublyLinkedList.DoublyLinkedList.prototype, name).get.call(list)
|
|
22
|
+
/**
|
|
23
|
+
* LinkedTreeList represents a collection stored with a root and spreading in branching (tree) formation.
|
|
24
|
+
* @extends DoublyLinkedList
|
|
25
|
+
*/
|
|
26
|
+
class LinkedTreeList {
|
|
27
|
+
/**
|
|
28
|
+
* Create the new LinkedTreeList instance, configure the list class.
|
|
29
|
+
* @param linkerClass The class used to wrap given data as tree linkers.
|
|
30
|
+
*/
|
|
31
|
+
constructor (linkerClass = _TreeLinker.TreeLinker) {
|
|
32
|
+
/** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
|
|
33
|
+
this.classType = LinkedTreeList
|
|
34
|
+
/** A linker of the list (null when the list is empty); the head is found by walking back from it. */
|
|
35
|
+
this.innerList = null
|
|
36
|
+
/** Whether the inner list has been initialized (it can only be initialized once). */
|
|
37
|
+
this.initialized = false
|
|
38
|
+
/** The last linker, remembered so that adding to the end does not need to walk the whole list (null when not known yet). */
|
|
39
|
+
this.tailCache = null
|
|
40
|
+
/** The number of linkers, kept up to date by the list's own methods so that the length does not need to walk the whole list (null when not known yet). */
|
|
41
|
+
this.countCache = null
|
|
42
|
+
/** The node these linkers are the children of, remembered so that it is known even while the list is empty (undefined until it is known). */
|
|
43
|
+
this.ownerNode = undefined
|
|
44
|
+
this.linkerClass = linkerClass
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Initialize the inner list, should only run once.
|
|
49
|
+
* @param initialList Give the list of tree-linkers to start in this linked-tree-list.
|
|
50
|
+
*/
|
|
51
|
+
initialize (initialList) {
|
|
52
|
+
if (this.initialized) {
|
|
53
|
+
console.warn('Attempt to initialize LinkedTreeList which is not empty.')
|
|
54
|
+
return this
|
|
55
|
+
}
|
|
56
|
+
this.initialized = true
|
|
57
|
+
this.innerList = initialList
|
|
58
|
+
return this
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Retrieve the innerList used (the list itself, not a copy).
|
|
63
|
+
*/
|
|
64
|
+
get list () {
|
|
65
|
+
return this.innerList
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Retrieve the first TreeLinker in the list.
|
|
70
|
+
*/
|
|
71
|
+
get first () {
|
|
72
|
+
return borrowedGetter('first', this)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Retrieve the last TreeLinker in the list. The end is remembered, so this does not walk the list.
|
|
77
|
+
*/
|
|
78
|
+
get last () {
|
|
79
|
+
return borrowedGetter('last', this)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Return the length of the list. It is kept up to date by the list's own methods, so this does not walk the list
|
|
84
|
+
* (call reset() after linkers were changed directly).
|
|
85
|
+
*/
|
|
86
|
+
get length () {
|
|
87
|
+
return borrowedGetter('length', this)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the parent of this tree list: the node these linkers are the children of (remembered even while the list is
|
|
92
|
+
* empty), or null for the linkers at the top of a tree.
|
|
93
|
+
*/
|
|
94
|
+
get parent () {
|
|
95
|
+
if (this.ownerNode !== undefined) {
|
|
96
|
+
return this.ownerNode
|
|
97
|
+
}
|
|
98
|
+
const first = this.first
|
|
99
|
+
return first === null ? null : first.parent
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Set the parent of this tree list: every linker in it gets the node as its parent, and the node gets this list as its
|
|
104
|
+
* children. Linkers added to the list later get this parent too.
|
|
105
|
+
* @param parent The new node to use as the parent for this group of children
|
|
106
|
+
*/
|
|
107
|
+
set parent (parent) {
|
|
108
|
+
this.ownerNode = parent
|
|
109
|
+
let current = this.first
|
|
110
|
+
while (current !== null) {
|
|
111
|
+
current.parent = parent
|
|
112
|
+
current = current.next
|
|
113
|
+
}
|
|
114
|
+
if (parent) {
|
|
115
|
+
parent.children = this
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Return the root parent of the entire tree.
|
|
121
|
+
*/
|
|
122
|
+
get rootParent () {
|
|
123
|
+
let current = this.first
|
|
124
|
+
if (!current) {
|
|
125
|
+
return null
|
|
126
|
+
}
|
|
127
|
+
let parent = this.first.parent
|
|
128
|
+
while (parent !== null) {
|
|
129
|
+
current = parent
|
|
130
|
+
parent = current.parent
|
|
131
|
+
}
|
|
132
|
+
return current
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Set the children on a parent item.
|
|
137
|
+
* @param item The TreeLinker node (one of the linkers of this list) that will be the parent of the children
|
|
138
|
+
* @param children The LinkedTreeList which has the child nodes to use, or null to remove the children of the item
|
|
139
|
+
* @throws {Error} When the item is not one of the linkers of this list
|
|
140
|
+
*/
|
|
141
|
+
setChildren (item, children = null) {
|
|
142
|
+
// The item must be one of the linkers of this list (only the siblings are checked, not the whole tree)
|
|
143
|
+
let isChild = false
|
|
144
|
+
this.forEach(linker => {
|
|
145
|
+
if (linker === item) {
|
|
146
|
+
isChild = true
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
if (!isChild) {
|
|
150
|
+
throw new Error('The item is not one of the linkers of this list.')
|
|
151
|
+
}
|
|
152
|
+
if (children === null || typeof children === 'undefined') {
|
|
153
|
+
item.children = null
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
children.parent = item
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Make a linker of the given node (or data) and make this list's parent its parent.
|
|
161
|
+
* @param newNode The node (or data) which is being added to this list
|
|
162
|
+
*/
|
|
163
|
+
adopt (newNode) {
|
|
164
|
+
const linker = this.linkerClass.make(newNode, this.linkerClass)
|
|
165
|
+
linker.parent = this.parent
|
|
166
|
+
return linker
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Insert a new node (or data) after a node. The new node gets the parent of this list.
|
|
171
|
+
* @param node The existing node as reference, or null to insert at the start of the list
|
|
172
|
+
* @param newNode The new node to go after the existing node
|
|
173
|
+
*/
|
|
174
|
+
insertAfter (node, newNode) {
|
|
175
|
+
return _DoublyLinkedList.DoublyLinkedList.prototype.insertAfter.call(this, node, this.adopt(newNode))
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Insert a new node (or data) before a node. The new node gets the parent of this list.
|
|
180
|
+
* @param node The existing node as reference, or null to insert at the end of the list
|
|
181
|
+
* @param newNode The new node to go before the existing node
|
|
182
|
+
*/
|
|
183
|
+
insertBefore (node, newNode) {
|
|
184
|
+
return _DoublyLinkedList.DoublyLinkedList.prototype.insertBefore.call(this, node, this.adopt(newNode))
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Add a node (or data) after the given (or last) node in the list.
|
|
189
|
+
* @param node The new node to add to the end of the list
|
|
190
|
+
* @param after The existing last node
|
|
191
|
+
*/
|
|
192
|
+
append (node, after = this.last) {
|
|
193
|
+
return _DoublyLinkedList.DoublyLinkedList.prototype.append.call(this, node, after)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Add a node (or data) before the given (or first) node in the list.
|
|
198
|
+
* @param node The new node to add to the start of the list
|
|
199
|
+
* @param before The existing first node
|
|
200
|
+
*/
|
|
201
|
+
prepend (node, before = this.first) {
|
|
202
|
+
return _DoublyLinkedList.DoublyLinkedList.prototype.prepend.call(this, node, before)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Remove a linker from this linked list. The removed node no longer has a parent.
|
|
207
|
+
* @param node The node we wish to remove (and it will be returned after removal)
|
|
208
|
+
* @returns The removed node, or null when there was nothing to remove
|
|
209
|
+
*/
|
|
210
|
+
remove (node) {
|
|
211
|
+
const owner = this.parent
|
|
212
|
+
const removed = _DoublyLinkedList.DoublyLinkedList.prototype.remove.call(this, node)
|
|
213
|
+
if (removed && removed.parent === owner) {
|
|
214
|
+
// Remember whose children these are (the list may now be empty), the removed node no longer has that parent
|
|
215
|
+
this.ownerNode = owner
|
|
216
|
+
removed.parent = null
|
|
217
|
+
}
|
|
218
|
+
return removed
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Refresh all references (the head, the end and the length) by walking the list once, and return the head. The
|
|
223
|
+
* list's own methods keep these up to date, so this is only needed after linkers were changed directly.
|
|
224
|
+
*/
|
|
225
|
+
reset () {
|
|
226
|
+
return _DoublyLinkedList.DoublyLinkedList.prototype.reset.call(this)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Retrieve a TreeLinker item from this list by numeric index, otherwise return null.
|
|
231
|
+
* @param index The integer number for retrieving a node by position.
|
|
232
|
+
*/
|
|
233
|
+
item (index) {
|
|
234
|
+
return _DoublyLinkedList.DoublyLinkedList.prototype.item.call(this, index)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Be able to run forEach on this LinkedTreeList to iterate over the TreeLinker Items.
|
|
239
|
+
* @param callback The function to call for-each tree node
|
|
240
|
+
* @param thisArg Optional, 'this' reference
|
|
241
|
+
* @returns The list which was iterated.
|
|
242
|
+
*/
|
|
243
|
+
forEach (callback, thisArg = this) {
|
|
244
|
+
let index = 0
|
|
245
|
+
let current = thisArg.first
|
|
246
|
+
while (current !== null) {
|
|
247
|
+
callback(current, index, thisArg)
|
|
248
|
+
current = current.next
|
|
249
|
+
++index
|
|
250
|
+
}
|
|
251
|
+
return thisArg
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Be able to iterate over this class: the linkers of this list and everything below them (left-first). It stays within
|
|
256
|
+
* this list (it does not start at, or climb up to, the parents), use the parseTree service to parse a whole tree.
|
|
257
|
+
*/
|
|
258
|
+
[Symbol.iterator] () {
|
|
259
|
+
// The linkers of this list and everything below them, left-first. It stays within this list: it does not start at,
|
|
260
|
+
// or climb up to, the parents (use the parseTree service to parse a whole tree)
|
|
261
|
+
return new _TreeLinkerIterator.TreeLinkerIterator(this.first, this.parent)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Convert an array into a LinkedTreeList instance, return the new instance.
|
|
266
|
+
* @param values An array of values which will be converted to nodes in this tree-list
|
|
267
|
+
* @param linkerClass The class to use for each node
|
|
268
|
+
* @param classType Provide the type of IsArrayable to use.
|
|
269
|
+
*/
|
|
270
|
+
exports.LinkedTreeList = LinkedTreeList
|
|
271
|
+
LinkedTreeList.fromArray = (values = [], linkerClass = _TreeLinker.TreeLinker, classType = LinkedTreeList) => {
|
|
272
|
+
const list = new classType(linkerClass)
|
|
273
|
+
return list.initialize(linkerClass.fromArray(values).head)
|
|
274
|
+
}
|