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,233 +1,233 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.LinkedList = void 0
|
|
7
|
-
var _Linker = require('./Linker')
|
|
8
|
-
var _LinkerIterator = require('../../recipes/LinkerIterator')
|
|
9
|
-
var _Arrayable = require('../arrayable/Arrayable')
|
|
10
|
-
/**
|
|
11
|
-
* LinkedList represents a collection stored as a LinkedList with next references.
|
|
12
|
-
* @extends Arrayable
|
|
13
|
-
*/
|
|
14
|
-
class LinkedList {
|
|
15
|
-
/**
|
|
16
|
-
* Create the new LinkedList instance.
|
|
17
|
-
*/
|
|
18
|
-
constructor (linkerClass = _Linker.Linker) {
|
|
19
|
-
this.classType = LinkedList
|
|
20
|
-
this.innerList = null
|
|
21
|
-
this.initialized = false
|
|
22
|
-
this.linkerClass = linkerClass
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Initialize the inner list, should only run once.
|
|
27
|
-
* @param {Linker|Array} initialList Give the list of linkers to start in this linked-list.
|
|
28
|
-
* @return {LinkedList}
|
|
29
|
-
*/
|
|
30
|
-
initialize (initialList) {
|
|
31
|
-
return _Arrayable.Arrayable.prototype.initialize.call(this, initialList)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Retrieve a copy of the innerList used.
|
|
36
|
-
* @returns {Linker}
|
|
37
|
-
*/
|
|
38
|
-
get list () {
|
|
39
|
-
return this.innerList
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Retrieve the first Linker in the list.
|
|
44
|
-
* @returns {Linker}
|
|
45
|
-
*/
|
|
46
|
-
get first () {
|
|
47
|
-
return this.innerList
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Retrieve the last Linker in the list.
|
|
52
|
-
* @returns {Linker}
|
|
53
|
-
*/
|
|
54
|
-
get last () {
|
|
55
|
-
let tail = this.innerList
|
|
56
|
-
if (tail === null) {
|
|
57
|
-
return null
|
|
58
|
-
}
|
|
59
|
-
let next = tail.next
|
|
60
|
-
while (next !== null) {
|
|
61
|
-
tail = next
|
|
62
|
-
next = tail.next
|
|
63
|
-
}
|
|
64
|
-
return tail
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Return the length of the list.
|
|
69
|
-
* @returns {number}
|
|
70
|
-
*/
|
|
71
|
-
get length () {
|
|
72
|
-
let current = this.first
|
|
73
|
-
let length = 0
|
|
74
|
-
while (current !== null) {
|
|
75
|
-
++length
|
|
76
|
-
current = current.next
|
|
77
|
-
}
|
|
78
|
-
return length
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Insert a new node (or data) after a node.
|
|
83
|
-
* @param {Linker|*} node The existing node as reference
|
|
84
|
-
* @param {Linker|*} newNode The new node to go after the existing node
|
|
85
|
-
* @returns {LinkedList}
|
|
86
|
-
*/
|
|
87
|
-
insertAfter (node, newNode) {
|
|
88
|
-
newNode = this.linkerClass.make(newNode)
|
|
89
|
-
if (node !== null) {
|
|
90
|
-
// Ensure the next reference of this node is assigned to the new node
|
|
91
|
-
newNode.next = node.next
|
|
92
|
-
// Then set this node's next reference to the new node
|
|
93
|
-
node.next = newNode
|
|
94
|
-
}
|
|
95
|
-
if (!this.length) {
|
|
96
|
-
this.innerList = newNode
|
|
97
|
-
}
|
|
98
|
-
return this
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Insert a new node (or data) before a node.
|
|
103
|
-
* @param {Linker|*} node The existing node as reference
|
|
104
|
-
* @param {Linker|*} newNode The new node to go before the existing node
|
|
105
|
-
* @returns {LinkedList}
|
|
106
|
-
*/
|
|
107
|
-
insertBefore (node, newNode) {
|
|
108
|
-
newNode = this.linkerClass.make(newNode)
|
|
109
|
-
let prevNode = null
|
|
110
|
-
let currentNode = this.first
|
|
111
|
-
while (currentNode !== node) {
|
|
112
|
-
prevNode = currentNode
|
|
113
|
-
currentNode = currentNode.next
|
|
114
|
-
}
|
|
115
|
-
// The new node will reference this node as next
|
|
116
|
-
newNode.next = node
|
|
117
|
-
if (prevNode) {
|
|
118
|
-
// Ensure the next reference of the previous node is assigned to the new node
|
|
119
|
-
prevNode.next = newNode
|
|
120
|
-
}
|
|
121
|
-
if (node === this.first || node === null) {
|
|
122
|
-
this.innerList = newNode
|
|
123
|
-
}
|
|
124
|
-
return this
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Add a node (or data) after the given (or last) node in the list.
|
|
129
|
-
* @param {Linker|*} node The new node to add to the end of the list
|
|
130
|
-
* @param {Linker} after The existing last node
|
|
131
|
-
* @returns {Linker}
|
|
132
|
-
*/
|
|
133
|
-
append (node, after = this.last) {
|
|
134
|
-
return this.insertAfter(after, node)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Add a node (or data) before the given (or first) node in the list.
|
|
139
|
-
* @param {Linker|*} node The new node to add to the start of the list
|
|
140
|
-
* @param {Linker} before The existing first node
|
|
141
|
-
* @returns {Linker}
|
|
142
|
-
*/
|
|
143
|
-
prepend (node, before = this.first) {
|
|
144
|
-
return this.insertBefore(before, node)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Remove a linker from this linked list.
|
|
149
|
-
* @param {Linker} node The node we wish to remove (and it will be returned after removal)
|
|
150
|
-
* @return {Linker}
|
|
151
|
-
*/
|
|
152
|
-
remove (node) {
|
|
153
|
-
let prevNode = null
|
|
154
|
-
let currentNode = this.first
|
|
155
|
-
while (currentNode !== node) {
|
|
156
|
-
prevNode = currentNode
|
|
157
|
-
currentNode = currentNode.next
|
|
158
|
-
}
|
|
159
|
-
if (prevNode) {
|
|
160
|
-
// Ensure the next reference of the previous node skips over the removed node
|
|
161
|
-
prevNode.next = node.next
|
|
162
|
-
}
|
|
163
|
-
if (node === this.first && node !== null) {
|
|
164
|
-
// Update list head to point to next if it was this node
|
|
165
|
-
this.innerList = node.next
|
|
166
|
-
}
|
|
167
|
-
return node
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Retrieve a Linker item from this list by numeric index, otherwise return null.
|
|
172
|
-
* @param {number} index The integer number for retrieving a node by position.
|
|
173
|
-
* @returns {Linker|null}
|
|
174
|
-
*/
|
|
175
|
-
item (index) {
|
|
176
|
-
if (index >= 0) {
|
|
177
|
-
let current = this.first
|
|
178
|
-
let currentIndex = -1
|
|
179
|
-
while (++currentIndex < index && current !== null) {
|
|
180
|
-
current = current.next
|
|
181
|
-
}
|
|
182
|
-
return currentIndex === index ? current : null
|
|
183
|
-
}
|
|
184
|
-
let current = this.first
|
|
185
|
-
let currentIndex = 0
|
|
186
|
-
const calculatedIndex = this.length + index
|
|
187
|
-
if (calculatedIndex < 0) {
|
|
188
|
-
return null
|
|
189
|
-
}
|
|
190
|
-
while (currentIndex < calculatedIndex && current !== null) {
|
|
191
|
-
current = current.next
|
|
192
|
-
++currentIndex
|
|
193
|
-
}
|
|
194
|
-
return currentIndex === calculatedIndex ? current : null
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Be able to run forEach on this LinkedList to iterate over the linkers.
|
|
199
|
-
* @param {forEachCallback} callback The function to call for-each linker
|
|
200
|
-
* @param {LinkedList} thisArg Optional, 'this' reference
|
|
201
|
-
* @returns {LinkedList}
|
|
202
|
-
*/
|
|
203
|
-
forEach (callback, thisArg = this) {
|
|
204
|
-
let index = 0
|
|
205
|
-
let current = thisArg.first
|
|
206
|
-
while (current !== null) {
|
|
207
|
-
callback(current, index, thisArg)
|
|
208
|
-
current = current.next
|
|
209
|
-
++index
|
|
210
|
-
}
|
|
211
|
-
return thisArg
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Be able to iterate over this class.
|
|
216
|
-
* @returns {Iterator}
|
|
217
|
-
*/
|
|
218
|
-
[Symbol.iterator] () {
|
|
219
|
-
return new _LinkerIterator.LinkerIterator(this.first)
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Convert an array to a LinkedList.
|
|
224
|
-
* @param {Array} values An array of values which will be converted to linkers in this linked-list
|
|
225
|
-
* @param {IsLinker} linkerClass The class to use for each linker
|
|
226
|
-
* @param {IsArrayable<Linker>} [classType=LinkedList] Provide the type of IsArrayable to use.
|
|
227
|
-
* @returns {LinkedList}
|
|
228
|
-
*/
|
|
229
|
-
exports.LinkedList = LinkedList
|
|
230
|
-
LinkedList.fromArray = (values = [], linkerClass = _Linker.Linker, classType = LinkedList) => {
|
|
231
|
-
const list = new classType(linkerClass)
|
|
232
|
-
return list.initialize(linkerClass.fromArray(values).head)
|
|
233
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.LinkedList = void 0
|
|
7
|
+
var _Linker = require('./Linker')
|
|
8
|
+
var _LinkerIterator = require('../../recipes/LinkerIterator')
|
|
9
|
+
var _Arrayable = require('../arrayable/Arrayable')
|
|
10
|
+
/**
|
|
11
|
+
* LinkedList represents a collection stored as a LinkedList with next references.
|
|
12
|
+
* @extends Arrayable
|
|
13
|
+
*/
|
|
14
|
+
class LinkedList {
|
|
15
|
+
/**
|
|
16
|
+
* Create the new LinkedList instance.
|
|
17
|
+
*/
|
|
18
|
+
constructor (linkerClass = _Linker.Linker) {
|
|
19
|
+
this.classType = LinkedList
|
|
20
|
+
this.innerList = null
|
|
21
|
+
this.initialized = false
|
|
22
|
+
this.linkerClass = linkerClass
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Initialize the inner list, should only run once.
|
|
27
|
+
* @param {Linker|Array} initialList Give the list of linkers to start in this linked-list.
|
|
28
|
+
* @return {LinkedList}
|
|
29
|
+
*/
|
|
30
|
+
initialize (initialList) {
|
|
31
|
+
return _Arrayable.Arrayable.prototype.initialize.call(this, initialList)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Retrieve a copy of the innerList used.
|
|
36
|
+
* @returns {Linker}
|
|
37
|
+
*/
|
|
38
|
+
get list () {
|
|
39
|
+
return this.innerList
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Retrieve the first Linker in the list.
|
|
44
|
+
* @returns {Linker}
|
|
45
|
+
*/
|
|
46
|
+
get first () {
|
|
47
|
+
return this.innerList
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Retrieve the last Linker in the list.
|
|
52
|
+
* @returns {Linker}
|
|
53
|
+
*/
|
|
54
|
+
get last () {
|
|
55
|
+
let tail = this.innerList
|
|
56
|
+
if (tail === null) {
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
let next = tail.next
|
|
60
|
+
while (next !== null) {
|
|
61
|
+
tail = next
|
|
62
|
+
next = tail.next
|
|
63
|
+
}
|
|
64
|
+
return tail
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Return the length of the list.
|
|
69
|
+
* @returns {number}
|
|
70
|
+
*/
|
|
71
|
+
get length () {
|
|
72
|
+
let current = this.first
|
|
73
|
+
let length = 0
|
|
74
|
+
while (current !== null) {
|
|
75
|
+
++length
|
|
76
|
+
current = current.next
|
|
77
|
+
}
|
|
78
|
+
return length
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Insert a new node (or data) after a node.
|
|
83
|
+
* @param {Linker|*} node The existing node as reference
|
|
84
|
+
* @param {Linker|*} newNode The new node to go after the existing node
|
|
85
|
+
* @returns {LinkedList}
|
|
86
|
+
*/
|
|
87
|
+
insertAfter (node, newNode) {
|
|
88
|
+
newNode = this.linkerClass.make(newNode)
|
|
89
|
+
if (node !== null) {
|
|
90
|
+
// Ensure the next reference of this node is assigned to the new node
|
|
91
|
+
newNode.next = node.next
|
|
92
|
+
// Then set this node's next reference to the new node
|
|
93
|
+
node.next = newNode
|
|
94
|
+
}
|
|
95
|
+
if (!this.length) {
|
|
96
|
+
this.innerList = newNode
|
|
97
|
+
}
|
|
98
|
+
return this
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Insert a new node (or data) before a node.
|
|
103
|
+
* @param {Linker|*} node The existing node as reference
|
|
104
|
+
* @param {Linker|*} newNode The new node to go before the existing node
|
|
105
|
+
* @returns {LinkedList}
|
|
106
|
+
*/
|
|
107
|
+
insertBefore (node, newNode) {
|
|
108
|
+
newNode = this.linkerClass.make(newNode)
|
|
109
|
+
let prevNode = null
|
|
110
|
+
let currentNode = this.first
|
|
111
|
+
while (currentNode !== node) {
|
|
112
|
+
prevNode = currentNode
|
|
113
|
+
currentNode = currentNode.next
|
|
114
|
+
}
|
|
115
|
+
// The new node will reference this node as next
|
|
116
|
+
newNode.next = node
|
|
117
|
+
if (prevNode) {
|
|
118
|
+
// Ensure the next reference of the previous node is assigned to the new node
|
|
119
|
+
prevNode.next = newNode
|
|
120
|
+
}
|
|
121
|
+
if (node === this.first || node === null) {
|
|
122
|
+
this.innerList = newNode
|
|
123
|
+
}
|
|
124
|
+
return this
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Add a node (or data) after the given (or last) node in the list.
|
|
129
|
+
* @param {Linker|*} node The new node to add to the end of the list
|
|
130
|
+
* @param {Linker} after The existing last node
|
|
131
|
+
* @returns {Linker}
|
|
132
|
+
*/
|
|
133
|
+
append (node, after = this.last) {
|
|
134
|
+
return this.insertAfter(after, node)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Add a node (or data) before the given (or first) node in the list.
|
|
139
|
+
* @param {Linker|*} node The new node to add to the start of the list
|
|
140
|
+
* @param {Linker} before The existing first node
|
|
141
|
+
* @returns {Linker}
|
|
142
|
+
*/
|
|
143
|
+
prepend (node, before = this.first) {
|
|
144
|
+
return this.insertBefore(before, node)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Remove a linker from this linked list.
|
|
149
|
+
* @param {Linker} node The node we wish to remove (and it will be returned after removal)
|
|
150
|
+
* @return {Linker}
|
|
151
|
+
*/
|
|
152
|
+
remove (node) {
|
|
153
|
+
let prevNode = null
|
|
154
|
+
let currentNode = this.first
|
|
155
|
+
while (currentNode !== node) {
|
|
156
|
+
prevNode = currentNode
|
|
157
|
+
currentNode = currentNode.next
|
|
158
|
+
}
|
|
159
|
+
if (prevNode) {
|
|
160
|
+
// Ensure the next reference of the previous node skips over the removed node
|
|
161
|
+
prevNode.next = node.next
|
|
162
|
+
}
|
|
163
|
+
if (node === this.first && node !== null) {
|
|
164
|
+
// Update list head to point to next if it was this node
|
|
165
|
+
this.innerList = node.next
|
|
166
|
+
}
|
|
167
|
+
return node
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Retrieve a Linker item from this list by numeric index, otherwise return null.
|
|
172
|
+
* @param {number} index The integer number for retrieving a node by position.
|
|
173
|
+
* @returns {Linker|null}
|
|
174
|
+
*/
|
|
175
|
+
item (index) {
|
|
176
|
+
if (index >= 0) {
|
|
177
|
+
let current = this.first
|
|
178
|
+
let currentIndex = -1
|
|
179
|
+
while (++currentIndex < index && current !== null) {
|
|
180
|
+
current = current.next
|
|
181
|
+
}
|
|
182
|
+
return currentIndex === index ? current : null
|
|
183
|
+
}
|
|
184
|
+
let current = this.first
|
|
185
|
+
let currentIndex = 0
|
|
186
|
+
const calculatedIndex = this.length + index
|
|
187
|
+
if (calculatedIndex < 0) {
|
|
188
|
+
return null
|
|
189
|
+
}
|
|
190
|
+
while (currentIndex < calculatedIndex && current !== null) {
|
|
191
|
+
current = current.next
|
|
192
|
+
++currentIndex
|
|
193
|
+
}
|
|
194
|
+
return currentIndex === calculatedIndex ? current : null
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Be able to run forEach on this LinkedList to iterate over the linkers.
|
|
199
|
+
* @param {forEachCallback} callback The function to call for-each linker
|
|
200
|
+
* @param {LinkedList} thisArg Optional, 'this' reference
|
|
201
|
+
* @returns {LinkedList}
|
|
202
|
+
*/
|
|
203
|
+
forEach (callback, thisArg = this) {
|
|
204
|
+
let index = 0
|
|
205
|
+
let current = thisArg.first
|
|
206
|
+
while (current !== null) {
|
|
207
|
+
callback(current, index, thisArg)
|
|
208
|
+
current = current.next
|
|
209
|
+
++index
|
|
210
|
+
}
|
|
211
|
+
return thisArg
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Be able to iterate over this class.
|
|
216
|
+
* @returns {Iterator}
|
|
217
|
+
*/
|
|
218
|
+
[Symbol.iterator] () {
|
|
219
|
+
return new _LinkerIterator.LinkerIterator(this.first)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Convert an array to a LinkedList.
|
|
224
|
+
* @param {Array} values An array of values which will be converted to linkers in this linked-list
|
|
225
|
+
* @param {IsLinker} linkerClass The class to use for each linker
|
|
226
|
+
* @param {IsArrayable<Linker>} [classType=LinkedList] Provide the type of IsArrayable to use.
|
|
227
|
+
* @returns {LinkedList}
|
|
228
|
+
*/
|
|
229
|
+
exports.LinkedList = LinkedList
|
|
230
|
+
LinkedList.fromArray = (values = [], linkerClass = _Linker.Linker, classType = LinkedList) => {
|
|
231
|
+
const list = new classType(linkerClass)
|
|
232
|
+
return list.initialize(linkerClass.fromArray(values).head)
|
|
233
|
+
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file linked list item.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.1.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
6
|
-
*/
|
|
7
|
-
import { IsLinker } from '../../recipes/IsLinker';
|
|
8
|
-
/**
|
|
9
|
-
* Linker represents a node in a LinkedList.
|
|
10
|
-
* @extends ArrayElement
|
|
11
|
-
*/
|
|
12
|
-
export declare class Linker implements IsLinker {
|
|
13
|
-
readonly classType: typeof Linker;
|
|
14
|
-
data: any;
|
|
15
|
-
next: Linker | null;
|
|
16
|
-
/**
|
|
17
|
-
* Create the new Linker instance, provide the data and optionally give the next Linker.
|
|
18
|
-
* @param {Object} [nodeData={}]
|
|
19
|
-
* @param {*} [nodeData.data=null] The data to be stored in this linker
|
|
20
|
-
* @param {Linker|null} [nodeData.next=null] The reference to the next linker if any
|
|
21
|
-
*/
|
|
22
|
-
constructor({ data, next }?: {
|
|
23
|
-
data?: any;
|
|
24
|
-
next?: Linker | null;
|
|
25
|
-
});
|
|
26
|
-
/**
|
|
27
|
-
* Make a new Linker from the data given if it is not already a valid Linker.
|
|
28
|
-
* @param {Linker|*} linker Return a valid Linker instance from given data, or even an already valid one.
|
|
29
|
-
* @param {IsLinker} [classType=Linker] Provide the type of IsLinker to use.
|
|
30
|
-
* @return {Linker}
|
|
31
|
-
*/
|
|
32
|
-
static make: (linker: Linker | any, classType?: any) => IsLinker | any;
|
|
33
|
-
/**
|
|
34
|
-
* Convert an array into Linker instances, return the head and tail Linkers.
|
|
35
|
-
* @param {Array} [values=[]] Provide an array of data that will be converted to a chain of linkers.
|
|
36
|
-
* @param {IsLinker} [classType=Linker] Provide the type of IsLinker to use.
|
|
37
|
-
* @returns {{head: Linker, tail: Linker}}
|
|
38
|
-
*/
|
|
39
|
-
static fromArray: (values: Array<any>, classType?: any) => {
|
|
40
|
-
head: IsLinker;
|
|
41
|
-
tail: IsLinker;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @file linked list item.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.1.0
|
|
5
|
+
* @memberOf module:collect-your-stuff
|
|
6
|
+
*/
|
|
7
|
+
import { IsLinker } from '../../recipes/IsLinker';
|
|
8
|
+
/**
|
|
9
|
+
* Linker represents a node in a LinkedList.
|
|
10
|
+
* @extends ArrayElement
|
|
11
|
+
*/
|
|
12
|
+
export declare class Linker implements IsLinker {
|
|
13
|
+
readonly classType: typeof Linker;
|
|
14
|
+
data: any;
|
|
15
|
+
next: Linker | null;
|
|
16
|
+
/**
|
|
17
|
+
* Create the new Linker instance, provide the data and optionally give the next Linker.
|
|
18
|
+
* @param {Object} [nodeData={}]
|
|
19
|
+
* @param {*} [nodeData.data=null] The data to be stored in this linker
|
|
20
|
+
* @param {Linker|null} [nodeData.next=null] The reference to the next linker if any
|
|
21
|
+
*/
|
|
22
|
+
constructor({ data, next }?: {
|
|
23
|
+
data?: any;
|
|
24
|
+
next?: Linker | null;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Make a new Linker from the data given if it is not already a valid Linker.
|
|
28
|
+
* @param {Linker|*} linker Return a valid Linker instance from given data, or even an already valid one.
|
|
29
|
+
* @param {IsLinker} [classType=Linker] Provide the type of IsLinker to use.
|
|
30
|
+
* @return {Linker}
|
|
31
|
+
*/
|
|
32
|
+
static make: (linker: Linker | any, classType?: any) => IsLinker | any;
|
|
33
|
+
/**
|
|
34
|
+
* Convert an array into Linker instances, return the head and tail Linkers.
|
|
35
|
+
* @param {Array} [values=[]] Provide an array of data that will be converted to a chain of linkers.
|
|
36
|
+
* @param {IsLinker} [classType=Linker] Provide the type of IsLinker to use.
|
|
37
|
+
* @returns {{head: Linker, tail: Linker}}
|
|
38
|
+
*/
|
|
39
|
+
static fromArray: (values: Array<any>, classType?: any) => {
|
|
40
|
+
head: IsLinker;
|
|
41
|
+
tail: IsLinker;
|
|
42
|
+
};
|
|
43
|
+
}
|