collect-your-stuff 1.2.7 → 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 -22761
- 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 -64
- package/dist/collections/arrayable/Arrayable.d.ts +108 -108
- package/dist/collections/arrayable/Arrayable.js +188 -188
- package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +46 -46
- package/dist/collections/doubly-linked-list/DoubleLinker.js +69 -69
- package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +113 -113
- package/dist/collections/doubly-linked-list/DoublyLinkedList.js +274 -269
- 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 -233
- package/dist/collections/linked-list/Linker.d.ts +43 -43
- package/dist/collections/linked-list/Linker.js +80 -80
- package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +135 -135
- package/dist/collections/linked-tree-list/LinkedTreeList.js +252 -252
- package/dist/collections/linked-tree-list/TreeLinker.d.ts +63 -63
- package/dist/collections/linked-tree-list/TreeLinker.js +79 -79
- package/dist/collections/queue/Queue.d.ts +63 -63
- package/dist/collections/queue/Queue.js +130 -130
- package/dist/collections/queue/Queueable.d.ts +77 -77
- package/dist/collections/queue/Queueable.js +141 -141
- package/dist/collections/stack/Stack.d.ts +63 -63
- package/dist/collections/stack/Stack.js +106 -106
- package/dist/collections/stack/Stackable.d.ts +56 -56
- package/dist/collections/stack/Stackable.js +83 -83
- 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 -29
- 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 -68
- 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 +1 -1
|
@@ -1,252 +1,252 @@
|
|
|
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
|
+
'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,63 +1,63 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file doubly linked tree node.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.1.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
6
|
-
*/
|
|
7
|
-
import { IsArrayable } from '../../recipes/IsArrayable';
|
|
8
|
-
import { IsTreeNode } from '../../recipes/IsTreeNode';
|
|
9
|
-
import { IsTree } from '../../recipes/IsTree';
|
|
10
|
-
/**
|
|
11
|
-
* TreeLinker represents a node in a LinkedTreeList having a parent (or root) and child nodes.
|
|
12
|
-
* @extends DoubleLinker
|
|
13
|
-
*/
|
|
14
|
-
export declare class TreeLinker implements IsTreeNode {
|
|
15
|
-
readonly classType: typeof TreeLinker;
|
|
16
|
-
data: any;
|
|
17
|
-
next: IsTreeNode | null;
|
|
18
|
-
prev: IsTreeNode | null;
|
|
19
|
-
parent: IsTreeNode;
|
|
20
|
-
children: IsArrayable<IsTreeNode>;
|
|
21
|
-
/**
|
|
22
|
-
* Create the new TreeLinker instance, provide the data and optionally set references for next, prev, parent, or children.
|
|
23
|
-
* @param {Object} [settings={}]
|
|
24
|
-
* @param {*} [settings.data=null] The data to be stored in this tree node
|
|
25
|
-
* @param {TreeLinker} [settings.next=null] The reference to the next linker if any
|
|
26
|
-
* @param {TreeLinker} [settings.prev=null] The reference to the previous linker if any
|
|
27
|
-
* @param {LinkedTreeList} [settings.children=null] The references to child linkers if any
|
|
28
|
-
* @param {TreeLinker} [settings.parent=null] The reference to a parent linker if any
|
|
29
|
-
* @param {IsArrayable<IsTreeNode>} listClass Give the type of list to use for storing the children
|
|
30
|
-
*/
|
|
31
|
-
constructor({ data, next, prev, children, parent, listClass }?: {
|
|
32
|
-
data?: any;
|
|
33
|
-
next?: IsTreeNode;
|
|
34
|
-
prev?: IsTreeNode;
|
|
35
|
-
children?: Array<any>;
|
|
36
|
-
parent?: IsTreeNode;
|
|
37
|
-
listClass?: any;
|
|
38
|
-
});
|
|
39
|
-
/**
|
|
40
|
-
* Create the children for this tree from an array.
|
|
41
|
-
* @param {Array|null} children Provide an array of data / linker references to be children of this tree node.
|
|
42
|
-
* @param {IsArrayable<IsTreeNode>} listClass Give the type of list to use for storing the children
|
|
43
|
-
* @return {LinkedTreeList|null}
|
|
44
|
-
*/
|
|
45
|
-
childrenFromArray(children?: Array<any> | null, listClass?: any): IsTree | any;
|
|
46
|
-
/**
|
|
47
|
-
* Make a new DoubleLinker from the data given if it is not already a valid Linker.
|
|
48
|
-
* @param {TreeLinker|*} linker Return a valid TreeLinker instance from given data, or even an already valid one.
|
|
49
|
-
* @param {IsTreeNode} [classType=TreeLinker] Provide the type of IsTreeNode to use.
|
|
50
|
-
* @return {TreeLinker}
|
|
51
|
-
*/
|
|
52
|
-
static make: (linker: TreeLinker | any, classType?: any) => IsTreeNode | any;
|
|
53
|
-
/**
|
|
54
|
-
* Convert an array into DoubleLinker instances, return the head and tail DoubleLinkers.
|
|
55
|
-
* @param {Array} [values=[]] Provide an array of data that will be converted to a chain of tree-linkers.
|
|
56
|
-
* @param {IsTreeNode} [classType=TreeLinker] Provide the type of IsTreeNode to use.
|
|
57
|
-
* @returns {{head: TreeLinker, tail: TreeLinker}}
|
|
58
|
-
*/
|
|
59
|
-
static fromArray: (values?: Array<any>, classType?: any) => {
|
|
60
|
-
head: TreeLinker | any;
|
|
61
|
-
tail: TreeLinker | any;
|
|
62
|
-
};
|
|
63
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @file doubly linked tree node.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.1.0
|
|
5
|
+
* @memberOf module:collect-your-stuff
|
|
6
|
+
*/
|
|
7
|
+
import { IsArrayable } from '../../recipes/IsArrayable';
|
|
8
|
+
import { IsTreeNode } from '../../recipes/IsTreeNode';
|
|
9
|
+
import { IsTree } from '../../recipes/IsTree';
|
|
10
|
+
/**
|
|
11
|
+
* TreeLinker represents a node in a LinkedTreeList having a parent (or root) and child nodes.
|
|
12
|
+
* @extends DoubleLinker
|
|
13
|
+
*/
|
|
14
|
+
export declare class TreeLinker implements IsTreeNode {
|
|
15
|
+
readonly classType: typeof TreeLinker;
|
|
16
|
+
data: any;
|
|
17
|
+
next: IsTreeNode | null;
|
|
18
|
+
prev: IsTreeNode | null;
|
|
19
|
+
parent: IsTreeNode;
|
|
20
|
+
children: IsArrayable<IsTreeNode>;
|
|
21
|
+
/**
|
|
22
|
+
* Create the new TreeLinker instance, provide the data and optionally set references for next, prev, parent, or children.
|
|
23
|
+
* @param {Object} [settings={}]
|
|
24
|
+
* @param {*} [settings.data=null] The data to be stored in this tree node
|
|
25
|
+
* @param {TreeLinker} [settings.next=null] The reference to the next linker if any
|
|
26
|
+
* @param {TreeLinker} [settings.prev=null] The reference to the previous linker if any
|
|
27
|
+
* @param {LinkedTreeList} [settings.children=null] The references to child linkers if any
|
|
28
|
+
* @param {TreeLinker} [settings.parent=null] The reference to a parent linker if any
|
|
29
|
+
* @param {IsArrayable<IsTreeNode>} listClass Give the type of list to use for storing the children
|
|
30
|
+
*/
|
|
31
|
+
constructor({ data, next, prev, children, parent, listClass }?: {
|
|
32
|
+
data?: any;
|
|
33
|
+
next?: IsTreeNode;
|
|
34
|
+
prev?: IsTreeNode;
|
|
35
|
+
children?: Array<any>;
|
|
36
|
+
parent?: IsTreeNode;
|
|
37
|
+
listClass?: any;
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Create the children for this tree from an array.
|
|
41
|
+
* @param {Array|null} children Provide an array of data / linker references to be children of this tree node.
|
|
42
|
+
* @param {IsArrayable<IsTreeNode>} listClass Give the type of list to use for storing the children
|
|
43
|
+
* @return {LinkedTreeList|null}
|
|
44
|
+
*/
|
|
45
|
+
childrenFromArray(children?: Array<any> | null, listClass?: any): IsTree | any;
|
|
46
|
+
/**
|
|
47
|
+
* Make a new DoubleLinker from the data given if it is not already a valid Linker.
|
|
48
|
+
* @param {TreeLinker|*} linker Return a valid TreeLinker instance from given data, or even an already valid one.
|
|
49
|
+
* @param {IsTreeNode} [classType=TreeLinker] Provide the type of IsTreeNode to use.
|
|
50
|
+
* @return {TreeLinker}
|
|
51
|
+
*/
|
|
52
|
+
static make: (linker: TreeLinker | any, classType?: any) => IsTreeNode | any;
|
|
53
|
+
/**
|
|
54
|
+
* Convert an array into DoubleLinker instances, return the head and tail DoubleLinkers.
|
|
55
|
+
* @param {Array} [values=[]] Provide an array of data that will be converted to a chain of tree-linkers.
|
|
56
|
+
* @param {IsTreeNode} [classType=TreeLinker] Provide the type of IsTreeNode to use.
|
|
57
|
+
* @returns {{head: TreeLinker, tail: TreeLinker}}
|
|
58
|
+
*/
|
|
59
|
+
static fromArray: (values?: Array<any>, classType?: any) => {
|
|
60
|
+
head: TreeLinker | any;
|
|
61
|
+
tail: TreeLinker | any;
|
|
62
|
+
};
|
|
63
|
+
}
|