collect-your-stuff 1.2.6 → 1.2.8
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 +2525 -2525
- package/browser/collect-your-stuff.js +22766 -22859
- package/browser/collect-your-stuff.min.js +1 -1
- package/dist/collections/arrayable/ArrayElement.d.ts +36 -36
- package/dist/collections/arrayable/ArrayElement.js +64 -70
- package/dist/collections/arrayable/ArrayElement.min.js +1 -1
- package/dist/collections/arrayable/Arrayable.d.ts +108 -108
- package/dist/collections/arrayable/Arrayable.js +188 -196
- package/dist/collections/arrayable/Arrayable.min.js +1 -1
- package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +46 -46
- package/dist/collections/doubly-linked-list/DoubleLinker.js +69 -77
- package/dist/collections/doubly-linked-list/DoubleLinker.min.js +1 -1
- package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +113 -113
- package/dist/collections/doubly-linked-list/DoublyLinkedList.js +274 -277
- package/dist/collections/doubly-linked-list/DoublyLinkedList.min.js +1 -1
- package/dist/collections/linked-list/LinkedList.d.ts +109 -109
- package/dist/collections/linked-list/LinkedList.js +233 -241
- package/dist/collections/linked-list/LinkedList.min.js +1 -1
- package/dist/collections/linked-list/Linker.d.ts +43 -43
- package/dist/collections/linked-list/Linker.js +80 -86
- package/dist/collections/linked-list/Linker.min.js +1 -1
- package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +135 -135
- package/dist/collections/linked-tree-list/LinkedTreeList.js +252 -261
- package/dist/collections/linked-tree-list/LinkedTreeList.min.js +1 -1
- package/dist/collections/linked-tree-list/TreeLinker.d.ts +63 -63
- package/dist/collections/linked-tree-list/TreeLinker.js +79 -92
- package/dist/collections/linked-tree-list/TreeLinker.min.js +1 -1
- package/dist/collections/queue/Queue.d.ts +63 -63
- package/dist/collections/queue/Queue.js +130 -136
- package/dist/collections/queue/Queue.min.js +1 -1
- package/dist/collections/queue/Queueable.d.ts +77 -77
- package/dist/collections/queue/Queueable.js +141 -151
- package/dist/collections/queue/Queueable.min.js +1 -1
- package/dist/collections/stack/Stack.d.ts +63 -63
- package/dist/collections/stack/Stack.js +106 -112
- package/dist/collections/stack/Stack.min.js +1 -1
- package/dist/collections/stack/Stackable.d.ts +56 -56
- package/dist/collections/stack/Stackable.js +83 -91
- package/dist/collections/stack/Stackable.min.js +1 -1
- package/dist/main.d.ts +40 -40
- package/dist/main.js +50 -50
- package/dist/recipes/ArrayIterator.d.ts +10 -10
- package/dist/recipes/ArrayIterator.js +29 -30
- package/dist/recipes/ArrayIterator.min.js +1 -1
- package/dist/recipes/DoubleLinkerIterator.d.ts +9 -9
- package/dist/recipes/DoubleLinkerIterator.js +24 -24
- package/dist/recipes/IsArrayable.d.ts +105 -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/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 +9 -9
- package/dist/recipes/LinkerIterator.js +24 -24
- package/dist/recipes/Runnable.d.ts +54 -54
- package/dist/recipes/Runnable.js +68 -69
- package/dist/recipes/Runnable.min.js +1 -1
- package/dist/recipes/TreeLinkerIterator.d.ts +9 -9
- package/dist/recipes/TreeLinkerIterator.js +25 -25
- package/dist/recipes/recipes.d.ts +15 -15
- package/dist/recipes/recipes.js +22 -22
- package/dist/services/parseTree.d.ts +9 -9
- package/dist/services/parseTree.js +24 -24
- package/dist/services/parseTreeNext.d.ts +14 -14
- package/dist/services/parseTreeNext.js +47 -47
- package/dist/services/services.d.ts +13 -13
- package/dist/services/services.js +22 -22
- package/package.json +2 -2
|
@@ -1,261 +1,252 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.LinkedTreeList = void 0
|
|
7
|
-
require('
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
*/
|
|
254
|
-
exports.LinkedTreeList = LinkedTreeList
|
|
255
|
-
LinkedTreeList.fromArray = function () {
|
|
256
|
-
const values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []
|
|
257
|
-
const linkerClass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _TreeLinker.TreeLinker
|
|
258
|
-
const classType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : LinkedTreeList
|
|
259
|
-
const list = new classType(linkerClass)
|
|
260
|
-
return list.initialize(linkerClass.fromArray(values).head)
|
|
261
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.LinkedTreeList = void 0
|
|
7
|
+
var _TreeLinker = require('./TreeLinker')
|
|
8
|
+
var _TreeLinkerIterator = require('../../recipes/TreeLinkerIterator')
|
|
9
|
+
var _DoublyLinkedList = require('../doubly-linked-list/DoublyLinkedList')
|
|
10
|
+
/**
|
|
11
|
+
* @file doubly linked tree list.
|
|
12
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
13
|
+
* @version 1.1.0
|
|
14
|
+
* @memberOf module:collect-your-stuff
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* LinkedTreeList represents a collection stored with a root and spreading in branching (tree) formation.
|
|
19
|
+
* @extends DoublyLinkedList
|
|
20
|
+
*/
|
|
21
|
+
class LinkedTreeList {
|
|
22
|
+
/**
|
|
23
|
+
* Create the new LinkedTreeList instance, configure the list class.
|
|
24
|
+
*/
|
|
25
|
+
constructor (linkerClass = _TreeLinker.TreeLinker) {
|
|
26
|
+
this.classType = LinkedTreeList
|
|
27
|
+
this.innerList = null
|
|
28
|
+
this.initialized = false
|
|
29
|
+
this.linkerClass = linkerClass
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Initialize the inner list, should only run once.
|
|
34
|
+
* @param {TreeLinker} initialList Give the list of tree-linkers to start in this linked-tree-list.
|
|
35
|
+
* @return {LinkedTreeList}
|
|
36
|
+
*/
|
|
37
|
+
initialize (initialList) {
|
|
38
|
+
if (this.initialized) {
|
|
39
|
+
console.warn('Attempt to initialize LinkedTreeList which is not empty.')
|
|
40
|
+
return this
|
|
41
|
+
}
|
|
42
|
+
this.initialized = true
|
|
43
|
+
this.innerList = initialList
|
|
44
|
+
return this
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Retrieve a copy of the innerList used.
|
|
49
|
+
* @returns {TreeLinker}
|
|
50
|
+
*/
|
|
51
|
+
get list () {
|
|
52
|
+
return this.innerList
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Retrieve the first TreeLinker in the list.
|
|
57
|
+
* @returns {TreeLinker}
|
|
58
|
+
*/
|
|
59
|
+
get first () {
|
|
60
|
+
return this.reset()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Retrieve the last TreeLinker in the list.
|
|
65
|
+
* @returns {TreeLinker}
|
|
66
|
+
*/
|
|
67
|
+
get last () {
|
|
68
|
+
let tail = this.innerList
|
|
69
|
+
if (tail === null) {
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
let next = tail.next
|
|
73
|
+
while (next !== null) {
|
|
74
|
+
tail = next
|
|
75
|
+
next = tail.next
|
|
76
|
+
}
|
|
77
|
+
return tail
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Return the length of the list.
|
|
82
|
+
* @returns {number}
|
|
83
|
+
*/
|
|
84
|
+
get length () {
|
|
85
|
+
let current = this.first
|
|
86
|
+
let length = 0
|
|
87
|
+
while (current !== null) {
|
|
88
|
+
++length
|
|
89
|
+
current = current.next
|
|
90
|
+
}
|
|
91
|
+
return length
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get the parent of this tree list.
|
|
96
|
+
* @return {TreeLinker}
|
|
97
|
+
*/
|
|
98
|
+
get parent () {
|
|
99
|
+
const first = this.first
|
|
100
|
+
if (first === null) {
|
|
101
|
+
return null
|
|
102
|
+
}
|
|
103
|
+
return this.first.parent
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Set the parent of this tree list
|
|
108
|
+
* @param {TreeLinker} parent The new node to use as the parent for this group of children
|
|
109
|
+
*/
|
|
110
|
+
set parent (parent) {
|
|
111
|
+
let current = this.first
|
|
112
|
+
while (current !== null) {
|
|
113
|
+
current.parent = parent
|
|
114
|
+
current = current.next
|
|
115
|
+
}
|
|
116
|
+
if (parent) {
|
|
117
|
+
parent.children = this
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Return the root parent of the entire tree.
|
|
123
|
+
* @return {TreeLinker}
|
|
124
|
+
*/
|
|
125
|
+
get rootParent () {
|
|
126
|
+
let current = this.first
|
|
127
|
+
if (!current) {
|
|
128
|
+
return null
|
|
129
|
+
}
|
|
130
|
+
let parent = this.first.parent
|
|
131
|
+
while (parent !== null) {
|
|
132
|
+
current = parent
|
|
133
|
+
parent = current.parent
|
|
134
|
+
}
|
|
135
|
+
return current
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Set the children on a parent item.
|
|
140
|
+
* @param {TreeLinker} item The TreeLinker node that will be the parent of the children
|
|
141
|
+
* @param {LinkedTreeList} children The LinkedTreeList which has the child nodes to use
|
|
142
|
+
*/
|
|
143
|
+
setChildren (item, children = null) {
|
|
144
|
+
if (Array.from(this).indexOf(item) < 0) {
|
|
145
|
+
console.error('item is not a child of this')
|
|
146
|
+
}
|
|
147
|
+
children.parent = item
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Insert a new node (or data) after a node.
|
|
152
|
+
* @param {TreeLinker|*} node The existing node as reference
|
|
153
|
+
* @param {TreeLinker|*} newNode The new node to go after the existing node
|
|
154
|
+
* @returns {LinkedTreeList}
|
|
155
|
+
*/
|
|
156
|
+
insertAfter (node, newNode) {
|
|
157
|
+
return _DoublyLinkedList.DoublyLinkedList.prototype.insertAfter.call(this, node, newNode)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Insert a new node (or data) before a node.
|
|
162
|
+
* @param {TreeLinker|*} node The existing node as reference
|
|
163
|
+
* @param {TreeLinker|*} newNode The new node to go before the existing node
|
|
164
|
+
* @returns {LinkedTreeList}
|
|
165
|
+
*/
|
|
166
|
+
insertBefore (node, newNode) {
|
|
167
|
+
return _DoublyLinkedList.DoublyLinkedList.prototype.insertBefore.call(this, node, newNode)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Add a node (or data) after the given (or last) node in the list.
|
|
172
|
+
* @param {TreeLinker|*} node The new node to add to the end of the list
|
|
173
|
+
* @param {TreeLinker} after The existing last node
|
|
174
|
+
* @returns {TreeLinker}
|
|
175
|
+
*/
|
|
176
|
+
append (node, after = this.last) {
|
|
177
|
+
return _DoublyLinkedList.DoublyLinkedList.prototype.append.call(this, node, after)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Add a node (or data) before the given (or first) node in the list.
|
|
182
|
+
* @param {TreeLinker|*} node The new node to add to the start of the list
|
|
183
|
+
* @param {TreeLinker} before The existing first node
|
|
184
|
+
* @returns {TreeLinker}
|
|
185
|
+
*/
|
|
186
|
+
prepend (node, before = this.first) {
|
|
187
|
+
return _DoublyLinkedList.DoublyLinkedList.prototype.prepend.call(this, node, before)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Remove a linker from this linked list.
|
|
192
|
+
* @param {TreeLinker} node The node we wish to remove (and it will be returned after removal)
|
|
193
|
+
* @return {TreeLinker}
|
|
194
|
+
*/
|
|
195
|
+
remove (node) {
|
|
196
|
+
return _DoublyLinkedList.DoublyLinkedList.prototype.remove.call(this, node)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Refresh all references and return head reference.
|
|
201
|
+
* @return {TreeLinker}
|
|
202
|
+
*/
|
|
203
|
+
reset () {
|
|
204
|
+
return _DoublyLinkedList.DoublyLinkedList.prototype.reset.call(this)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Retrieve a TreeLinker item from this list by numeric index, otherwise return null.
|
|
209
|
+
* @param {number} index The integer number for retrieving a node by position.
|
|
210
|
+
* @returns {TreeLinker|null}
|
|
211
|
+
*/
|
|
212
|
+
item (index) {
|
|
213
|
+
return _DoublyLinkedList.DoublyLinkedList.prototype.item.call(this, index)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Be able to run forEach on this LinkedTreeList to iterate over the TreeLinker Items.
|
|
218
|
+
* @param {forEachCallback} callback The function to call for-each tree node
|
|
219
|
+
* @param {LinkedTreeList} thisArg Optional, 'this' reference
|
|
220
|
+
*/
|
|
221
|
+
forEach (callback, thisArg = this) {
|
|
222
|
+
let index = 0
|
|
223
|
+
let current = thisArg.first
|
|
224
|
+
while (current !== null) {
|
|
225
|
+
callback(current, index, thisArg)
|
|
226
|
+
current = current.next
|
|
227
|
+
++index
|
|
228
|
+
}
|
|
229
|
+
return thisArg
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Be able to iterate over this class.
|
|
234
|
+
* @returns {Iterator}
|
|
235
|
+
*/
|
|
236
|
+
[Symbol.iterator] () {
|
|
237
|
+
const root = this.rootParent
|
|
238
|
+
return new _TreeLinkerIterator.TreeLinkerIterator(root)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Convert an array into a LinkedTreeList instance, return the new instance.
|
|
243
|
+
* @param {Array} [values=[]] An array of values which will be converted to nodes in this tree-list
|
|
244
|
+
* @param {TreeLinker} [linkerClass=TreeLinker] The class to use for each node
|
|
245
|
+
* @param {IsArrayable<TreeLinker>} [classType=LinkedTreeList] Provide the type of IsArrayable to use.
|
|
246
|
+
* @returns {LinkedTreeList}
|
|
247
|
+
*/
|
|
248
|
+
exports.LinkedTreeList = LinkedTreeList
|
|
249
|
+
LinkedTreeList.fromArray = (values = [], linkerClass = _TreeLinker.TreeLinker, classType = LinkedTreeList) => {
|
|
250
|
+
const list = new classType(linkerClass)
|
|
251
|
+
return list.initialize(linkerClass.fromArray(values).head)
|
|
252
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LinkedTreeList=void 0
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LinkedTreeList=void 0;var _TreeLinker=require("./TreeLinker"),_TreeLinkerIterator=require("../../recipes/TreeLinkerIterator"),_DoublyLinkedList=require("../doubly-linked-list/DoublyLinkedList");class LinkedTreeList{constructor(e=_TreeLinker.TreeLinker){this.classType=LinkedTreeList,this.innerList=null,this.initialized=!1,this.linkerClass=e}initialize(e){return this.initialized?(console.warn("Attempt to initialize LinkedTreeList which is not empty."),this):(this.initialized=!0,this.innerList=e,this)}get list(){return this.innerList}get first(){return this.reset()}get last(){let e=this.innerList;if(null===e)return null;let t=e.next;for(;null!==t;)e=t,t=e.next;return e}get length(){let e=this.first,t=0;for(;null!==e;)++t,e=e.next;return t}get parent(){return null===this.first?null:this.first.parent}set parent(e){let t=this.first;for(;null!==t;)t.parent=e,t=t.next;e&&(e.children=this)}get rootParent(){let e=this.first;if(!e)return null;let t=this.first.parent;for(;null!==t;)e=t,t=e.parent;return e}setChildren(e,t=null){Array.from(this).indexOf(e)<0&&console.error("item is not a child of this"),t.parent=e}insertAfter(e,t){return _DoublyLinkedList.DoublyLinkedList.prototype.insertAfter.call(this,e,t)}insertBefore(e,t){return _DoublyLinkedList.DoublyLinkedList.prototype.insertBefore.call(this,e,t)}append(e,t=this.last){return _DoublyLinkedList.DoublyLinkedList.prototype.append.call(this,e,t)}prepend(e,t=this.first){return _DoublyLinkedList.DoublyLinkedList.prototype.prepend.call(this,e,t)}remove(e){return _DoublyLinkedList.DoublyLinkedList.prototype.remove.call(this,e)}reset(){return _DoublyLinkedList.DoublyLinkedList.prototype.reset.call(this)}item(e){return _DoublyLinkedList.DoublyLinkedList.prototype.item.call(this,e)}forEach(e,t=this){let i=0,r=t.first;for(;null!==r;)e(r,i,t),r=r.next,++i;return t}[Symbol.iterator](){let e=this.rootParent;return new _TreeLinkerIterator.TreeLinkerIterator(e)}}exports.LinkedTreeList=LinkedTreeList,LinkedTreeList.fromArray=(e=[],t=_TreeLinker.TreeLinker,i=LinkedTreeList)=>new i(t).initialize(t.fromArray(e).head);
|