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,269 +1,274 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.DoublyLinkedList = void 0
|
|
7
|
-
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
-
require('core-js/modules/esnext.iterator.for-each.js')
|
|
9
|
-
var _DoubleLinker = require('./DoubleLinker')
|
|
10
|
-
var _DoubleLinkerIterator = require('../../recipes/DoubleLinkerIterator')
|
|
11
|
-
var _LinkedList = require('../linked-list/LinkedList')
|
|
12
|
-
/**
|
|
13
|
-
* @file doubly linked list.
|
|
14
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
15
|
-
* @version 1.1.0
|
|
16
|
-
* @memberOf module:collect-your-stuff
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* DoublyLinkedList represents a collection stored as a LinkedList with prev and next references.
|
|
21
|
-
* @extends LinkedList
|
|
22
|
-
*/
|
|
23
|
-
class DoublyLinkedList {
|
|
24
|
-
/**
|
|
25
|
-
* Create the new DoublyLinkedList instance.
|
|
26
|
-
*/
|
|
27
|
-
constructor (linkerClass = _DoubleLinker.DoubleLinker) {
|
|
28
|
-
this.classType = DoublyLinkedList
|
|
29
|
-
this.innerList = null
|
|
30
|
-
this.initialized = false
|
|
31
|
-
this.linkerClass = linkerClass
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Initialize the inner list, should only run once.
|
|
36
|
-
* @param {DoubleLinker} initialList Give the list of double-linkers to start in this doubly linked-list.
|
|
37
|
-
* @return {DoublyLinkedList}
|
|
38
|
-
*/
|
|
39
|
-
initialize (initialList) {
|
|
40
|
-
return _LinkedList.LinkedList.prototype.initialize.call(this, initialList)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Retrieve a copy of the innerList used.
|
|
45
|
-
* @returns {DoubleLinker}
|
|
46
|
-
*/
|
|
47
|
-
get list () {
|
|
48
|
-
return this.innerList
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Retrieve the first DoubleLinker in the list.
|
|
53
|
-
* @returns {DoubleLinker}
|
|
54
|
-
*/
|
|
55
|
-
get first () {
|
|
56
|
-
return this.reset()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Retrieve the last DoubleLinker in the list.
|
|
61
|
-
* @returns {DoubleLinker}
|
|
62
|
-
*/
|
|
63
|
-
get last () {
|
|
64
|
-
let tail = this.innerList
|
|
65
|
-
if (tail === null) {
|
|
66
|
-
return null
|
|
67
|
-
}
|
|
68
|
-
let next = tail.next
|
|
69
|
-
while (next !== null) {
|
|
70
|
-
tail = next
|
|
71
|
-
next = tail.next
|
|
72
|
-
}
|
|
73
|
-
return tail
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Return the length of the list.
|
|
78
|
-
* @returns {number}
|
|
79
|
-
*/
|
|
80
|
-
get length () {
|
|
81
|
-
let current = this.first
|
|
82
|
-
let length = 0
|
|
83
|
-
while (current !== null) {
|
|
84
|
-
++length
|
|
85
|
-
current = current.next
|
|
86
|
-
}
|
|
87
|
-
return length
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Insert a new node (or data) after a node.
|
|
92
|
-
* @param {DoubleLinker|*} node The existing node as reference
|
|
93
|
-
* @param {DoubleLinker|*} newNode The new node to go after the existing node
|
|
94
|
-
* @returns {DoublyLinkedList}
|
|
95
|
-
*/
|
|
96
|
-
insertAfter (node, newNode) {
|
|
97
|
-
newNode = this.linkerClass.make(newNode)
|
|
98
|
-
if (node !== null) {
|
|
99
|
-
// Ensure the next reference of this node is assigned to the new node
|
|
100
|
-
newNode.next = node.next
|
|
101
|
-
// Ensure this node is assigned as the prev reference of the new node
|
|
102
|
-
newNode.prev = node
|
|
103
|
-
// Then set this node's next reference to the new node
|
|
104
|
-
node.next = newNode
|
|
105
|
-
}
|
|
106
|
-
if (newNode.next) {
|
|
107
|
-
// Update the next reference to ensure circular reference for prev points to the new node
|
|
108
|
-
newNode.next.prev = newNode
|
|
109
|
-
}
|
|
110
|
-
if (!this.length) {
|
|
111
|
-
this.innerList = newNode
|
|
112
|
-
}
|
|
113
|
-
this.reset()
|
|
114
|
-
return this
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Insert a new node (or data) before a node.
|
|
119
|
-
* @param {DoubleLinker|*} node The existing node as reference
|
|
120
|
-
* @param {DoubleLinker|*} newNode The new node to go before the existing node
|
|
121
|
-
* @returns {DoublyLinkedList}
|
|
122
|
-
*/
|
|
123
|
-
insertBefore (node, newNode) {
|
|
124
|
-
newNode = this.linkerClass.make(newNode)
|
|
125
|
-
if (node !== null) {
|
|
126
|
-
// The new node will reference this prev node as prev
|
|
127
|
-
newNode.prev = node.prev
|
|
128
|
-
// The new node will reference this node as next
|
|
129
|
-
newNode.next = node
|
|
130
|
-
// This prev will reference the new node
|
|
131
|
-
node.prev = newNode
|
|
132
|
-
}
|
|
133
|
-
if (newNode.prev) {
|
|
134
|
-
// Update the prev reference to ensure circular reference for next points to the new node
|
|
135
|
-
newNode.prev.next = newNode
|
|
136
|
-
}
|
|
137
|
-
if (!this.length) {
|
|
138
|
-
this.innerList = newNode
|
|
139
|
-
}
|
|
140
|
-
this.reset()
|
|
141
|
-
return this
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Add a node (or data) after the given (or last) node in the list.
|
|
146
|
-
* @param {DoubleLinker|*} node The new node to add to the end of the list
|
|
147
|
-
* @param {DoubleLinker} after The existing last node
|
|
148
|
-
* @returns {DoubleLinker}
|
|
149
|
-
*/
|
|
150
|
-
append (node, after = this.last) {
|
|
151
|
-
return this.insertAfter(after, node)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Add a node (or data) before the given (or first) node in the list.
|
|
156
|
-
* @param {DoubleLinker|*} node The new node to add to the start of the list
|
|
157
|
-
* @param {DoubleLinker} before The existing first node
|
|
158
|
-
* @returns {DoubleLinker}
|
|
159
|
-
*/
|
|
160
|
-
prepend (node, before = this.first) {
|
|
161
|
-
return this.insertBefore(before, node)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Remove a linker from this linked list.
|
|
166
|
-
* @param {DoubleLinker} node The node we wish to remove (and it will be returned after removal)
|
|
167
|
-
* @return {DoubleLinker}
|
|
168
|
-
*/
|
|
169
|
-
remove (node) {
|
|
170
|
-
if (node === null) {
|
|
171
|
-
return null
|
|
172
|
-
}
|
|
173
|
-
if (node.prev) {
|
|
174
|
-
// The previous node will reference this next node
|
|
175
|
-
node.prev.next = node.next
|
|
176
|
-
}
|
|
177
|
-
if (node.next) {
|
|
178
|
-
// The next node will reference this previous node
|
|
179
|
-
node.next.prev = node.prev
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.DoublyLinkedList = void 0
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
+
require('core-js/modules/esnext.iterator.for-each.js')
|
|
9
|
+
var _DoubleLinker = require('./DoubleLinker')
|
|
10
|
+
var _DoubleLinkerIterator = require('../../recipes/DoubleLinkerIterator')
|
|
11
|
+
var _LinkedList = require('../linked-list/LinkedList')
|
|
12
|
+
/**
|
|
13
|
+
* @file doubly linked list.
|
|
14
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
15
|
+
* @version 1.1.0
|
|
16
|
+
* @memberOf module:collect-your-stuff
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* DoublyLinkedList represents a collection stored as a LinkedList with prev and next references.
|
|
21
|
+
* @extends LinkedList
|
|
22
|
+
*/
|
|
23
|
+
class DoublyLinkedList {
|
|
24
|
+
/**
|
|
25
|
+
* Create the new DoublyLinkedList instance.
|
|
26
|
+
*/
|
|
27
|
+
constructor (linkerClass = _DoubleLinker.DoubleLinker) {
|
|
28
|
+
this.classType = DoublyLinkedList
|
|
29
|
+
this.innerList = null
|
|
30
|
+
this.initialized = false
|
|
31
|
+
this.linkerClass = linkerClass
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Initialize the inner list, should only run once.
|
|
36
|
+
* @param {DoubleLinker} initialList Give the list of double-linkers to start in this doubly linked-list.
|
|
37
|
+
* @return {DoublyLinkedList}
|
|
38
|
+
*/
|
|
39
|
+
initialize (initialList) {
|
|
40
|
+
return _LinkedList.LinkedList.prototype.initialize.call(this, initialList)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Retrieve a copy of the innerList used.
|
|
45
|
+
* @returns {DoubleLinker}
|
|
46
|
+
*/
|
|
47
|
+
get list () {
|
|
48
|
+
return this.innerList
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Retrieve the first DoubleLinker in the list.
|
|
53
|
+
* @returns {DoubleLinker}
|
|
54
|
+
*/
|
|
55
|
+
get first () {
|
|
56
|
+
return this.reset()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Retrieve the last DoubleLinker in the list.
|
|
61
|
+
* @returns {DoubleLinker}
|
|
62
|
+
*/
|
|
63
|
+
get last () {
|
|
64
|
+
let tail = this.innerList
|
|
65
|
+
if (tail === null) {
|
|
66
|
+
return null
|
|
67
|
+
}
|
|
68
|
+
let next = tail.next
|
|
69
|
+
while (next !== null) {
|
|
70
|
+
tail = next
|
|
71
|
+
next = tail.next
|
|
72
|
+
}
|
|
73
|
+
return tail
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Return the length of the list.
|
|
78
|
+
* @returns {number}
|
|
79
|
+
*/
|
|
80
|
+
get length () {
|
|
81
|
+
let current = this.first
|
|
82
|
+
let length = 0
|
|
83
|
+
while (current !== null) {
|
|
84
|
+
++length
|
|
85
|
+
current = current.next
|
|
86
|
+
}
|
|
87
|
+
return length
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Insert a new node (or data) after a node.
|
|
92
|
+
* @param {DoubleLinker|*} node The existing node as reference
|
|
93
|
+
* @param {DoubleLinker|*} newNode The new node to go after the existing node
|
|
94
|
+
* @returns {DoublyLinkedList}
|
|
95
|
+
*/
|
|
96
|
+
insertAfter (node, newNode) {
|
|
97
|
+
newNode = this.linkerClass.make(newNode)
|
|
98
|
+
if (node !== null) {
|
|
99
|
+
// Ensure the next reference of this node is assigned to the new node
|
|
100
|
+
newNode.next = node.next
|
|
101
|
+
// Ensure this node is assigned as the prev reference of the new node
|
|
102
|
+
newNode.prev = node
|
|
103
|
+
// Then set this node's next reference to the new node
|
|
104
|
+
node.next = newNode
|
|
105
|
+
}
|
|
106
|
+
if (newNode.next) {
|
|
107
|
+
// Update the next reference to ensure circular reference for prev points to the new node
|
|
108
|
+
newNode.next.prev = newNode
|
|
109
|
+
}
|
|
110
|
+
if (!this.length) {
|
|
111
|
+
this.innerList = newNode
|
|
112
|
+
}
|
|
113
|
+
this.reset()
|
|
114
|
+
return this
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Insert a new node (or data) before a node.
|
|
119
|
+
* @param {DoubleLinker|*} node The existing node as reference
|
|
120
|
+
* @param {DoubleLinker|*} newNode The new node to go before the existing node
|
|
121
|
+
* @returns {DoublyLinkedList}
|
|
122
|
+
*/
|
|
123
|
+
insertBefore (node, newNode) {
|
|
124
|
+
newNode = this.linkerClass.make(newNode)
|
|
125
|
+
if (node !== null) {
|
|
126
|
+
// The new node will reference this prev node as prev
|
|
127
|
+
newNode.prev = node.prev
|
|
128
|
+
// The new node will reference this node as next
|
|
129
|
+
newNode.next = node
|
|
130
|
+
// This prev will reference the new node
|
|
131
|
+
node.prev = newNode
|
|
132
|
+
}
|
|
133
|
+
if (newNode.prev) {
|
|
134
|
+
// Update the prev reference to ensure circular reference for next points to the new node
|
|
135
|
+
newNode.prev.next = newNode
|
|
136
|
+
}
|
|
137
|
+
if (!this.length) {
|
|
138
|
+
this.innerList = newNode
|
|
139
|
+
}
|
|
140
|
+
this.reset()
|
|
141
|
+
return this
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Add a node (or data) after the given (or last) node in the list.
|
|
146
|
+
* @param {DoubleLinker|*} node The new node to add to the end of the list
|
|
147
|
+
* @param {DoubleLinker} after The existing last node
|
|
148
|
+
* @returns {DoubleLinker}
|
|
149
|
+
*/
|
|
150
|
+
append (node, after = this.last) {
|
|
151
|
+
return this.insertAfter(after, node)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Add a node (or data) before the given (or first) node in the list.
|
|
156
|
+
* @param {DoubleLinker|*} node The new node to add to the start of the list
|
|
157
|
+
* @param {DoubleLinker} before The existing first node
|
|
158
|
+
* @returns {DoubleLinker}
|
|
159
|
+
*/
|
|
160
|
+
prepend (node, before = this.first) {
|
|
161
|
+
return this.insertBefore(before, node)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Remove a linker from this linked list.
|
|
166
|
+
* @param {DoubleLinker} node The node we wish to remove (and it will be returned after removal)
|
|
167
|
+
* @return {DoubleLinker}
|
|
168
|
+
*/
|
|
169
|
+
remove (node) {
|
|
170
|
+
if (node === null) {
|
|
171
|
+
return null
|
|
172
|
+
}
|
|
173
|
+
if (node.prev) {
|
|
174
|
+
// The previous node will reference this next node
|
|
175
|
+
node.prev.next = node.next
|
|
176
|
+
}
|
|
177
|
+
if (node.next) {
|
|
178
|
+
// The next node will reference this previous node
|
|
179
|
+
node.next.prev = node.prev
|
|
180
|
+
}
|
|
181
|
+
// The list finds its head by walking from innerList, so it must not keep pointing at the node being removed. For the
|
|
182
|
+
// last remaining node there is nothing to walk to, which would otherwise leave the removed node in the list.
|
|
183
|
+
if (this.innerList === node) {
|
|
184
|
+
this.innerList = node.next || node.prev || null
|
|
185
|
+
}
|
|
186
|
+
// Update head reference
|
|
187
|
+
this.reset()
|
|
188
|
+
return node
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Refresh all references and return head reference.
|
|
193
|
+
* @return {DoubleLinker}
|
|
194
|
+
*/
|
|
195
|
+
reset () {
|
|
196
|
+
// Start at the pointer for the list
|
|
197
|
+
let pointer = this.innerList
|
|
198
|
+
if (pointer === null) {
|
|
199
|
+
return null
|
|
200
|
+
}
|
|
201
|
+
let next = pointer.next
|
|
202
|
+
// Follow references till the end
|
|
203
|
+
while (next !== null) {
|
|
204
|
+
pointer = next
|
|
205
|
+
next = pointer.next
|
|
206
|
+
}
|
|
207
|
+
let prev = pointer.prev
|
|
208
|
+
// From final reference, follow references back to the beginning
|
|
209
|
+
while (prev !== null) {
|
|
210
|
+
pointer = prev
|
|
211
|
+
prev = pointer.prev
|
|
212
|
+
}
|
|
213
|
+
// All the live references should have been found, and we are pointing to the true head
|
|
214
|
+
this.innerList = pointer
|
|
215
|
+
return pointer
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Retrieve a DoubleLinker item from this list by numeric index, otherwise return null.
|
|
220
|
+
* @param {number} index The integer number for retrieving a node by position.
|
|
221
|
+
* @returns {DoubleLinker|null}
|
|
222
|
+
*/
|
|
223
|
+
item (index) {
|
|
224
|
+
if (index >= 0) {
|
|
225
|
+
// For a positive index, start from the beginning of the list until the current item counter equals our index
|
|
226
|
+
let current = this.first
|
|
227
|
+
let currentIndex = -1
|
|
228
|
+
while (++currentIndex < index && current !== null) {
|
|
229
|
+
current = current.next
|
|
230
|
+
}
|
|
231
|
+
return currentIndex === index ? current : null
|
|
232
|
+
}
|
|
233
|
+
// For a negative index, get the delta of index and length, then go backwards until we reach that delta
|
|
234
|
+
let current = this.last
|
|
235
|
+
let currentIndex = this.length
|
|
236
|
+
const calculatedIndex = this.length + index
|
|
237
|
+
if (calculatedIndex < 0) {
|
|
238
|
+
return null
|
|
239
|
+
}
|
|
240
|
+
while (--currentIndex > calculatedIndex && current !== null) {
|
|
241
|
+
current = current.prev
|
|
242
|
+
}
|
|
243
|
+
return currentIndex === calculatedIndex ? current : null
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Be able to run forEach on this DoublyLinkedList to iterate over the DoubleLinker Items.
|
|
248
|
+
* @param {forEachCallback} callback The function to call for-each double linker
|
|
249
|
+
* @param {DoublyLinkedList} thisArg Optional, 'this' reference
|
|
250
|
+
*/
|
|
251
|
+
forEach (callback, thisArg = this) {
|
|
252
|
+
return _LinkedList.LinkedList.prototype.forEach.call(this, callback, thisArg)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Be able to iterate over this class.
|
|
257
|
+
* @returns {Iterator}
|
|
258
|
+
*/
|
|
259
|
+
[Symbol.iterator] () {
|
|
260
|
+
const current = this.first
|
|
261
|
+
return new _DoubleLinkerIterator.DoubleLinkerIterator(current)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Convert an array into a DoublyLinkedList instance, return the new instance.
|
|
266
|
+
* @param {Array} [values=[]] An array of values which will be converted to linkers in this doubly-linked-list
|
|
267
|
+
* @param {IsDoubleLinker} [linkerClass=DoubleLinker] The class to use for each linker
|
|
268
|
+
* @param {IsArrayable<IsDoubleLinker>} [classType=LinkedList] Provide the type of IsArrayable to use.
|
|
269
|
+
* @returns {DoublyLinkedList}
|
|
270
|
+
*/
|
|
271
|
+
exports.DoublyLinkedList = DoublyLinkedList
|
|
272
|
+
DoublyLinkedList.fromArray = (values = [], linkerClass = _DoubleLinker.DoubleLinker, classType = DoublyLinkedList) => {
|
|
273
|
+
return _LinkedList.LinkedList.fromArray(values, linkerClass, classType)
|
|
274
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DoublyLinkedList=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.for-each.js");var _DoubleLinker=require("./DoubleLinker"),_DoubleLinkerIterator=require("../../recipes/DoubleLinkerIterator"),_LinkedList=require("../linked-list/LinkedList");class DoublyLinkedList{constructor(e=_DoubleLinker.DoubleLinker){this.classType=DoublyLinkedList,this.innerList=null,this.initialized=!1,this.linkerClass=e}initialize(e){return _LinkedList.LinkedList.prototype.initialize.call(this,e)}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}insertAfter(e,t){return t=this.linkerClass.make(t),null!==e&&(t.next=e.next,t.prev=e,e.next=t),t.next&&(t.next.prev=t),this.length||(this.innerList=t),this.reset(),this}insertBefore(e,t){return t=this.linkerClass.make(t),null!==e&&(t.prev=e.prev,t.next=e,e.prev=t),t.prev&&(t.prev.next=t),this.length||(this.innerList=t),this.reset(),this}append(e,t=this.last){return this.insertAfter(t,e)}prepend(e,t=this.first){return this.insertBefore(t,e)}remove(e){return null===e?null:(e.prev&&(e.prev.next=e.next),e.next&&(e.next.prev=e.prev),this.reset(),e)}reset(){let e=this.innerList;if(null===e)return null;let t=e.next;for(;null!==t;)e=t,t=e.next;let r=e.prev;for(;null!==r;)e=r,r=e.prev;return this.innerList=e,e}item(e){if(e>=0){let t=this.first,r=-1;for(;++r<e&&null!==t;)t=t.next;return r===e?t:null}let t=this.last,r=this.length;const i=this.length+e;if(i<0)return null;for(;--r>i&&null!==t;)t=t.prev;return r===i?t:null}forEach(e,t=this){return _LinkedList.LinkedList.prototype.forEach.call(this,e,t)}[Symbol.iterator](){let e=this.first;return new _DoubleLinkerIterator.DoubleLinkerIterator(e)}}exports.DoublyLinkedList=DoublyLinkedList,DoublyLinkedList.fromArray=(e=[],t=_DoubleLinker.DoubleLinker,r=DoublyLinkedList)=>_LinkedList.LinkedList.fromArray(e,t,r);
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DoublyLinkedList=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.for-each.js");var _DoubleLinker=require("./DoubleLinker"),_DoubleLinkerIterator=require("../../recipes/DoubleLinkerIterator"),_LinkedList=require("../linked-list/LinkedList");class DoublyLinkedList{constructor(e=_DoubleLinker.DoubleLinker){this.classType=DoublyLinkedList,this.innerList=null,this.initialized=!1,this.linkerClass=e}initialize(e){return _LinkedList.LinkedList.prototype.initialize.call(this,e)}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}insertAfter(e,t){return t=this.linkerClass.make(t),null!==e&&(t.next=e.next,t.prev=e,e.next=t),t.next&&(t.next.prev=t),this.length||(this.innerList=t),this.reset(),this}insertBefore(e,t){return t=this.linkerClass.make(t),null!==e&&(t.prev=e.prev,t.next=e,e.prev=t),t.prev&&(t.prev.next=t),this.length||(this.innerList=t),this.reset(),this}append(e,t=this.last){return this.insertAfter(t,e)}prepend(e,t=this.first){return this.insertBefore(t,e)}remove(e){return null===e?null:(e.prev&&(e.prev.next=e.next),e.next&&(e.next.prev=e.prev),this.innerList===e&&(this.innerList=e.next||e.prev||null),this.reset(),e)}reset(){let e=this.innerList;if(null===e)return null;let t=e.next;for(;null!==t;)e=t,t=e.next;let r=e.prev;for(;null!==r;)e=r,r=e.prev;return this.innerList=e,e}item(e){if(e>=0){let t=this.first,r=-1;for(;++r<e&&null!==t;)t=t.next;return r===e?t:null}let t=this.last,r=this.length;const i=this.length+e;if(i<0)return null;for(;--r>i&&null!==t;)t=t.prev;return r===i?t:null}forEach(e,t=this){return _LinkedList.LinkedList.prototype.forEach.call(this,e,t)}[Symbol.iterator](){let e=this.first;return new _DoubleLinkerIterator.DoubleLinkerIterator(e)}}exports.DoublyLinkedList=DoublyLinkedList,DoublyLinkedList.fromArray=(e=[],t=_DoubleLinker.DoubleLinker,r=DoublyLinkedList)=>_LinkedList.LinkedList.fromArray(e,t,r);
|