collect-your-stuff 1.4.0 → 2.1.0
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/dist/collections/linked-tree-list/LinkedTreeList.d.ts +31 -19
- package/dist/collections/linked-tree-list/LinkedTreeList.js +63 -24
- package/dist/collections/linked-tree-list/LinkedTreeList.min.js +1 -1
- package/dist/collections/linked-tree-list/TreeLinker.d.ts +3 -1
- package/dist/collections/linked-tree-list/TreeLinker.js +14 -5
- package/dist/collections/linked-tree-list/TreeLinker.min.js +1 -1
- package/dist/collections/queue/Queue.d.ts +35 -42
- package/dist/collections/queue/Queue.js +64 -80
- package/dist/collections/queue/Queue.min.js +1 -1
- package/dist/collections/queue/TaskQueue.d.ts +68 -0
- package/dist/collections/queue/TaskQueue.js +137 -0
- package/dist/collections/queue/TaskQueue.min.js +1 -0
- package/dist/collections/stack/Stack.d.ts +40 -40
- package/dist/collections/stack/Stack.js +73 -52
- package/dist/collections/stack/Stack.min.js +1 -1
- package/dist/collections/stack/TaskStack.d.ts +65 -0
- package/dist/collections/stack/TaskStack.js +107 -0
- package/dist/collections/stack/TaskStack.min.js +1 -0
- package/dist/main.d.ts +8 -2
- package/dist/main.js +16 -0
- package/dist/main.min.js +1 -1
- package/dist/recipes/IsQueue.d.ts +37 -0
- package/dist/recipes/IsQueue.js +5 -0
- package/dist/recipes/IsQueue.min.js +1 -0
- package/dist/recipes/IsStack.d.ts +36 -0
- package/dist/recipes/IsStack.js +5 -0
- package/dist/recipes/IsStack.min.js +1 -0
- package/dist/recipes/TreeLinkerIterator.d.ts +3 -1
- package/dist/recipes/TreeLinkerIterator.js +4 -2
- package/dist/recipes/TreeLinkerIterator.min.js +1 -1
- package/dist/services/parseTreeNext.d.ts +4 -1
- package/dist/services/parseTreeNext.js +14 -19
- package/dist/services/parseTreeNext.min.js +1 -1
- package/dist/services/services.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.TaskStack = void 0
|
|
7
|
+
var _Stackable = require('./Stackable')
|
|
8
|
+
var _LinkedList = require('../linked-list/LinkedList')
|
|
9
|
+
/**
|
|
10
|
+
* @file task stack.
|
|
11
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
12
|
+
* @version 1.0.0
|
|
13
|
+
* @memberOf module:collect-your-stuff
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Store a collection of tasks (Stackables) which can only be inserted and removed from the top: pop() takes the task from
|
|
18
|
+
* the top and RUNS it. For a plain last-in-first-out collection of items use Stack.
|
|
19
|
+
*/
|
|
20
|
+
class TaskStack {
|
|
21
|
+
/**
|
|
22
|
+
* Instantiate the state with the starter stacked list.
|
|
23
|
+
* @param {Iterable|LinkedList} [stackedList=null] The list of stackables to start in this stack.
|
|
24
|
+
* @param {IsArrayable} [listClass=LinkedList] The type of list to create when no stacked list is given.
|
|
25
|
+
* @param {Stackable} [stackableClass=Stackable] The class used to wrap stacked items.
|
|
26
|
+
*/
|
|
27
|
+
constructor (stackedList = null, listClass = _LinkedList.LinkedList, stackableClass = _Stackable.Stackable) {
|
|
28
|
+
this.listClass = listClass
|
|
29
|
+
this.stackableClass = stackableClass
|
|
30
|
+
if (stackedList === null) {
|
|
31
|
+
stackedList = new listClass(stackableClass)
|
|
32
|
+
}
|
|
33
|
+
this.stackedList = stackedList
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Return true if the stack is empty (there are no tasks in the stacked list)
|
|
38
|
+
* @return {boolean}
|
|
39
|
+
*/
|
|
40
|
+
empty () {
|
|
41
|
+
return this.size() <= 0
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Take a look at the next stacked task
|
|
46
|
+
* @return {Stackable}
|
|
47
|
+
*/
|
|
48
|
+
top () {
|
|
49
|
+
return this.stackedList.first
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Remove the next stacked task and return it.
|
|
54
|
+
* @return {Stackable|null}
|
|
55
|
+
*/
|
|
56
|
+
pop () {
|
|
57
|
+
const next = this.remove()
|
|
58
|
+
if (!next) {
|
|
59
|
+
return {
|
|
60
|
+
success: 'No more stackable tasks in the stack',
|
|
61
|
+
error: false,
|
|
62
|
+
context: this.stackedList
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return next.run()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Push a stackable task to the top of the stack.
|
|
70
|
+
* @param {Stackable|*} stackable Add a new stackable to the top of the stack
|
|
71
|
+
*/
|
|
72
|
+
push (stackable) {
|
|
73
|
+
this.stackedList.prepend(stackable)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Remove the next stacked task and return it.
|
|
78
|
+
* @return {Stackable|null}
|
|
79
|
+
*/
|
|
80
|
+
remove () {
|
|
81
|
+
if (this.empty()) {
|
|
82
|
+
return null
|
|
83
|
+
}
|
|
84
|
+
return this.stackedList.remove(this.stackedList.first)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Get the size of the current stack.
|
|
89
|
+
* @return {number}
|
|
90
|
+
*/
|
|
91
|
+
size () {
|
|
92
|
+
return this.stackedList.length
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Convert an array to a TaskStack.
|
|
97
|
+
* @param {Array} values An array of values which will be converted to stackables in this queue
|
|
98
|
+
* @param {Stackable} stackableClass The class to use for each stackable
|
|
99
|
+
* @param {TaskStack|Iterable} listClass The class to use to manage the stackables
|
|
100
|
+
* @returns {TaskStack}
|
|
101
|
+
*/
|
|
102
|
+
exports.TaskStack = TaskStack
|
|
103
|
+
TaskStack.fromArray = (values = [], stackableClass = _Stackable.Stackable, listClass = _LinkedList.LinkedList) => {
|
|
104
|
+
const list = new listClass(stackableClass)
|
|
105
|
+
list.initialize(stackableClass.fromArray(values, stackableClass).head)
|
|
106
|
+
return new TaskStack(list, listClass, stackableClass)
|
|
107
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TaskStack=void 0;var _Stackable=require("./Stackable"),_LinkedList=require("../linked-list/LinkedList");class TaskStack{constructor(t=null,s=_LinkedList.LinkedList,e=_Stackable.Stackable){this.listClass=s,this.stackableClass=e,null===t&&(t=new s(e)),this.stackedList=t}empty(){return this.size()<=0}top(){return this.stackedList.first}pop(){const t=this.remove();return t?t.run():{success:"No more stackable tasks in the stack",error:!1,context:this.stackedList}}push(t){this.stackedList.prepend(t)}remove(){return this.empty()?null:this.stackedList.remove(this.stackedList.first)}size(){return this.stackedList.length}}exports.TaskStack=TaskStack,TaskStack.fromArray=(t=[],s=_Stackable.Stackable,e=_LinkedList.LinkedList)=>{const i=new e(s);return i.initialize(s.fromArray(t,s).head),new TaskStack(i,e,s)};
|
package/dist/main.d.ts
CHANGED
|
@@ -16,8 +16,10 @@ import { TreeLinker } from './collections/linked-tree-list/TreeLinker';
|
|
|
16
16
|
import { LinkedTreeList } from './collections/linked-tree-list/LinkedTreeList';
|
|
17
17
|
import { Queueable } from './collections/queue/Queueable';
|
|
18
18
|
import { Queue } from './collections/queue/Queue';
|
|
19
|
+
import { TaskQueue } from './collections/queue/TaskQueue';
|
|
19
20
|
import { Stackable } from './collections/stack/Stackable';
|
|
20
21
|
import { Stack } from './collections/stack/Stack';
|
|
22
|
+
import { TaskStack } from './collections/stack/TaskStack';
|
|
21
23
|
import { recipes } from './recipes/recipes';
|
|
22
24
|
import { services } from './services/services';
|
|
23
25
|
/**
|
|
@@ -26,13 +28,15 @@ import { services } from './services/services';
|
|
|
26
28
|
* 2. Create a heap (both min and max heap variants) which is similar to binary tree in structure, but tree having its min / max value as root. and it must insert on the left-most lowest level, and removes from root. Be able to easily swap nodes to ensure min / max ordering.
|
|
27
29
|
* 3. Create a graph type which can have directional and undirectional variants for linking nodes
|
|
28
30
|
*/
|
|
29
|
-
export { ArrayElement, Arrayable, DoubleLinker, DoublyLinkedList, Linker, LinkedList, TreeLinker, LinkedTreeList, Queueable, Queue, Stackable, Stack, recipes, services };
|
|
31
|
+
export { ArrayElement, Arrayable, DoubleLinker, DoublyLinkedList, Linker, LinkedList, TreeLinker, LinkedTreeList, Queueable, Queue, TaskQueue, Stackable, Stack, TaskStack, recipes, services };
|
|
30
32
|
export type { IsArrayable, forEachCallback } from './recipes/IsArrayable';
|
|
31
33
|
export type { IsDoubleLinker } from './recipes/IsDoubleLinker';
|
|
32
34
|
export type { IsElement } from './recipes/IsElement';
|
|
33
35
|
export type { IsLinker } from './recipes/IsLinker';
|
|
34
36
|
export type { IsTree } from './recipes/IsTree';
|
|
35
37
|
export type { IsTreeNode } from './recipes/IsTreeNode';
|
|
38
|
+
export type { IsQueue } from './recipes/IsQueue';
|
|
39
|
+
export type { IsStack } from './recipes/IsStack';
|
|
36
40
|
export type { IsRunnable, completeResponse } from './recipes/Runnable';
|
|
37
41
|
/**
|
|
38
42
|
* All methods exported from this module are encapsulated within collect-your-stuff (this default export is the same
|
|
@@ -49,15 +53,17 @@ declare const collectYourStuff: {
|
|
|
49
53
|
LinkedTreeList: typeof LinkedTreeList;
|
|
50
54
|
Queueable: typeof Queueable;
|
|
51
55
|
Queue: typeof Queue;
|
|
56
|
+
TaskQueue: typeof TaskQueue;
|
|
52
57
|
Stackable: typeof Stackable;
|
|
53
58
|
Stack: typeof Stack;
|
|
59
|
+
TaskStack: typeof TaskStack;
|
|
54
60
|
recipes: {
|
|
55
61
|
ArrayIterator: typeof import("./recipes/ArrayIterator").ArrayIterator;
|
|
56
62
|
Runnable: typeof import("./recipes/Runnable").Runnable;
|
|
57
63
|
};
|
|
58
64
|
services: {
|
|
59
65
|
parseTree: (tree: import("./main").IsTree, callback: import("./main").forEachCallback) => import("./main").IsTree;
|
|
60
|
-
parseTreeNext: (treeNode: import("./main").IsTreeNode) => import("./main").IsTreeNode | null;
|
|
66
|
+
parseTreeNext: (treeNode: import("./main").IsTreeNode, boundaryParent?: import("./main").IsTreeNode | null) => import("./main").IsTreeNode | null;
|
|
61
67
|
};
|
|
62
68
|
};
|
|
63
69
|
export default collectYourStuff;
|
package/dist/main.js
CHANGED
|
@@ -69,6 +69,18 @@ Object.defineProperty(exports, 'Stackable', {
|
|
|
69
69
|
return _Stackable.Stackable
|
|
70
70
|
}
|
|
71
71
|
})
|
|
72
|
+
Object.defineProperty(exports, 'TaskQueue', {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _TaskQueue.TaskQueue
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
Object.defineProperty(exports, 'TaskStack', {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _TaskStack.TaskStack
|
|
82
|
+
}
|
|
83
|
+
})
|
|
72
84
|
Object.defineProperty(exports, 'TreeLinker', {
|
|
73
85
|
enumerable: true,
|
|
74
86
|
get: function () {
|
|
@@ -99,8 +111,10 @@ var _TreeLinker = require('./collections/linked-tree-list/TreeLinker')
|
|
|
99
111
|
var _LinkedTreeList = require('./collections/linked-tree-list/LinkedTreeList')
|
|
100
112
|
var _Queueable = require('./collections/queue/Queueable')
|
|
101
113
|
var _Queue = require('./collections/queue/Queue')
|
|
114
|
+
var _TaskQueue = require('./collections/queue/TaskQueue')
|
|
102
115
|
var _Stackable = require('./collections/stack/Stackable')
|
|
103
116
|
var _Stack = require('./collections/stack/Stack')
|
|
117
|
+
var _TaskStack = require('./collections/stack/TaskStack')
|
|
104
118
|
var _recipes = require('./recipes/recipes')
|
|
105
119
|
var _services = require('./services/services')
|
|
106
120
|
/**
|
|
@@ -135,8 +149,10 @@ const collectYourStuff = {
|
|
|
135
149
|
LinkedTreeList: _LinkedTreeList.LinkedTreeList,
|
|
136
150
|
Queueable: _Queueable.Queueable,
|
|
137
151
|
Queue: _Queue.Queue,
|
|
152
|
+
TaskQueue: _TaskQueue.TaskQueue,
|
|
138
153
|
Stackable: _Stackable.Stackable,
|
|
139
154
|
Stack: _Stack.Stack,
|
|
155
|
+
TaskStack: _TaskStack.TaskStack,
|
|
140
156
|
recipes: _recipes.recipes,
|
|
141
157
|
services: _services.services
|
|
142
158
|
}
|
package/dist/main.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ArrayElement",{enumerable:!0,get:function(){return _ArrayElement.ArrayElement}}),Object.defineProperty(exports,"Arrayable",{enumerable:!0,get:function(){return _Arrayable.Arrayable}}),Object.defineProperty(exports,"DoubleLinker",{enumerable:!0,get:function(){return _DoubleLinker.DoubleLinker}}),Object.defineProperty(exports,"DoublyLinkedList",{enumerable:!0,get:function(){return _DoublyLinkedList.DoublyLinkedList}}),Object.defineProperty(exports,"LinkedList",{enumerable:!0,get:function(){return _LinkedList.LinkedList}}),Object.defineProperty(exports,"LinkedTreeList",{enumerable:!0,get:function(){return _LinkedTreeList.LinkedTreeList}}),Object.defineProperty(exports,"Linker",{enumerable:!0,get:function(){return _Linker.Linker}}),Object.defineProperty(exports,"Queue",{enumerable:!0,get:function(){return _Queue.Queue}}),Object.defineProperty(exports,"Queueable",{enumerable:!0,get:function(){return _Queueable.Queueable}}),Object.defineProperty(exports,"Stack",{enumerable:!0,get:function(){return _Stack.Stack}}),Object.defineProperty(exports,"Stackable",{enumerable:!0,get:function(){return _Stackable.Stackable}}),Object.defineProperty(exports,"TreeLinker",{enumerable:!0,get:function(){return _TreeLinker.TreeLinker}}),exports.default=void 0,Object.defineProperty(exports,"recipes",{enumerable:!0,get:function(){return _recipes.recipes}}),Object.defineProperty(exports,"services",{enumerable:!0,get:function(){return _services.services}}),require("core-js/stable");var _ArrayElement=require("./collections/arrayable/ArrayElement"),_Arrayable=require("./collections/arrayable/Arrayable"),_DoubleLinker=require("./collections/doubly-linked-list/DoubleLinker"),_DoublyLinkedList=require("./collections/doubly-linked-list/DoublyLinkedList"),_Linker=require("./collections/linked-list/Linker"),_LinkedList=require("./collections/linked-list/LinkedList"),_TreeLinker=require("./collections/linked-tree-list/TreeLinker"),_LinkedTreeList=require("./collections/linked-tree-list/LinkedTreeList"),_Queueable=require("./collections/queue/Queueable"),_Queue=require("./collections/queue/Queue"),_Stackable=require("./collections/stack/Stackable"),_Stack=require("./collections/stack/Stack"),_recipes=require("./recipes/recipes"),_services=require("./services/services");const collectYourStuff={ArrayElement:_ArrayElement.ArrayElement,Arrayable:_Arrayable.Arrayable,DoubleLinker:_DoubleLinker.DoubleLinker,DoublyLinkedList:_DoublyLinkedList.DoublyLinkedList,Linker:_Linker.Linker,LinkedList:_LinkedList.LinkedList,TreeLinker:_TreeLinker.TreeLinker,LinkedTreeList:_LinkedTreeList.LinkedTreeList,Queueable:_Queueable.Queueable,Queue:_Queue.Queue,Stackable:_Stackable.Stackable,Stack:_Stack.Stack,recipes:_recipes.recipes,services:_services.services};var _default=exports.default=collectYourStuff;"undefined"!=typeof window&&(window.collectYourStuff=collectYourStuff);
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ArrayElement",{enumerable:!0,get:function(){return _ArrayElement.ArrayElement}}),Object.defineProperty(exports,"Arrayable",{enumerable:!0,get:function(){return _Arrayable.Arrayable}}),Object.defineProperty(exports,"DoubleLinker",{enumerable:!0,get:function(){return _DoubleLinker.DoubleLinker}}),Object.defineProperty(exports,"DoublyLinkedList",{enumerable:!0,get:function(){return _DoublyLinkedList.DoublyLinkedList}}),Object.defineProperty(exports,"LinkedList",{enumerable:!0,get:function(){return _LinkedList.LinkedList}}),Object.defineProperty(exports,"LinkedTreeList",{enumerable:!0,get:function(){return _LinkedTreeList.LinkedTreeList}}),Object.defineProperty(exports,"Linker",{enumerable:!0,get:function(){return _Linker.Linker}}),Object.defineProperty(exports,"Queue",{enumerable:!0,get:function(){return _Queue.Queue}}),Object.defineProperty(exports,"Queueable",{enumerable:!0,get:function(){return _Queueable.Queueable}}),Object.defineProperty(exports,"Stack",{enumerable:!0,get:function(){return _Stack.Stack}}),Object.defineProperty(exports,"Stackable",{enumerable:!0,get:function(){return _Stackable.Stackable}}),Object.defineProperty(exports,"TaskQueue",{enumerable:!0,get:function(){return _TaskQueue.TaskQueue}}),Object.defineProperty(exports,"TaskStack",{enumerable:!0,get:function(){return _TaskStack.TaskStack}}),Object.defineProperty(exports,"TreeLinker",{enumerable:!0,get:function(){return _TreeLinker.TreeLinker}}),exports.default=void 0,Object.defineProperty(exports,"recipes",{enumerable:!0,get:function(){return _recipes.recipes}}),Object.defineProperty(exports,"services",{enumerable:!0,get:function(){return _services.services}}),require("core-js/stable");var _ArrayElement=require("./collections/arrayable/ArrayElement"),_Arrayable=require("./collections/arrayable/Arrayable"),_DoubleLinker=require("./collections/doubly-linked-list/DoubleLinker"),_DoublyLinkedList=require("./collections/doubly-linked-list/DoublyLinkedList"),_Linker=require("./collections/linked-list/Linker"),_LinkedList=require("./collections/linked-list/LinkedList"),_TreeLinker=require("./collections/linked-tree-list/TreeLinker"),_LinkedTreeList=require("./collections/linked-tree-list/LinkedTreeList"),_Queueable=require("./collections/queue/Queueable"),_Queue=require("./collections/queue/Queue"),_TaskQueue=require("./collections/queue/TaskQueue"),_Stackable=require("./collections/stack/Stackable"),_Stack=require("./collections/stack/Stack"),_TaskStack=require("./collections/stack/TaskStack"),_recipes=require("./recipes/recipes"),_services=require("./services/services");const collectYourStuff={ArrayElement:_ArrayElement.ArrayElement,Arrayable:_Arrayable.Arrayable,DoubleLinker:_DoubleLinker.DoubleLinker,DoublyLinkedList:_DoublyLinkedList.DoublyLinkedList,Linker:_Linker.Linker,LinkedList:_LinkedList.LinkedList,TreeLinker:_TreeLinker.TreeLinker,LinkedTreeList:_LinkedTreeList.LinkedTreeList,Queueable:_Queueable.Queueable,Queue:_Queue.Queue,TaskQueue:_TaskQueue.TaskQueue,Stackable:_Stackable.Stackable,Stack:_Stack.Stack,TaskStack:_TaskStack.TaskStack,recipes:_recipes.recipes,services:_services.services};var _default=exports.default=collectYourStuff;"undefined"!=typeof window&&(window.collectYourStuff=collectYourStuff);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Queue recipe.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
* @memberOf module:collect-your-stuff
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Define a first-in-first-out queue: items are added to the back (enqueue) and taken from the front (dequeue).
|
|
9
|
+
* This is the shape which si-funciona's queueManager / queueTimeout expect of a queue.
|
|
10
|
+
*/
|
|
11
|
+
export interface IsQueue<T = any> {
|
|
12
|
+
/**
|
|
13
|
+
* Take the item from the front of the queue.
|
|
14
|
+
* @return {T|null} The item, or null when the queue is empty
|
|
15
|
+
*/
|
|
16
|
+
dequeue: () => T | null;
|
|
17
|
+
/**
|
|
18
|
+
* Check whether the queue has no items.
|
|
19
|
+
* @return {boolean}
|
|
20
|
+
*/
|
|
21
|
+
empty: () => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Add an item to the back of the queue.
|
|
24
|
+
* @param {T} data The item to add
|
|
25
|
+
*/
|
|
26
|
+
enqueue: (data: T) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Look at the item at the front of the queue, without removing it.
|
|
29
|
+
* @return {T|null} The item, or null when the queue is empty
|
|
30
|
+
*/
|
|
31
|
+
peek: () => T | null;
|
|
32
|
+
/**
|
|
33
|
+
* Count the items in the queue.
|
|
34
|
+
* @return {number}
|
|
35
|
+
*/
|
|
36
|
+
size: () => number;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Stack recipe.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
* @memberOf module:collect-your-stuff
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Define a last-in-first-out stack: items are added to the top (push) and taken from the top (pop).
|
|
9
|
+
*/
|
|
10
|
+
export interface IsStack<T = any> {
|
|
11
|
+
/**
|
|
12
|
+
* Check whether the stack has no items.
|
|
13
|
+
* @return {boolean}
|
|
14
|
+
*/
|
|
15
|
+
empty: () => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Look at the item on the top of the stack, without removing it.
|
|
18
|
+
* @return {T|null} The item, or null when the stack is empty
|
|
19
|
+
*/
|
|
20
|
+
peek: () => T | null;
|
|
21
|
+
/**
|
|
22
|
+
* Take the item from the top of the stack.
|
|
23
|
+
* @return {T|null} The item, or null when the stack is empty
|
|
24
|
+
*/
|
|
25
|
+
pop: () => T | null;
|
|
26
|
+
/**
|
|
27
|
+
* Add an item to the top of the stack.
|
|
28
|
+
* @param {T} data The item to add
|
|
29
|
+
*/
|
|
30
|
+
push: (data: T) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Count the items in the stack.
|
|
33
|
+
* @return {number}
|
|
34
|
+
*/
|
|
35
|
+
size: () => number;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -4,11 +4,13 @@ import { IsTreeNode } from './IsTreeNode';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare class TreeLinkerIterator implements Iterator<IsTreeNode> {
|
|
6
6
|
private current;
|
|
7
|
+
private readonly boundaryParent;
|
|
7
8
|
/**
|
|
8
9
|
* Create an iterator starting at the given item.
|
|
9
10
|
* @param {IsTreeNode} current The item to start from.
|
|
11
|
+
* @param {IsTreeNode|null} [boundaryParent] The parent of the nodes to stay within (null for the top of a tree), the whole tree when not given.
|
|
10
12
|
*/
|
|
11
|
-
constructor(current: IsTreeNode);
|
|
13
|
+
constructor(current: IsTreeNode, boundaryParent?: IsTreeNode | null);
|
|
12
14
|
/**
|
|
13
15
|
* Get the current item and move on to the following one (left-first, down each branch).
|
|
14
16
|
* @param {*} [value] Not used, present to match the Iterator interface.
|
|
@@ -12,9 +12,11 @@ class TreeLinkerIterator {
|
|
|
12
12
|
/**
|
|
13
13
|
* Create an iterator starting at the given item.
|
|
14
14
|
* @param {IsTreeNode} current The item to start from.
|
|
15
|
+
* @param {IsTreeNode|null} [boundaryParent] The parent of the nodes to stay within (null for the top of a tree), the whole tree when not given.
|
|
15
16
|
*/
|
|
16
|
-
constructor (current) {
|
|
17
|
+
constructor (current, boundaryParent) {
|
|
17
18
|
this.current = current
|
|
19
|
+
this.boundaryParent = boundaryParent
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
/**
|
|
@@ -27,7 +29,7 @@ class TreeLinkerIterator {
|
|
|
27
29
|
value: this.current,
|
|
28
30
|
done: !this.current
|
|
29
31
|
}
|
|
30
|
-
this.current = (0, _parseTreeNext.parseTreeNext)(this.current)
|
|
32
|
+
this.current = (0, _parseTreeNext.parseTreeNext)(this.current, this.boundaryParent)
|
|
31
33
|
return result
|
|
32
34
|
}
|
|
33
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TreeLinkerIterator=void 0;var _parseTreeNext=require("../services/parseTreeNext");class TreeLinkerIterator{constructor(e){this.current=e}next(e){const r={value:this.current,done:!this.current};return this.current=(0,_parseTreeNext.parseTreeNext)(this.current),r}}exports.TreeLinkerIterator=TreeLinkerIterator;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TreeLinkerIterator=void 0;var _parseTreeNext=require("../services/parseTreeNext");class TreeLinkerIterator{constructor(e,r){this.current=e,this.boundaryParent=r}next(e){const r={value:this.current,done:!this.current};return this.current=(0,_parseTreeNext.parseTreeNext)(this.current,this.boundaryParent),r}}exports.TreeLinkerIterator=TreeLinkerIterator;
|
|
@@ -8,7 +8,10 @@ import { IsTreeNode } from '../recipes/IsTreeNode';
|
|
|
8
8
|
* 5. Repeat 3
|
|
9
9
|
* 6. If no next child, return to parent and repeat 3
|
|
10
10
|
* 7. Stop at root (next is null and parent is null
|
|
11
|
+
* A boundary can be given to parse only part of a tree: going back up to the parents stops at the boundary, so the
|
|
12
|
+
* parsing stays within the nodes whose parent is the boundary (and everything below them).
|
|
11
13
|
* @param {IsTreeNode} treeNode Provide a node in a tree and get the next node (left-first approach)
|
|
14
|
+
* @param {IsTreeNode|null} [boundaryParent] The parent of the nodes to stay within, null for the nodes at the top of a tree. When it is not given the whole tree is parsed.
|
|
12
15
|
* @returns {IsTreeNode|null}
|
|
13
16
|
*/
|
|
14
|
-
export declare const parseTreeNext: (treeNode: IsTreeNode) => IsTreeNode | null;
|
|
17
|
+
export declare const parseTreeNext: (treeNode: IsTreeNode, boundaryParent?: IsTreeNode | null) => IsTreeNode | null;
|
|
@@ -13,35 +13,30 @@ exports.parseTreeNext = void 0
|
|
|
13
13
|
* 5. Repeat 3
|
|
14
14
|
* 6. If no next child, return to parent and repeat 3
|
|
15
15
|
* 7. Stop at root (next is null and parent is null
|
|
16
|
+
* A boundary can be given to parse only part of a tree: going back up to the parents stops at the boundary, so the
|
|
17
|
+
* parsing stays within the nodes whose parent is the boundary (and everything below them).
|
|
16
18
|
* @param {IsTreeNode} treeNode Provide a node in a tree and get the next node (left-first approach)
|
|
19
|
+
* @param {IsTreeNode|null} [boundaryParent] The parent of the nodes to stay within, null for the nodes at the top of a tree. When it is not given the whole tree is parsed.
|
|
17
20
|
* @returns {IsTreeNode|null}
|
|
18
21
|
*/
|
|
19
|
-
const parseTreeNext = treeNode => {
|
|
22
|
+
const parseTreeNext = (treeNode, boundaryParent) => {
|
|
20
23
|
if (!treeNode) {
|
|
21
24
|
return null
|
|
22
25
|
}
|
|
23
|
-
let test = null
|
|
24
26
|
if (treeNode.children && treeNode.children.length) {
|
|
25
|
-
|
|
26
|
-
test = treeNode.children.first
|
|
27
|
+
return treeNode.children.first
|
|
27
28
|
}
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
test = treeNode.next
|
|
29
|
+
if (treeNode.next) {
|
|
30
|
+
return treeNode.next
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
parentNext = parent.next
|
|
38
|
-
// Keep checking parent next, until there are no more parents, or we find the parent sibling
|
|
39
|
-
parent = parent.parent
|
|
32
|
+
// Nothing more below or beside this node, so go back up until there is a node which has a next (or the boundary)
|
|
33
|
+
let parent = treeNode.parent
|
|
34
|
+
while (parent && parent !== boundaryParent) {
|
|
35
|
+
if (parent.next) {
|
|
36
|
+
return parent.next
|
|
40
37
|
}
|
|
41
|
-
|
|
42
|
-
test = parentNext
|
|
38
|
+
parent = parent.parent
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
return test
|
|
40
|
+
return null
|
|
46
41
|
}
|
|
47
42
|
exports.parseTreeNext = parseTreeNext
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseTreeNext=void 0;const parseTreeNext=e=>{if(!e)return null;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseTreeNext=void 0;const parseTreeNext=(e,r)=>{if(!e)return null;if(e.children&&e.children.length)return e.children.first;if(e.next)return e.next;let t=e.parent;for(;t&&t!==r;){if(t.next)return t.next;t=t.parent}return null};exports.parseTreeNext=parseTreeNext;
|
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const services: {
|
|
11
11
|
parseTree: (tree: import("../main").IsTree, callback: import("../main").forEachCallback) => import("../main").IsTree;
|
|
12
|
-
parseTreeNext: (treeNode: import("../main").IsTreeNode) => import("../main").IsTreeNode | null;
|
|
12
|
+
parseTreeNext: (treeNode: import("../main").IsTreeNode, boundaryParent?: import("../main").IsTreeNode | null) => import("../main").IsTreeNode | null;
|
|
13
13
|
};
|
package/package.json
CHANGED