collect-your-stuff 1.2.6 → 1.2.7
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 +39 -39
- package/browser/collect-your-stuff.js +123 -221
- package/browser/collect-your-stuff.min.js +1 -1
- package/dist/collections/arrayable/ArrayElement.js +18 -24
- package/dist/collections/arrayable/ArrayElement.min.js +1 -1
- package/dist/collections/arrayable/Arrayable.js +5 -13
- package/dist/collections/arrayable/Arrayable.min.js +1 -1
- package/dist/collections/doubly-linked-list/DoubleLinker.js +23 -31
- package/dist/collections/doubly-linked-list/DoubleLinker.min.js +1 -1
- package/dist/collections/doubly-linked-list/DoublyLinkedList.js +5 -13
- package/dist/collections/doubly-linked-list/DoublyLinkedList.min.js +1 -1
- package/dist/collections/linked-list/LinkedList.js +5 -13
- package/dist/collections/linked-list/LinkedList.min.js +1 -1
- package/dist/collections/linked-list/Linker.js +21 -27
- package/dist/collections/linked-list/Linker.min.js +1 -1
- package/dist/collections/linked-tree-list/LinkedTreeList.js +6 -15
- package/dist/collections/linked-tree-list/LinkedTreeList.min.js +1 -1
- package/dist/collections/linked-tree-list/TreeLinker.js +11 -24
- package/dist/collections/linked-tree-list/TreeLinker.min.js +1 -1
- package/dist/collections/queue/Queue.js +2 -8
- package/dist/collections/queue/Queue.min.js +1 -1
- package/dist/collections/queue/Queueable.js +12 -22
- package/dist/collections/queue/Queueable.min.js +1 -1
- package/dist/collections/stack/Stack.js +2 -8
- package/dist/collections/stack/Stack.min.js +1 -1
- package/dist/collections/stack/Stackable.js +7 -15
- package/dist/collections/stack/Stackable.min.js +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/recipes/ArrayIterator.js +1 -2
- package/dist/recipes/ArrayIterator.min.js +1 -1
- package/dist/recipes/Runnable.js +1 -2
- package/dist/recipes/Runnable.min.js +1 -1
- package/dist/services/services.d.ts +1 -1
- package/package.json +2 -2
|
@@ -14,8 +14,7 @@ class ArrayElement {
|
|
|
14
14
|
* Create the new Element instance, provide the data and optionally configure the type of Element.
|
|
15
15
|
* @param {*} [data=null] The data to be stored in this element.
|
|
16
16
|
*/
|
|
17
|
-
constructor () {
|
|
18
|
-
const data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null
|
|
17
|
+
constructor (data = null) {
|
|
19
18
|
this.classType = ArrayElement
|
|
20
19
|
this.data = null
|
|
21
20
|
this.data = data
|
|
@@ -28,8 +27,7 @@ class ArrayElement {
|
|
|
28
27
|
* @return {ArrayElement}
|
|
29
28
|
*/
|
|
30
29
|
exports.ArrayElement = ArrayElement
|
|
31
|
-
ArrayElement.make =
|
|
32
|
-
const classType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ArrayElement
|
|
30
|
+
ArrayElement.make = (element, classType = ArrayElement) => {
|
|
33
31
|
if (typeof element !== 'object') {
|
|
34
32
|
// It is not an object, so instantiate the Element with element as the data
|
|
35
33
|
return new classType(element)
|
|
@@ -47,24 +45,20 @@ ArrayElement.make = function (element) {
|
|
|
47
45
|
* @param {IsElement} [classType=ArrayElement] Provide the type of IsElement to use.
|
|
48
46
|
* @returns {{head: ArrayElement[], tail: ArrayElement}}
|
|
49
47
|
*/
|
|
50
|
-
ArrayElement.fromArray =
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
head: [newElement],
|
|
59
|
-
tail: newElement
|
|
60
|
-
}
|
|
48
|
+
ArrayElement.fromArray = (values = [], classType = ArrayElement) => values.reduce((references, element) => {
|
|
49
|
+
const newElement = classType.make(element, classType)
|
|
50
|
+
if (!references.head.length) {
|
|
51
|
+
// Initialize the head and tail with the new node
|
|
52
|
+
return {
|
|
53
|
+
head: [newElement],
|
|
54
|
+
tail: newElement
|
|
61
55
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
56
|
+
}
|
|
57
|
+
// Only update the tail once head has been set, tail is always the most recent node
|
|
58
|
+
references.head.push(newElement)
|
|
59
|
+
references.tail = newElement
|
|
60
|
+
return references
|
|
61
|
+
}, {
|
|
62
|
+
head: [],
|
|
63
|
+
tail: null
|
|
64
|
+
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ArrayElement=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");class ArrayElement{constructor(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ArrayElement=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");class ArrayElement{constructor(e=null){this.classType=ArrayElement,this.data=null,this.data=e}}exports.ArrayElement=ArrayElement,ArrayElement.make=(e,r=ArrayElement)=>"object"!=typeof e?new r(e):e.classType?e:new r(e),ArrayElement.fromArray=(e=[],r=ArrayElement)=>e.reduce(((e,t)=>{const a=r.make(t,r);return e.head.length?(e.head.push(a),e.tail=a,e):{head:[a],tail:a}}),{head:[],tail:null});
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
4
4
|
value: true
|
|
5
5
|
})
|
|
6
6
|
exports.Arrayable = void 0
|
|
7
|
-
require('core-js/modules/web.dom-collections.iterator.js')
|
|
8
7
|
var _ArrayElement = require('./ArrayElement')
|
|
9
8
|
var _ArrayIterator = require('../../recipes/ArrayIterator')
|
|
10
9
|
/**
|
|
@@ -21,8 +20,7 @@ class Arrayable {
|
|
|
21
20
|
/**
|
|
22
21
|
* Create the new Arrayable instance, configure the Arrayable class.
|
|
23
22
|
*/
|
|
24
|
-
constructor () {
|
|
25
|
-
const elementClass = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _ArrayElement.ArrayElement
|
|
23
|
+
constructor (elementClass = _ArrayElement.ArrayElement) {
|
|
26
24
|
this.classType = Arrayable
|
|
27
25
|
this.innerList = []
|
|
28
26
|
this.initialized = false
|
|
@@ -106,8 +104,7 @@ class Arrayable {
|
|
|
106
104
|
* @param {ArrayElement} after The existing last node
|
|
107
105
|
* @returns {Arrayable}
|
|
108
106
|
*/
|
|
109
|
-
append (node) {
|
|
110
|
-
const after = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.last
|
|
107
|
+
append (node, after = this.last) {
|
|
111
108
|
return this.insertAfter(after, node)
|
|
112
109
|
}
|
|
113
110
|
|
|
@@ -117,8 +114,7 @@ class Arrayable {
|
|
|
117
114
|
* @param {ArrayElement} before The existing first node
|
|
118
115
|
* @returns {Arrayable}
|
|
119
116
|
*/
|
|
120
|
-
prepend (node) {
|
|
121
|
-
const before = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.first
|
|
117
|
+
prepend (node, before = this.first) {
|
|
122
118
|
return this.insertBefore(before, node)
|
|
123
119
|
}
|
|
124
120
|
|
|
@@ -162,8 +158,7 @@ class Arrayable {
|
|
|
162
158
|
* @param {Arrayable} thisArg Optional, 'this' reference
|
|
163
159
|
* @returns {Arrayable}
|
|
164
160
|
*/
|
|
165
|
-
forEach (callback) {
|
|
166
|
-
const thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this
|
|
161
|
+
forEach (callback, thisArg = this) {
|
|
167
162
|
for (let i = 0; i < thisArg.length; ++i) {
|
|
168
163
|
callback(thisArg.item(i), i, thisArg)
|
|
169
164
|
}
|
|
@@ -187,10 +182,7 @@ class Arrayable {
|
|
|
187
182
|
* @returns {Arrayable}
|
|
188
183
|
*/
|
|
189
184
|
exports.Arrayable = Arrayable
|
|
190
|
-
Arrayable.fromArray =
|
|
191
|
-
const values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []
|
|
192
|
-
const elementClass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _ArrayElement.ArrayElement
|
|
193
|
-
const classType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Arrayable
|
|
185
|
+
Arrayable.fromArray = (values = [], elementClass = _ArrayElement.ArrayElement, classType = Arrayable) => {
|
|
194
186
|
const list = new classType(elementClass)
|
|
195
187
|
return list.initialize(elementClass.fromArray(values).head)
|
|
196
188
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Arrayable=void 0
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Arrayable=void 0;var _ArrayElement=require("./ArrayElement"),_ArrayIterator=require("../../recipes/ArrayIterator");class Arrayable{constructor(t=_ArrayElement.ArrayElement){this.classType=Arrayable,this.innerList=[],this.initialized=!1,this.elementClass=t}initialize(t){return this.initialized?(console.warn("Attempt to initialize non-empty list."),this):(this.initialized=!0,this.innerList=t,this)}get list(){return this.innerList}get first(){return this.innerList[0]}get last(){return this.innerList[this.length-1]}get length(){return this.innerList.length}insertAfter(t,e){const r=this.innerList.indexOf(t);return this.innerList.splice(r+1,0,this.elementClass.make(e)),this}insertBefore(t,e){const r=this.innerList.indexOf(t);return this.innerList.splice(r,0,this.elementClass.make(e)),this}append(t,e=this.last){return this.insertAfter(e,t)}prepend(t,e=this.first){return this.insertBefore(e,t)}remove(t){const e=this.innerList.indexOf(t);return this.innerList.splice(e,1),t}item(t){if(t>=this.length)return null;if(t>=0)return this.innerList[t];const e=this.length+t;return e<0?null:this.innerList[e]}forEach(t,e=this){for(let r=0;r<e.length;++r)t(e.item(r),r,e);return e}[Symbol.iterator](){return new _ArrayIterator.ArrayIterator(this.innerList,0)}}exports.Arrayable=Arrayable,Arrayable.fromArray=(t=[],e=_ArrayElement.ArrayElement,r=Arrayable)=>new r(e).initialize(e.fromArray(t).head);
|
|
@@ -19,14 +19,11 @@ class DoubleLinker {
|
|
|
19
19
|
* @param {DoubleLinker|null} [nodeData.next=null] The reference to the next linker if any
|
|
20
20
|
* @param {DoubleLinker|null} [nodeData.prev=null] The reference to the previous linker if any
|
|
21
21
|
*/
|
|
22
|
-
constructor (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const next = _ref$next === void 0 ? null : _ref$next
|
|
28
|
-
const _ref$prev = _ref.prev
|
|
29
|
-
const prev = _ref$prev === void 0 ? null : _ref$prev
|
|
22
|
+
constructor ({
|
|
23
|
+
data = null,
|
|
24
|
+
next = null,
|
|
25
|
+
prev = null
|
|
26
|
+
} = {}) {
|
|
30
27
|
this.classType = DoubleLinker
|
|
31
28
|
this.data = null
|
|
32
29
|
this.next = null
|
|
@@ -43,8 +40,7 @@ class DoubleLinker {
|
|
|
43
40
|
* @return {DoubleLinker}
|
|
44
41
|
*/
|
|
45
42
|
exports.DoubleLinker = DoubleLinker
|
|
46
|
-
DoubleLinker.make =
|
|
47
|
-
const classType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DoubleLinker
|
|
43
|
+
DoubleLinker.make = (linker, classType = DoubleLinker) => {
|
|
48
44
|
return _Linker.Linker.make(linker, classType)
|
|
49
45
|
}
|
|
50
46
|
/**
|
|
@@ -53,25 +49,21 @@ DoubleLinker.make = function (linker) {
|
|
|
53
49
|
* @param {IsDoubleLinker} [classType=DoubleLinker] Provide the type of IsDoubleLinker to use.
|
|
54
50
|
* @returns {{head: DoubleLinker, tail: DoubleLinker}}
|
|
55
51
|
*/
|
|
56
|
-
DoubleLinker.fromArray =
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
head: newLinker,
|
|
65
|
-
tail: newLinker
|
|
66
|
-
}
|
|
52
|
+
DoubleLinker.fromArray = (values = [], classType = DoubleLinker) => values.reduce((references, linker) => {
|
|
53
|
+
const newLinker = classType.make(linker, classType)
|
|
54
|
+
if (references.head === null) {
|
|
55
|
+
// Initialize the head and tail with the new node
|
|
56
|
+
return {
|
|
57
|
+
head: newLinker,
|
|
58
|
+
tail: newLinker
|
|
67
59
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
60
|
+
}
|
|
61
|
+
newLinker.prev = references.tail
|
|
62
|
+
// Only update the tail once head has been set, tail is always the most recent node
|
|
63
|
+
references.tail.next = newLinker
|
|
64
|
+
references.tail = newLinker
|
|
65
|
+
return references
|
|
66
|
+
}, {
|
|
67
|
+
head: null,
|
|
68
|
+
tail: null
|
|
69
|
+
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DoubleLinker=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var _Linker=require("../linked-list/Linker");class DoubleLinker{constructor(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DoubleLinker=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var _Linker=require("../linked-list/Linker");class DoubleLinker{constructor({data:e=null,next:r=null,prev:l=null}={}){this.classType=DoubleLinker,this.data=null,this.next=null,this.prev=null,this.data=e,this.next=r,this.prev=l}}exports.DoubleLinker=DoubleLinker,DoubleLinker.make=(e,r=DoubleLinker)=>_Linker.Linker.make(e,r),DoubleLinker.fromArray=(e=[],r=DoubleLinker)=>e.reduce(((e,l)=>{const t=r.make(l,r);return null===e.head?{head:t,tail:t}:(t.prev=e.tail,e.tail.next=t,e.tail=t,e)}),{head:null,tail:null});
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
6
6
|
exports.DoublyLinkedList = void 0
|
|
7
7
|
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
8
|
require('core-js/modules/esnext.iterator.for-each.js')
|
|
9
|
-
require('core-js/modules/web.dom-collections.iterator.js')
|
|
10
9
|
var _DoubleLinker = require('./DoubleLinker')
|
|
11
10
|
var _DoubleLinkerIterator = require('../../recipes/DoubleLinkerIterator')
|
|
12
11
|
var _LinkedList = require('../linked-list/LinkedList')
|
|
@@ -25,8 +24,7 @@ class DoublyLinkedList {
|
|
|
25
24
|
/**
|
|
26
25
|
* Create the new DoublyLinkedList instance.
|
|
27
26
|
*/
|
|
28
|
-
constructor () {
|
|
29
|
-
const linkerClass = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _DoubleLinker.DoubleLinker
|
|
27
|
+
constructor (linkerClass = _DoubleLinker.DoubleLinker) {
|
|
30
28
|
this.classType = DoublyLinkedList
|
|
31
29
|
this.innerList = null
|
|
32
30
|
this.initialized = false
|
|
@@ -149,8 +147,7 @@ class DoublyLinkedList {
|
|
|
149
147
|
* @param {DoubleLinker} after The existing last node
|
|
150
148
|
* @returns {DoubleLinker}
|
|
151
149
|
*/
|
|
152
|
-
append (node) {
|
|
153
|
-
const after = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.last
|
|
150
|
+
append (node, after = this.last) {
|
|
154
151
|
return this.insertAfter(after, node)
|
|
155
152
|
}
|
|
156
153
|
|
|
@@ -160,8 +157,7 @@ class DoublyLinkedList {
|
|
|
160
157
|
* @param {DoubleLinker} before The existing first node
|
|
161
158
|
* @returns {DoubleLinker}
|
|
162
159
|
*/
|
|
163
|
-
prepend (node) {
|
|
164
|
-
const before = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.first
|
|
160
|
+
prepend (node, before = this.first) {
|
|
165
161
|
return this.insertBefore(before, node)
|
|
166
162
|
}
|
|
167
163
|
|
|
@@ -247,8 +243,7 @@ class DoublyLinkedList {
|
|
|
247
243
|
* @param {forEachCallback} callback The function to call for-each double linker
|
|
248
244
|
* @param {DoublyLinkedList} thisArg Optional, 'this' reference
|
|
249
245
|
*/
|
|
250
|
-
forEach (callback) {
|
|
251
|
-
const thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this
|
|
246
|
+
forEach (callback, thisArg = this) {
|
|
252
247
|
return _LinkedList.LinkedList.prototype.forEach.call(this, callback, thisArg)
|
|
253
248
|
}
|
|
254
249
|
|
|
@@ -269,9 +264,6 @@ class DoublyLinkedList {
|
|
|
269
264
|
* @returns {DoublyLinkedList}
|
|
270
265
|
*/
|
|
271
266
|
exports.DoublyLinkedList = DoublyLinkedList
|
|
272
|
-
DoublyLinkedList.fromArray =
|
|
273
|
-
const values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []
|
|
274
|
-
const linkerClass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _DoubleLinker.DoubleLinker
|
|
275
|
-
const classType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DoublyLinkedList
|
|
267
|
+
DoublyLinkedList.fromArray = (values = [], linkerClass = _DoubleLinker.DoubleLinker, classType = DoublyLinkedList) => {
|
|
276
268
|
return _LinkedList.LinkedList.fromArray(values, linkerClass, classType)
|
|
277
269
|
}
|
|
@@ -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")
|
|
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);
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
4
4
|
value: true
|
|
5
5
|
})
|
|
6
6
|
exports.LinkedList = void 0
|
|
7
|
-
require('core-js/modules/web.dom-collections.iterator.js')
|
|
8
7
|
var _Linker = require('./Linker')
|
|
9
8
|
var _LinkerIterator = require('../../recipes/LinkerIterator')
|
|
10
9
|
var _Arrayable = require('../arrayable/Arrayable')
|
|
@@ -16,8 +15,7 @@ class LinkedList {
|
|
|
16
15
|
/**
|
|
17
16
|
* Create the new LinkedList instance.
|
|
18
17
|
*/
|
|
19
|
-
constructor () {
|
|
20
|
-
const linkerClass = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _Linker.Linker
|
|
18
|
+
constructor (linkerClass = _Linker.Linker) {
|
|
21
19
|
this.classType = LinkedList
|
|
22
20
|
this.innerList = null
|
|
23
21
|
this.initialized = false
|
|
@@ -132,8 +130,7 @@ class LinkedList {
|
|
|
132
130
|
* @param {Linker} after The existing last node
|
|
133
131
|
* @returns {Linker}
|
|
134
132
|
*/
|
|
135
|
-
append (node) {
|
|
136
|
-
const after = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.last
|
|
133
|
+
append (node, after = this.last) {
|
|
137
134
|
return this.insertAfter(after, node)
|
|
138
135
|
}
|
|
139
136
|
|
|
@@ -143,8 +140,7 @@ class LinkedList {
|
|
|
143
140
|
* @param {Linker} before The existing first node
|
|
144
141
|
* @returns {Linker}
|
|
145
142
|
*/
|
|
146
|
-
prepend (node) {
|
|
147
|
-
const before = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.first
|
|
143
|
+
prepend (node, before = this.first) {
|
|
148
144
|
return this.insertBefore(before, node)
|
|
149
145
|
}
|
|
150
146
|
|
|
@@ -204,8 +200,7 @@ class LinkedList {
|
|
|
204
200
|
* @param {LinkedList} thisArg Optional, 'this' reference
|
|
205
201
|
* @returns {LinkedList}
|
|
206
202
|
*/
|
|
207
|
-
forEach (callback) {
|
|
208
|
-
const thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this
|
|
203
|
+
forEach (callback, thisArg = this) {
|
|
209
204
|
let index = 0
|
|
210
205
|
let current = thisArg.first
|
|
211
206
|
while (current !== null) {
|
|
@@ -232,10 +227,7 @@ class LinkedList {
|
|
|
232
227
|
* @returns {LinkedList}
|
|
233
228
|
*/
|
|
234
229
|
exports.LinkedList = LinkedList
|
|
235
|
-
LinkedList.fromArray =
|
|
236
|
-
const values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []
|
|
237
|
-
const linkerClass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _Linker.Linker
|
|
238
|
-
const classType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : LinkedList
|
|
230
|
+
LinkedList.fromArray = (values = [], linkerClass = _Linker.Linker, classType = LinkedList) => {
|
|
239
231
|
const list = new classType(linkerClass)
|
|
240
232
|
return list.initialize(linkerClass.fromArray(values).head)
|
|
241
233
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LinkedList=void 0
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LinkedList=void 0;var _Linker=require("./Linker"),_LinkerIterator=require("../../recipes/LinkerIterator"),_Arrayable=require("../arrayable/Arrayable");class LinkedList{constructor(t=_Linker.Linker){this.classType=LinkedList,this.innerList=null,this.initialized=!1,this.linkerClass=t}initialize(t){return _Arrayable.Arrayable.prototype.initialize.call(this,t)}get list(){return this.innerList}get first(){return this.innerList}get last(){let t=this.innerList;if(null===t)return null;let e=t.next;for(;null!==e;)t=e,e=t.next;return t}get length(){let t=this.first,e=0;for(;null!==t;)++e,t=t.next;return e}insertAfter(t,e){return e=this.linkerClass.make(e),null!==t&&(e.next=t.next,t.next=e),this.length||(this.innerList=e),this}insertBefore(t,e){e=this.linkerClass.make(e);let r=null,i=this.first;for(;i!==t;)r=i,i=i.next;return e.next=t,r&&(r.next=e),t!==this.first&&null!==t||(this.innerList=e),this}append(t,e=this.last){return this.insertAfter(e,t)}prepend(t,e=this.first){return this.insertBefore(e,t)}remove(t){let e=null,r=this.first;for(;r!==t;)e=r,r=r.next;return e&&(e.next=t.next),t===this.first&&null!==t&&(this.innerList=t.next),t}item(t){if(t>=0){let e=this.first,r=-1;for(;++r<t&&null!==e;)e=e.next;return r===t?e:null}let e=this.first,r=0;const i=this.length+t;if(i<0)return null;for(;r<i&&null!==e;)e=e.next,++r;return r===i?e:null}forEach(t,e=this){let r=0,i=e.first;for(;null!==i;)t(i,r,e),i=i.next,++r;return e}[Symbol.iterator](){return new _LinkerIterator.LinkerIterator(this.first)}}exports.LinkedList=LinkedList,LinkedList.fromArray=(t=[],e=_Linker.Linker,r=LinkedList)=>new r(e).initialize(e.fromArray(t).head);
|
|
@@ -18,12 +18,10 @@ class Linker {
|
|
|
18
18
|
* @param {*} [nodeData.data=null] The data to be stored in this linker
|
|
19
19
|
* @param {Linker|null} [nodeData.next=null] The reference to the next linker if any
|
|
20
20
|
*/
|
|
21
|
-
constructor (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const _ref$next = _ref.next
|
|
26
|
-
const next = _ref$next === void 0 ? null : _ref$next
|
|
21
|
+
constructor ({
|
|
22
|
+
data = null,
|
|
23
|
+
next = null
|
|
24
|
+
} = {}) {
|
|
27
25
|
this.classType = Linker
|
|
28
26
|
this.data = null
|
|
29
27
|
this.next = null
|
|
@@ -38,8 +36,7 @@ class Linker {
|
|
|
38
36
|
* @return {Linker}
|
|
39
37
|
*/
|
|
40
38
|
exports.Linker = Linker
|
|
41
|
-
Linker.make =
|
|
42
|
-
const classType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Linker
|
|
39
|
+
Linker.make = (linker, classType = Linker) => {
|
|
43
40
|
if (typeof linker !== 'object') {
|
|
44
41
|
// It is not an object, so instantiate the Linker with element as the data
|
|
45
42
|
return new classType({
|
|
@@ -64,23 +61,20 @@ Linker.make = function (linker) {
|
|
|
64
61
|
* @param {IsLinker} [classType=Linker] Provide the type of IsLinker to use.
|
|
65
62
|
* @returns {{head: Linker, tail: Linker}}
|
|
66
63
|
*/
|
|
67
|
-
Linker.fromArray =
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
head: newLinker,
|
|
75
|
-
tail: newLinker
|
|
76
|
-
}
|
|
64
|
+
Linker.fromArray = (values, classType = Linker) => values.reduce((references, linker) => {
|
|
65
|
+
const newLinker = classType.make(linker, classType)
|
|
66
|
+
if (references.head === null) {
|
|
67
|
+
// Initialize the head and tail with the new node
|
|
68
|
+
return {
|
|
69
|
+
head: newLinker,
|
|
70
|
+
tail: newLinker
|
|
77
71
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
72
|
+
}
|
|
73
|
+
// Only update the tail once head has been set, tail is always the most recent node
|
|
74
|
+
references.tail.next = newLinker
|
|
75
|
+
references.tail = newLinker
|
|
76
|
+
return references
|
|
77
|
+
}, {
|
|
78
|
+
head: null,
|
|
79
|
+
tail: null
|
|
80
|
+
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Linker=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var _ArrayElement=require("../arrayable/ArrayElement");class Linker{constructor(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Linker=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var _ArrayElement=require("../arrayable/ArrayElement");class Linker{constructor({data:e=null,next:r=null}={}){this.classType=Linker,this.data=null,this.next=null,this.data=e,this.next=r}}exports.Linker=Linker,Linker.make=(e,r=Linker)=>"object"!=typeof e?new r({data:e}):e.classType?e:(e.data||(e={data:e}),_ArrayElement.ArrayElement.make(e,r)),Linker.fromArray=(e,r=Linker)=>e.reduce(((e,t)=>{const a=r.make(t,r);return null===e.head?{head:a,tail:a}:(e.tail.next=a,e.tail=a,e)}),{head:null,tail:null});
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
4
4
|
value: true
|
|
5
5
|
})
|
|
6
6
|
exports.LinkedTreeList = void 0
|
|
7
|
-
require('core-js/modules/web.dom-collections.iterator.js')
|
|
8
7
|
var _TreeLinker = require('./TreeLinker')
|
|
9
8
|
var _TreeLinkerIterator = require('../../recipes/TreeLinkerIterator')
|
|
10
9
|
var _DoublyLinkedList = require('../doubly-linked-list/DoublyLinkedList')
|
|
@@ -23,8 +22,7 @@ class LinkedTreeList {
|
|
|
23
22
|
/**
|
|
24
23
|
* Create the new LinkedTreeList instance, configure the list class.
|
|
25
24
|
*/
|
|
26
|
-
constructor () {
|
|
27
|
-
const linkerClass = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _TreeLinker.TreeLinker
|
|
25
|
+
constructor (linkerClass = _TreeLinker.TreeLinker) {
|
|
28
26
|
this.classType = LinkedTreeList
|
|
29
27
|
this.innerList = null
|
|
30
28
|
this.initialized = false
|
|
@@ -142,8 +140,7 @@ class LinkedTreeList {
|
|
|
142
140
|
* @param {TreeLinker} item The TreeLinker node that will be the parent of the children
|
|
143
141
|
* @param {LinkedTreeList} children The LinkedTreeList which has the child nodes to use
|
|
144
142
|
*/
|
|
145
|
-
setChildren (item) {
|
|
146
|
-
const children = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null
|
|
143
|
+
setChildren (item, children = null) {
|
|
147
144
|
if (Array.from(this).indexOf(item) < 0) {
|
|
148
145
|
console.error('item is not a child of this')
|
|
149
146
|
}
|
|
@@ -176,8 +173,7 @@ class LinkedTreeList {
|
|
|
176
173
|
* @param {TreeLinker} after The existing last node
|
|
177
174
|
* @returns {TreeLinker}
|
|
178
175
|
*/
|
|
179
|
-
append (node) {
|
|
180
|
-
const after = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.last
|
|
176
|
+
append (node, after = this.last) {
|
|
181
177
|
return _DoublyLinkedList.DoublyLinkedList.prototype.append.call(this, node, after)
|
|
182
178
|
}
|
|
183
179
|
|
|
@@ -187,8 +183,7 @@ class LinkedTreeList {
|
|
|
187
183
|
* @param {TreeLinker} before The existing first node
|
|
188
184
|
* @returns {TreeLinker}
|
|
189
185
|
*/
|
|
190
|
-
prepend (node) {
|
|
191
|
-
const before = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.first
|
|
186
|
+
prepend (node, before = this.first) {
|
|
192
187
|
return _DoublyLinkedList.DoublyLinkedList.prototype.prepend.call(this, node, before)
|
|
193
188
|
}
|
|
194
189
|
|
|
@@ -223,8 +218,7 @@ class LinkedTreeList {
|
|
|
223
218
|
* @param {forEachCallback} callback The function to call for-each tree node
|
|
224
219
|
* @param {LinkedTreeList} thisArg Optional, 'this' reference
|
|
225
220
|
*/
|
|
226
|
-
forEach (callback) {
|
|
227
|
-
const thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this
|
|
221
|
+
forEach (callback, thisArg = this) {
|
|
228
222
|
let index = 0
|
|
229
223
|
let current = thisArg.first
|
|
230
224
|
while (current !== null) {
|
|
@@ -252,10 +246,7 @@ class LinkedTreeList {
|
|
|
252
246
|
* @returns {LinkedTreeList}
|
|
253
247
|
*/
|
|
254
248
|
exports.LinkedTreeList = LinkedTreeList
|
|
255
|
-
LinkedTreeList.fromArray =
|
|
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
|
|
249
|
+
LinkedTreeList.fromArray = (values = [], linkerClass = _TreeLinker.TreeLinker, classType = LinkedTreeList) => {
|
|
259
250
|
const list = new classType(linkerClass)
|
|
260
251
|
return list.initialize(linkerClass.fromArray(values).head)
|
|
261
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);
|
|
@@ -23,20 +23,14 @@ class TreeLinker {
|
|
|
23
23
|
* @param {TreeLinker} [settings.parent=null] The reference to a parent linker if any
|
|
24
24
|
* @param {IsArrayable<IsTreeNode>} listClass Give the type of list to use for storing the children
|
|
25
25
|
*/
|
|
26
|
-
constructor (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const _ref$children = _ref.children
|
|
35
|
-
const children = _ref$children === void 0 ? null : _ref$children
|
|
36
|
-
const _ref$parent = _ref.parent
|
|
37
|
-
const parent = _ref$parent === void 0 ? null : _ref$parent
|
|
38
|
-
const _ref$listClass = _ref.listClass
|
|
39
|
-
const listClass = _ref$listClass === void 0 ? _LinkedTreeList.LinkedTreeList : _ref$listClass
|
|
26
|
+
constructor ({
|
|
27
|
+
data = null,
|
|
28
|
+
next = null,
|
|
29
|
+
prev = null,
|
|
30
|
+
children = null,
|
|
31
|
+
parent = null,
|
|
32
|
+
listClass = _LinkedTreeList.LinkedTreeList
|
|
33
|
+
} = {}) {
|
|
40
34
|
this.classType = TreeLinker
|
|
41
35
|
this.data = null
|
|
42
36
|
this.next = null
|
|
@@ -56,9 +50,7 @@ class TreeLinker {
|
|
|
56
50
|
* @param {IsArrayable<IsTreeNode>} listClass Give the type of list to use for storing the children
|
|
57
51
|
* @return {LinkedTreeList|null}
|
|
58
52
|
*/
|
|
59
|
-
childrenFromArray () {
|
|
60
|
-
const children = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null
|
|
61
|
-
const listClass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _LinkedTreeList.LinkedTreeList
|
|
53
|
+
childrenFromArray (children = null, listClass = _LinkedTreeList.LinkedTreeList) {
|
|
62
54
|
if (children === null) {
|
|
63
55
|
return null
|
|
64
56
|
}
|
|
@@ -75,8 +67,7 @@ class TreeLinker {
|
|
|
75
67
|
* @return {TreeLinker}
|
|
76
68
|
*/
|
|
77
69
|
exports.TreeLinker = TreeLinker
|
|
78
|
-
TreeLinker.make =
|
|
79
|
-
const classType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TreeLinker
|
|
70
|
+
TreeLinker.make = (linker, classType = TreeLinker) => {
|
|
80
71
|
return _DoubleLinker.DoubleLinker.make(linker, classType)
|
|
81
72
|
}
|
|
82
73
|
/**
|
|
@@ -85,8 +76,4 @@ TreeLinker.make = function (linker) {
|
|
|
85
76
|
* @param {IsTreeNode} [classType=TreeLinker] Provide the type of IsTreeNode to use.
|
|
86
77
|
* @returns {{head: TreeLinker, tail: TreeLinker}}
|
|
87
78
|
*/
|
|
88
|
-
TreeLinker.fromArray =
|
|
89
|
-
const values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []
|
|
90
|
-
const classType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TreeLinker
|
|
91
|
-
return _DoubleLinker.DoubleLinker.fromArray(values, classType)
|
|
92
|
-
}
|
|
79
|
+
TreeLinker.fromArray = (values = [], classType = TreeLinker) => _DoubleLinker.DoubleLinker.fromArray(values, classType)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TreeLinker=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.map.js");var _DoubleLinker=require("../doubly-linked-list/DoubleLinker"),_LinkedTreeList=require("./LinkedTreeList");class TreeLinker{constructor(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TreeLinker=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.map.js");var _DoubleLinker=require("../doubly-linked-list/DoubleLinker"),_LinkedTreeList=require("./LinkedTreeList");class TreeLinker{constructor({data:e=null,next:r=null,prev:i=null,children:n=null,parent:t=null,listClass:l=_LinkedTreeList.LinkedTreeList}={}){this.classType=TreeLinker,this.data=null,this.next=null,this.prev=null,this.parent=null,this.children=null,this.data=e,this.next=r,this.prev=i,this.parent=t,this.children=this.childrenFromArray(n,l)}childrenFromArray(e=null,r=_LinkedTreeList.LinkedTreeList){return null===e?null:r.fromArray(e.map((e=>Object.assign({},e,{parent:this}))),this.classType)}}exports.TreeLinker=TreeLinker,TreeLinker.make=(e,r=TreeLinker)=>_DoubleLinker.DoubleLinker.make(e,r),TreeLinker.fromArray=(e=[],r=TreeLinker)=>_DoubleLinker.DoubleLinker.fromArray(e,r);
|
|
@@ -23,10 +23,7 @@ class Queue {
|
|
|
23
23
|
* @param {IsArrayable} listClass
|
|
24
24
|
* @param {Queueable} queueableClass
|
|
25
25
|
*/
|
|
26
|
-
constructor () {
|
|
27
|
-
let queuedList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null
|
|
28
|
-
const listClass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _LinkedList.LinkedList
|
|
29
|
-
const queueableClass = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _Queueable.Queueable
|
|
26
|
+
constructor (queuedList = null, listClass = _LinkedList.LinkedList, queueableClass = _Queueable.Queueable) {
|
|
30
27
|
this.listClass = listClass
|
|
31
28
|
this.queueableClass = queueableClass
|
|
32
29
|
if (queuedList === null) {
|
|
@@ -126,10 +123,7 @@ class Queue {
|
|
|
126
123
|
* @returns {Queue}
|
|
127
124
|
*/
|
|
128
125
|
exports.Queue = Queue
|
|
129
|
-
Queue.fromArray =
|
|
130
|
-
const values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []
|
|
131
|
-
const queueableClass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _Queueable.Queueable
|
|
132
|
-
const listClass = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _LinkedList.LinkedList
|
|
126
|
+
Queue.fromArray = (values = [], queueableClass = _Queueable.Queueable, listClass = _LinkedList.LinkedList) => {
|
|
133
127
|
const list = new listClass(queueableClass)
|
|
134
128
|
list.initialize(queueableClass.fromArray(values, queueableClass).head)
|
|
135
129
|
return new Queue(list, listClass, queueableClass)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Queue=void 0;var _Queueable=require("./Queueable"),_LinkedList=require("../linked-list/LinkedList");class Queue{constructor(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Queue=void 0;var _Queueable=require("./Queueable"),_LinkedList=require("../linked-list/LinkedList");class Queue{constructor(e=null,u=_LinkedList.LinkedList,t=_Queueable.Queueable){this.listClass=u,this.queueableClass=t,null===e&&(e=new u(t)),this.queuedList=e}dequeue(){const e=this.remove();return e?e.complete?this.dequeue():e.running?{success:!1,error:"The queue has been blocked by an unfinished task.",context:e}:(this.empty()||this.enqueue(e),e.isReady?e.run.call(e):{success:!1,error:"Unable to find ready task.",context:e}):{success:"No more queueable tasks in the queue",error:!1,context:this.queuedList}}empty(){return this.size()<=0}enqueue(e){this.queuedList.append(e)}peek(){return this.queuedList.first}remove(){return this.empty()?null:this.queuedList.remove(this.queuedList.first)}size(){return this.queuedList.length}}exports.Queue=Queue,Queue.fromArray=(e=[],u=_Queueable.Queueable,t=_LinkedList.LinkedList)=>{const s=new t(u);return s.initialize(u.fromArray(e,u).head),new Queue(s,t,u)};
|