collect-your-stuff 2.1.0 → 2.1.2
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 +898 -213
- package/browser/collect-your-stuff.js +2672 -20684
- package/browser/collect-your-stuff.min.js +1 -1
- package/dist/collections/arrayable/ArrayElement.d.ts +38 -38
- package/dist/collections/arrayable/ArrayElement.js +66 -66
- package/dist/collections/arrayable/Arrayable.d.ts +122 -122
- package/dist/collections/arrayable/Arrayable.js +2 -2
- package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +50 -50
- package/dist/collections/doubly-linked-list/DoubleLinker.js +1 -1
- package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +125 -125
- package/dist/collections/doubly-linked-list/DoublyLinkedList.js +3 -3
- package/dist/collections/linked-list/LinkedList.d.ts +126 -126
- package/dist/collections/linked-list/LinkedList.js +3 -3
- package/dist/collections/linked-list/Linker.d.ts +46 -46
- package/dist/collections/linked-list/Linker.js +1 -1
- package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +159 -159
- package/dist/collections/linked-tree-list/LinkedTreeList.js +3 -3
- package/dist/collections/linked-tree-list/TreeLinker.d.ts +71 -71
- package/dist/collections/linked-tree-list/TreeLinker.js +2 -2
- package/dist/collections/queue/Queue.d.ts +59 -59
- package/dist/collections/queue/Queue.js +11 -9
- package/dist/collections/queue/Queueable.d.ts +83 -83
- package/dist/collections/queue/Queueable.js +9 -7
- package/dist/collections/queue/TaskQueue.d.ts +68 -68
- package/dist/collections/queue/TaskQueue.js +2 -2
- package/dist/collections/stack/Stack.d.ts +64 -64
- package/dist/collections/stack/Stack.js +11 -9
- package/dist/collections/stack/Stackable.d.ts +59 -59
- package/dist/collections/stack/Stackable.js +1 -1
- package/dist/collections/stack/TaskStack.d.ts +65 -65
- package/dist/collections/stack/TaskStack.js +2 -2
- package/dist/main.d.ts +68 -69
- package/dist/main.js +1 -2
- package/dist/main.min.js +1 -1
- package/dist/recipes/ArrayIterator.d.ts +20 -20
- package/dist/recipes/ArrayIterator.js +39 -39
- package/dist/recipes/DoubleLinkerIterator.d.ts +18 -18
- package/dist/recipes/DoubleLinkerIterator.js +33 -33
- 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/IsQueue.d.ts +37 -37
- package/dist/recipes/IsQueue.js +5 -5
- package/dist/recipes/IsStack.d.ts +36 -36
- package/dist/recipes/IsStack.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 +18 -18
- package/dist/recipes/LinkerIterator.js +33 -33
- package/dist/recipes/Runnable.d.ts +55 -55
- package/dist/recipes/Runnable.js +69 -69
- package/dist/recipes/TreeLinkerIterator.d.ts +20 -20
- package/dist/recipes/TreeLinkerIterator.js +1 -1
- package/dist/recipes/recipes.d.ts +15 -15
- package/dist/recipes/recipes.js +2 -2
- package/dist/services/parseTree.d.ts +9 -9
- package/dist/services/parseTree.js +1 -1
- package/dist/services/parseTreeNext.d.ts +17 -17
- package/dist/services/parseTreeNext.js +42 -42
- package/dist/services/services.d.ts +13 -13
- package/dist/services/services.js +2 -2
- package/package.json +2 -2
|
@@ -1,159 +1,159 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file doubly linked tree list.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.1.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
6
|
-
*/
|
|
7
|
-
import { TreeLinker } from './TreeLinker';
|
|
8
|
-
import { forEachCallback } from '../../recipes/IsArrayable';
|
|
9
|
-
import { IsTree } from '../../recipes/IsTree';
|
|
10
|
-
import { IsTreeNode } from '../../recipes/IsTreeNode';
|
|
11
|
-
/**
|
|
12
|
-
* LinkedTreeList represents a collection stored with a root and spreading in branching (tree) formation.
|
|
13
|
-
* @extends DoublyLinkedList
|
|
14
|
-
*/
|
|
15
|
-
export declare class LinkedTreeList implements IsTree, Iterable<TreeLinker> {
|
|
16
|
-
/** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
|
|
17
|
-
readonly classType: typeof LinkedTreeList;
|
|
18
|
-
/** A linker of the list (null when the list is empty); the head is found by walking back from it. */
|
|
19
|
-
innerList: IsTreeNode | any;
|
|
20
|
-
/** Whether the inner list has been initialized (it can only be initialized once). */
|
|
21
|
-
initialized: boolean;
|
|
22
|
-
/** The class used to wrap the data given to this list as tree linkers. */
|
|
23
|
-
linkerClass: typeof TreeLinker;
|
|
24
|
-
/** The last linker, remembered so that adding to the end does not need to walk the whole list (null when not known yet). */
|
|
25
|
-
private tailCache;
|
|
26
|
-
/** The number of linkers, kept up to date by the list's own methods so that the length does not need to walk the whole list (null when not known yet). */
|
|
27
|
-
private countCache;
|
|
28
|
-
/** The node these linkers are the children of, remembered so that it is known even while the list is empty (undefined until it is known). */
|
|
29
|
-
private ownerNode;
|
|
30
|
-
/**
|
|
31
|
-
* Create the new LinkedTreeList instance, configure the list class.
|
|
32
|
-
* @param {TreeLinker} [linkerClass=TreeLinker] The class used to wrap given data as tree linkers.
|
|
33
|
-
*/
|
|
34
|
-
constructor(linkerClass?: typeof TreeLinker);
|
|
35
|
-
/**
|
|
36
|
-
* Initialize the inner list, should only run once.
|
|
37
|
-
* @param {TreeLinker} initialList Give the list of tree-linkers to start in this linked-tree-list.
|
|
38
|
-
* @return {LinkedTreeList}
|
|
39
|
-
*/
|
|
40
|
-
initialize(initialList: TreeLinker): LinkedTreeList;
|
|
41
|
-
/**
|
|
42
|
-
* Retrieve the innerList used (the list itself, not a copy).
|
|
43
|
-
* @returns {TreeLinker}
|
|
44
|
-
*/
|
|
45
|
-
get list(): TreeLinker;
|
|
46
|
-
/**
|
|
47
|
-
* Retrieve the first TreeLinker in the list.
|
|
48
|
-
* @returns {TreeLinker}
|
|
49
|
-
*/
|
|
50
|
-
get first(): TreeLinker;
|
|
51
|
-
/**
|
|
52
|
-
* Retrieve the last TreeLinker in the list. The end is remembered, so this does not walk the list.
|
|
53
|
-
* @returns {TreeLinker}
|
|
54
|
-
*/
|
|
55
|
-
get last(): TreeLinker;
|
|
56
|
-
/**
|
|
57
|
-
* Return the length of the list. It is kept up to date by the list's own methods, so this does not walk the list
|
|
58
|
-
* (call reset() after linkers were changed directly).
|
|
59
|
-
* @returns {number}
|
|
60
|
-
*/
|
|
61
|
-
get length(): number;
|
|
62
|
-
/**
|
|
63
|
-
* Get the parent of this tree list: the node these linkers are the children of (remembered even while the list is
|
|
64
|
-
* empty), or null for the linkers at the top of a tree.
|
|
65
|
-
* @return {TreeLinker|null}
|
|
66
|
-
*/
|
|
67
|
-
get parent(): TreeLinker | null;
|
|
68
|
-
/**
|
|
69
|
-
* Set the parent of this tree list: every linker in it gets the node as its parent, and the node gets this list as its
|
|
70
|
-
* children. Linkers added to the list later get this parent too.
|
|
71
|
-
* @param {TreeLinker|null} parent The new node to use as the parent for this group of children
|
|
72
|
-
*/
|
|
73
|
-
set parent(parent: TreeLinker | null);
|
|
74
|
-
/**
|
|
75
|
-
* Return the root parent of the entire tree.
|
|
76
|
-
* @return {TreeLinker}
|
|
77
|
-
*/
|
|
78
|
-
get rootParent(): TreeLinker;
|
|
79
|
-
/**
|
|
80
|
-
* Set the children on a parent item.
|
|
81
|
-
* @param {TreeLinker} item The TreeLinker node (one of the linkers of this list) that will be the parent of the children
|
|
82
|
-
* @param {LinkedTreeList|null} [children=null] The LinkedTreeList which has the child nodes to use, or null to remove the children of the item
|
|
83
|
-
* @throws {Error} When the item is not one of the linkers of this list
|
|
84
|
-
*/
|
|
85
|
-
setChildren(item: TreeLinker, children?: LinkedTreeList | null): void;
|
|
86
|
-
/**
|
|
87
|
-
* Make a linker of the given node (or data) and make this list's parent its parent.
|
|
88
|
-
* @param {TreeLinker|*} newNode The node (or data) which is being added to this list
|
|
89
|
-
* @returns {TreeLinker}
|
|
90
|
-
*/
|
|
91
|
-
private adopt;
|
|
92
|
-
/**
|
|
93
|
-
* Insert a new node (or data) after a node. The new node gets the parent of this list.
|
|
94
|
-
* @param {TreeLinker|*} node The existing node as reference, or null to insert at the start of the list
|
|
95
|
-
* @param {TreeLinker|*} newNode The new node to go after the existing node
|
|
96
|
-
* @returns {LinkedTreeList}
|
|
97
|
-
*/
|
|
98
|
-
insertAfter(node: TreeLinker | null, newNode: TreeLinker | any): LinkedTreeList;
|
|
99
|
-
/**
|
|
100
|
-
* Insert a new node (or data) before a node. The new node gets the parent of this list.
|
|
101
|
-
* @param {TreeLinker|*} node The existing node as reference, or null to insert at the end of the list
|
|
102
|
-
* @param {TreeLinker|*} newNode The new node to go before the existing node
|
|
103
|
-
* @returns {LinkedTreeList}
|
|
104
|
-
*/
|
|
105
|
-
insertBefore(node: TreeLinker | null, newNode: TreeLinker | any): LinkedTreeList;
|
|
106
|
-
/**
|
|
107
|
-
* Add a node (or data) after the given (or last) node in the list.
|
|
108
|
-
* @param {TreeLinker|*} node The new node to add to the end of the list
|
|
109
|
-
* @param {TreeLinker} after The existing last node
|
|
110
|
-
* @returns {TreeLinker}
|
|
111
|
-
*/
|
|
112
|
-
append(node: TreeLinker | any, after?: TreeLinker): LinkedTreeList;
|
|
113
|
-
/**
|
|
114
|
-
* Add a node (or data) before the given (or first) node in the list.
|
|
115
|
-
* @param {TreeLinker|*} node The new node to add to the start of the list
|
|
116
|
-
* @param {TreeLinker} before The existing first node
|
|
117
|
-
* @returns {TreeLinker}
|
|
118
|
-
*/
|
|
119
|
-
prepend(node: TreeLinker | any, before?: TreeLinker): LinkedTreeList;
|
|
120
|
-
/**
|
|
121
|
-
* Remove a linker from this linked list. The removed node no longer has a parent.
|
|
122
|
-
* @param {TreeLinker} node The node we wish to remove (and it will be returned after removal)
|
|
123
|
-
* @return {TreeLinker|null} The removed node, or null when there was nothing to remove
|
|
124
|
-
*/
|
|
125
|
-
remove(node: TreeLinker): TreeLinker | null;
|
|
126
|
-
/**
|
|
127
|
-
* Refresh all references (the head, the end and the length) by walking the list once, and return the head. The
|
|
128
|
-
* list's own methods keep these up to date, so this is only needed after linkers were changed directly.
|
|
129
|
-
* @return {TreeLinker}
|
|
130
|
-
*/
|
|
131
|
-
reset(): TreeLinker;
|
|
132
|
-
/**
|
|
133
|
-
* Retrieve a TreeLinker item from this list by numeric index, otherwise return null.
|
|
134
|
-
* @param {number} index The integer number for retrieving a node by position.
|
|
135
|
-
* @returns {TreeLinker|null}
|
|
136
|
-
*/
|
|
137
|
-
item(index: number): TreeLinker;
|
|
138
|
-
/**
|
|
139
|
-
* Be able to run forEach on this LinkedTreeList to iterate over the TreeLinker Items.
|
|
140
|
-
* @param {forEachCallback} callback The function to call for-each tree node
|
|
141
|
-
* @param {LinkedTreeList} thisArg Optional, 'this' reference
|
|
142
|
-
* @return {LinkedTreeList} The list which was iterated.
|
|
143
|
-
*/
|
|
144
|
-
forEach(callback: forEachCallback, thisArg?: LinkedTreeList): LinkedTreeList;
|
|
145
|
-
/**
|
|
146
|
-
* Be able to iterate over this class: the linkers of this list and everything below them (left-first). It stays within
|
|
147
|
-
* this list (it does not start at, or climb up to, the parents), use the parseTree service to parse a whole tree.
|
|
148
|
-
* @returns {Iterator}
|
|
149
|
-
*/
|
|
150
|
-
[Symbol.iterator](): Iterator<TreeLinker>;
|
|
151
|
-
/**
|
|
152
|
-
* Convert an array into a LinkedTreeList instance, return the new instance.
|
|
153
|
-
* @param {Array} [values=[]] An array of values which will be converted to nodes in this tree-list
|
|
154
|
-
* @param {TreeLinker} [linkerClass=TreeLinker] The class to use for each node
|
|
155
|
-
* @param {IsArrayable<TreeLinker>} [classType=LinkedTreeList] Provide the type of IsArrayable to use.
|
|
156
|
-
* @returns {LinkedTreeList}
|
|
157
|
-
*/
|
|
158
|
-
static fromArray: (values?: Array<any>, linkerClass?: typeof TreeLinker, classType?: any) => IsTree | any;
|
|
159
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @file doubly linked tree list.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.1.0
|
|
5
|
+
* @memberOf module:collect-your-stuff
|
|
6
|
+
*/
|
|
7
|
+
import { TreeLinker } from './TreeLinker';
|
|
8
|
+
import { forEachCallback } from '../../recipes/IsArrayable';
|
|
9
|
+
import { IsTree } from '../../recipes/IsTree';
|
|
10
|
+
import { IsTreeNode } from '../../recipes/IsTreeNode';
|
|
11
|
+
/**
|
|
12
|
+
* LinkedTreeList represents a collection stored with a root and spreading in branching (tree) formation.
|
|
13
|
+
* @extends DoublyLinkedList
|
|
14
|
+
*/
|
|
15
|
+
export declare class LinkedTreeList implements IsTree, Iterable<TreeLinker> {
|
|
16
|
+
/** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
|
|
17
|
+
readonly classType: typeof LinkedTreeList;
|
|
18
|
+
/** A linker of the list (null when the list is empty); the head is found by walking back from it. */
|
|
19
|
+
innerList: IsTreeNode | any;
|
|
20
|
+
/** Whether the inner list has been initialized (it can only be initialized once). */
|
|
21
|
+
initialized: boolean;
|
|
22
|
+
/** The class used to wrap the data given to this list as tree linkers. */
|
|
23
|
+
linkerClass: typeof TreeLinker;
|
|
24
|
+
/** The last linker, remembered so that adding to the end does not need to walk the whole list (null when not known yet). */
|
|
25
|
+
private tailCache;
|
|
26
|
+
/** The number of linkers, kept up to date by the list's own methods so that the length does not need to walk the whole list (null when not known yet). */
|
|
27
|
+
private countCache;
|
|
28
|
+
/** The node these linkers are the children of, remembered so that it is known even while the list is empty (undefined until it is known). */
|
|
29
|
+
private ownerNode;
|
|
30
|
+
/**
|
|
31
|
+
* Create the new LinkedTreeList instance, configure the list class.
|
|
32
|
+
* @param {TreeLinker} [linkerClass=TreeLinker] The class used to wrap given data as tree linkers.
|
|
33
|
+
*/
|
|
34
|
+
constructor(linkerClass?: typeof TreeLinker);
|
|
35
|
+
/**
|
|
36
|
+
* Initialize the inner list, should only run once.
|
|
37
|
+
* @param {TreeLinker} initialList Give the list of tree-linkers to start in this linked-tree-list.
|
|
38
|
+
* @return {LinkedTreeList}
|
|
39
|
+
*/
|
|
40
|
+
initialize(initialList: TreeLinker): LinkedTreeList;
|
|
41
|
+
/**
|
|
42
|
+
* Retrieve the innerList used (the list itself, not a copy).
|
|
43
|
+
* @returns {TreeLinker}
|
|
44
|
+
*/
|
|
45
|
+
get list(): TreeLinker;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieve the first TreeLinker in the list.
|
|
48
|
+
* @returns {TreeLinker}
|
|
49
|
+
*/
|
|
50
|
+
get first(): TreeLinker;
|
|
51
|
+
/**
|
|
52
|
+
* Retrieve the last TreeLinker in the list. The end is remembered, so this does not walk the list.
|
|
53
|
+
* @returns {TreeLinker}
|
|
54
|
+
*/
|
|
55
|
+
get last(): TreeLinker;
|
|
56
|
+
/**
|
|
57
|
+
* Return the length of the list. It is kept up to date by the list's own methods, so this does not walk the list
|
|
58
|
+
* (call reset() after linkers were changed directly).
|
|
59
|
+
* @returns {number}
|
|
60
|
+
*/
|
|
61
|
+
get length(): number;
|
|
62
|
+
/**
|
|
63
|
+
* Get the parent of this tree list: the node these linkers are the children of (remembered even while the list is
|
|
64
|
+
* empty), or null for the linkers at the top of a tree.
|
|
65
|
+
* @return {TreeLinker|null}
|
|
66
|
+
*/
|
|
67
|
+
get parent(): TreeLinker | null;
|
|
68
|
+
/**
|
|
69
|
+
* Set the parent of this tree list: every linker in it gets the node as its parent, and the node gets this list as its
|
|
70
|
+
* children. Linkers added to the list later get this parent too.
|
|
71
|
+
* @param {TreeLinker|null} parent The new node to use as the parent for this group of children
|
|
72
|
+
*/
|
|
73
|
+
set parent(parent: TreeLinker | null);
|
|
74
|
+
/**
|
|
75
|
+
* Return the root parent of the entire tree.
|
|
76
|
+
* @return {TreeLinker}
|
|
77
|
+
*/
|
|
78
|
+
get rootParent(): TreeLinker;
|
|
79
|
+
/**
|
|
80
|
+
* Set the children on a parent item.
|
|
81
|
+
* @param {TreeLinker} item The TreeLinker node (one of the linkers of this list) that will be the parent of the children
|
|
82
|
+
* @param {LinkedTreeList|null} [children=null] The LinkedTreeList which has the child nodes to use, or null to remove the children of the item
|
|
83
|
+
* @throws {Error} When the item is not one of the linkers of this list
|
|
84
|
+
*/
|
|
85
|
+
setChildren(item: TreeLinker, children?: LinkedTreeList | null): void;
|
|
86
|
+
/**
|
|
87
|
+
* Make a linker of the given node (or data) and make this list's parent its parent.
|
|
88
|
+
* @param {TreeLinker|*} newNode The node (or data) which is being added to this list
|
|
89
|
+
* @returns {TreeLinker}
|
|
90
|
+
*/
|
|
91
|
+
private adopt;
|
|
92
|
+
/**
|
|
93
|
+
* Insert a new node (or data) after a node. The new node gets the parent of this list.
|
|
94
|
+
* @param {TreeLinker|*} node The existing node as reference, or null to insert at the start of the list
|
|
95
|
+
* @param {TreeLinker|*} newNode The new node to go after the existing node
|
|
96
|
+
* @returns {LinkedTreeList}
|
|
97
|
+
*/
|
|
98
|
+
insertAfter(node: TreeLinker | null, newNode: TreeLinker | any): LinkedTreeList;
|
|
99
|
+
/**
|
|
100
|
+
* Insert a new node (or data) before a node. The new node gets the parent of this list.
|
|
101
|
+
* @param {TreeLinker|*} node The existing node as reference, or null to insert at the end of the list
|
|
102
|
+
* @param {TreeLinker|*} newNode The new node to go before the existing node
|
|
103
|
+
* @returns {LinkedTreeList}
|
|
104
|
+
*/
|
|
105
|
+
insertBefore(node: TreeLinker | null, newNode: TreeLinker | any): LinkedTreeList;
|
|
106
|
+
/**
|
|
107
|
+
* Add a node (or data) after the given (or last) node in the list.
|
|
108
|
+
* @param {TreeLinker|*} node The new node to add to the end of the list
|
|
109
|
+
* @param {TreeLinker} after The existing last node
|
|
110
|
+
* @returns {TreeLinker}
|
|
111
|
+
*/
|
|
112
|
+
append(node: TreeLinker | any, after?: TreeLinker): LinkedTreeList;
|
|
113
|
+
/**
|
|
114
|
+
* Add a node (or data) before the given (or first) node in the list.
|
|
115
|
+
* @param {TreeLinker|*} node The new node to add to the start of the list
|
|
116
|
+
* @param {TreeLinker} before The existing first node
|
|
117
|
+
* @returns {TreeLinker}
|
|
118
|
+
*/
|
|
119
|
+
prepend(node: TreeLinker | any, before?: TreeLinker): LinkedTreeList;
|
|
120
|
+
/**
|
|
121
|
+
* Remove a linker from this linked list. The removed node no longer has a parent.
|
|
122
|
+
* @param {TreeLinker} node The node we wish to remove (and it will be returned after removal)
|
|
123
|
+
* @return {TreeLinker|null} The removed node, or null when there was nothing to remove
|
|
124
|
+
*/
|
|
125
|
+
remove(node: TreeLinker): TreeLinker | null;
|
|
126
|
+
/**
|
|
127
|
+
* Refresh all references (the head, the end and the length) by walking the list once, and return the head. The
|
|
128
|
+
* list's own methods keep these up to date, so this is only needed after linkers were changed directly.
|
|
129
|
+
* @return {TreeLinker}
|
|
130
|
+
*/
|
|
131
|
+
reset(): TreeLinker;
|
|
132
|
+
/**
|
|
133
|
+
* Retrieve a TreeLinker item from this list by numeric index, otherwise return null.
|
|
134
|
+
* @param {number} index The integer number for retrieving a node by position.
|
|
135
|
+
* @returns {TreeLinker|null}
|
|
136
|
+
*/
|
|
137
|
+
item(index: number): TreeLinker;
|
|
138
|
+
/**
|
|
139
|
+
* Be able to run forEach on this LinkedTreeList to iterate over the TreeLinker Items.
|
|
140
|
+
* @param {forEachCallback} callback The function to call for-each tree node
|
|
141
|
+
* @param {LinkedTreeList} thisArg Optional, 'this' reference
|
|
142
|
+
* @return {LinkedTreeList} The list which was iterated.
|
|
143
|
+
*/
|
|
144
|
+
forEach(callback: forEachCallback, thisArg?: LinkedTreeList): LinkedTreeList;
|
|
145
|
+
/**
|
|
146
|
+
* Be able to iterate over this class: the linkers of this list and everything below them (left-first). It stays within
|
|
147
|
+
* this list (it does not start at, or climb up to, the parents), use the parseTree service to parse a whole tree.
|
|
148
|
+
* @returns {Iterator}
|
|
149
|
+
*/
|
|
150
|
+
[Symbol.iterator](): Iterator<TreeLinker>;
|
|
151
|
+
/**
|
|
152
|
+
* Convert an array into a LinkedTreeList instance, return the new instance.
|
|
153
|
+
* @param {Array} [values=[]] An array of values which will be converted to nodes in this tree-list
|
|
154
|
+
* @param {TreeLinker} [linkerClass=TreeLinker] The class to use for each node
|
|
155
|
+
* @param {IsArrayable<TreeLinker>} [classType=LinkedTreeList] Provide the type of IsArrayable to use.
|
|
156
|
+
* @returns {LinkedTreeList}
|
|
157
|
+
*/
|
|
158
|
+
static fromArray: (values?: Array<any>, linkerClass?: typeof TreeLinker, classType?: any) => IsTree | any;
|
|
159
|
+
}
|
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
6
6
|
exports.LinkedTreeList = void 0
|
|
7
7
|
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
8
|
require('core-js/modules/esnext.iterator.for-each.js')
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const _TreeLinker = require('./TreeLinker')
|
|
10
|
+
const _TreeLinkerIterator = require('../../recipes/TreeLinkerIterator')
|
|
11
|
+
const _DoublyLinkedList = require('../doubly-linked-list/DoublyLinkedList')
|
|
12
12
|
/**
|
|
13
13
|
* @file doubly linked tree list.
|
|
14
14
|
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file doubly linked tree node.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.1.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
6
|
-
*/
|
|
7
|
-
import { IsArrayable } from '../../recipes/IsArrayable';
|
|
8
|
-
import { IsTreeNode } from '../../recipes/IsTreeNode';
|
|
9
|
-
import { IsTree } from '../../recipes/IsTree';
|
|
10
|
-
/**
|
|
11
|
-
* TreeLinker represents a node in a LinkedTreeList having a parent (or root) and child nodes.
|
|
12
|
-
* @extends DoubleLinker
|
|
13
|
-
*/
|
|
14
|
-
export declare class TreeLinker implements IsTreeNode {
|
|
15
|
-
/** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
|
|
16
|
-
readonly classType: typeof TreeLinker;
|
|
17
|
-
/** The data stored in this tree node. */
|
|
18
|
-
data: any;
|
|
19
|
-
/** The sibling after this node, or null when this is the last child. */
|
|
20
|
-
next: IsTreeNode | null;
|
|
21
|
-
/** The sibling before this node, or null when this is the first child. */
|
|
22
|
-
prev: IsTreeNode | null;
|
|
23
|
-
/** The node this node is a child of, or null for a root node. */
|
|
24
|
-
parent: IsTreeNode;
|
|
25
|
-
/** The list of the children of this node, or null when it has none. */
|
|
26
|
-
children: IsArrayable<IsTreeNode>;
|
|
27
|
-
/**
|
|
28
|
-
* Create the new TreeLinker instance, provide the data and optionally set references for next, prev, parent, or children.
|
|
29
|
-
* @param {Object} [settings={}] The settings for the new tree node.
|
|
30
|
-
* @param {*} [settings.data=null] The data to be stored in this tree node
|
|
31
|
-
* @param {TreeLinker} [settings.next=null] The reference to the next linker if any
|
|
32
|
-
* @param {TreeLinker} [settings.prev=null] The reference to the previous linker if any
|
|
33
|
-
* @param {LinkedTreeList} [settings.children=null] The references to child linkers if any
|
|
34
|
-
* @param {TreeLinker} [settings.parent=null] The reference to a parent linker if any
|
|
35
|
-
* @param {IsArrayable<IsTreeNode>} listClass Give the type of list to use for storing the children
|
|
36
|
-
*/
|
|
37
|
-
constructor({ data, next, prev, children, parent, listClass }?: {
|
|
38
|
-
data?: any;
|
|
39
|
-
next?: IsTreeNode;
|
|
40
|
-
prev?: IsTreeNode;
|
|
41
|
-
children?: Array<any>;
|
|
42
|
-
parent?: IsTreeNode;
|
|
43
|
-
listClass?: any;
|
|
44
|
-
});
|
|
45
|
-
/**
|
|
46
|
-
* Create the children for this tree from an array. Each child becomes a tree linker with this node as its parent: an
|
|
47
|
-
* existing linker is kept as it is, an object with a data property gives the settings of the linker, and anything
|
|
48
|
-
* else is the data of the linker.
|
|
49
|
-
* @param {Array|null} children Provide an array of data / linker references to be children of this tree node.
|
|
50
|
-
* @param {IsArrayable<IsTreeNode>} listClass Give the type of list to use for storing the children
|
|
51
|
-
* @return {LinkedTreeList|null}
|
|
52
|
-
*/
|
|
53
|
-
childrenFromArray(children?: Array<any> | null, listClass?: any): IsTree | any;
|
|
54
|
-
/**
|
|
55
|
-
* Make a new DoubleLinker from the data given if it is not already a valid Linker.
|
|
56
|
-
* @param {TreeLinker|*} linker Return a valid TreeLinker instance from given data, or even an already valid one.
|
|
57
|
-
* @param {IsTreeNode} [classType=TreeLinker] Provide the type of IsTreeNode to use.
|
|
58
|
-
* @return {TreeLinker}
|
|
59
|
-
*/
|
|
60
|
-
static make: (linker: TreeLinker | any, classType?: any) => IsTreeNode | any;
|
|
61
|
-
/**
|
|
62
|
-
* Convert an array into DoubleLinker instances, return the head and tail DoubleLinkers.
|
|
63
|
-
* @param {Array} [values=[]] Provide an array of data that will be converted to a chain of tree-linkers.
|
|
64
|
-
* @param {IsTreeNode} [classType=TreeLinker] Provide the type of IsTreeNode to use.
|
|
65
|
-
* @returns {{head: TreeLinker, tail: TreeLinker}}
|
|
66
|
-
*/
|
|
67
|
-
static fromArray: (values?: Array<any>, classType?: any) => {
|
|
68
|
-
head: TreeLinker | any;
|
|
69
|
-
tail: TreeLinker | any;
|
|
70
|
-
};
|
|
71
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @file doubly linked tree node.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.1.0
|
|
5
|
+
* @memberOf module:collect-your-stuff
|
|
6
|
+
*/
|
|
7
|
+
import { IsArrayable } from '../../recipes/IsArrayable';
|
|
8
|
+
import { IsTreeNode } from '../../recipes/IsTreeNode';
|
|
9
|
+
import { IsTree } from '../../recipes/IsTree';
|
|
10
|
+
/**
|
|
11
|
+
* TreeLinker represents a node in a LinkedTreeList having a parent (or root) and child nodes.
|
|
12
|
+
* @extends DoubleLinker
|
|
13
|
+
*/
|
|
14
|
+
export declare class TreeLinker implements IsTreeNode {
|
|
15
|
+
/** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
|
|
16
|
+
readonly classType: typeof TreeLinker;
|
|
17
|
+
/** The data stored in this tree node. */
|
|
18
|
+
data: any;
|
|
19
|
+
/** The sibling after this node, or null when this is the last child. */
|
|
20
|
+
next: IsTreeNode | null;
|
|
21
|
+
/** The sibling before this node, or null when this is the first child. */
|
|
22
|
+
prev: IsTreeNode | null;
|
|
23
|
+
/** The node this node is a child of, or null for a root node. */
|
|
24
|
+
parent: IsTreeNode;
|
|
25
|
+
/** The list of the children of this node, or null when it has none. */
|
|
26
|
+
children: IsArrayable<IsTreeNode>;
|
|
27
|
+
/**
|
|
28
|
+
* Create the new TreeLinker instance, provide the data and optionally set references for next, prev, parent, or children.
|
|
29
|
+
* @param {Object} [settings={}] The settings for the new tree node.
|
|
30
|
+
* @param {*} [settings.data=null] The data to be stored in this tree node
|
|
31
|
+
* @param {TreeLinker} [settings.next=null] The reference to the next linker if any
|
|
32
|
+
* @param {TreeLinker} [settings.prev=null] The reference to the previous linker if any
|
|
33
|
+
* @param {LinkedTreeList} [settings.children=null] The references to child linkers if any
|
|
34
|
+
* @param {TreeLinker} [settings.parent=null] The reference to a parent linker if any
|
|
35
|
+
* @param {IsArrayable<IsTreeNode>} listClass Give the type of list to use for storing the children
|
|
36
|
+
*/
|
|
37
|
+
constructor({ data, next, prev, children, parent, listClass }?: {
|
|
38
|
+
data?: any;
|
|
39
|
+
next?: IsTreeNode;
|
|
40
|
+
prev?: IsTreeNode;
|
|
41
|
+
children?: Array<any>;
|
|
42
|
+
parent?: IsTreeNode;
|
|
43
|
+
listClass?: any;
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Create the children for this tree from an array. Each child becomes a tree linker with this node as its parent: an
|
|
47
|
+
* existing linker is kept as it is, an object with a data property gives the settings of the linker, and anything
|
|
48
|
+
* else is the data of the linker.
|
|
49
|
+
* @param {Array|null} children Provide an array of data / linker references to be children of this tree node.
|
|
50
|
+
* @param {IsArrayable<IsTreeNode>} listClass Give the type of list to use for storing the children
|
|
51
|
+
* @return {LinkedTreeList|null}
|
|
52
|
+
*/
|
|
53
|
+
childrenFromArray(children?: Array<any> | null, listClass?: any): IsTree | any;
|
|
54
|
+
/**
|
|
55
|
+
* Make a new DoubleLinker from the data given if it is not already a valid Linker.
|
|
56
|
+
* @param {TreeLinker|*} linker Return a valid TreeLinker instance from given data, or even an already valid one.
|
|
57
|
+
* @param {IsTreeNode} [classType=TreeLinker] Provide the type of IsTreeNode to use.
|
|
58
|
+
* @return {TreeLinker}
|
|
59
|
+
*/
|
|
60
|
+
static make: (linker: TreeLinker | any, classType?: any) => IsTreeNode | any;
|
|
61
|
+
/**
|
|
62
|
+
* Convert an array into DoubleLinker instances, return the head and tail DoubleLinkers.
|
|
63
|
+
* @param {Array} [values=[]] Provide an array of data that will be converted to a chain of tree-linkers.
|
|
64
|
+
* @param {IsTreeNode} [classType=TreeLinker] Provide the type of IsTreeNode to use.
|
|
65
|
+
* @returns {{head: TreeLinker, tail: TreeLinker}}
|
|
66
|
+
*/
|
|
67
|
+
static fromArray: (values?: Array<any>, classType?: any) => {
|
|
68
|
+
head: TreeLinker | any;
|
|
69
|
+
tail: TreeLinker | any;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
6
6
|
exports.TreeLinker = void 0
|
|
7
7
|
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
8
|
require('core-js/modules/esnext.iterator.map.js')
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const _DoubleLinker = require('../doubly-linked-list/DoubleLinker')
|
|
10
|
+
const _LinkedTreeList = require('./LinkedTreeList')
|
|
11
11
|
/**
|
|
12
12
|
* TreeLinker represents a node in a LinkedTreeList having a parent (or root) and child nodes.
|
|
13
13
|
* @extends DoubleLinker
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import { Linker } from '../linked-list/Linker';
|
|
2
|
-
import { IsArrayable } from '../../recipes/IsArrayable';
|
|
3
|
-
import { IsQueue } from '../../recipes/IsQueue';
|
|
4
|
-
/**
|
|
5
|
-
* A first-in-first-out collection: items are added to the back with enqueue and taken from the front with dequeue.
|
|
6
|
-
* Any value can be queued (it is stored as it is, whether it is a function, an object or null), and adding and taking
|
|
7
|
-
* are constant time. To queue tasks which are run as they are taken use TaskQueue.
|
|
8
|
-
*/
|
|
9
|
-
export declare class Queue<T = any> implements IsQueue<T>, Iterable<T> {
|
|
10
|
-
/** The list which stores the queued items, the first is next to be dequeued. */
|
|
11
|
-
queuedList: IsArrayable<any>;
|
|
12
|
-
private readonly linkerClass;
|
|
13
|
-
/**
|
|
14
|
-
* Instantiate the queue, optionally with a list of items to start from.
|
|
15
|
-
* @param {IsArrayable|null} [queuedList=null] The list of linkers to start in this queue (the first is the front)
|
|
16
|
-
* @param {IsArrayable} [listClass=LinkedList] The type of list to create when no queued list is given
|
|
17
|
-
* @param {Linker} [linkerClass=Linker] The class used to hold each queued item
|
|
18
|
-
*/
|
|
19
|
-
constructor(queuedList?: IsArrayable<any> | null, listClass?: any, linkerClass?: typeof Linker);
|
|
20
|
-
/**
|
|
21
|
-
* Take the item from the front of the queue.
|
|
22
|
-
* @return {*|null} The item, or null when the queue is empty
|
|
23
|
-
*/
|
|
24
|
-
dequeue(): T | null;
|
|
25
|
-
/**
|
|
26
|
-
* Check whether the queue has no items.
|
|
27
|
-
* @return {boolean}
|
|
28
|
-
*/
|
|
29
|
-
empty(): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Add an item to the back of the queue.
|
|
32
|
-
* @param {*} data The item to add
|
|
33
|
-
* @return {Queue} This queue, so that adding can be chained
|
|
34
|
-
*/
|
|
35
|
-
enqueue(data: T): this;
|
|
36
|
-
/**
|
|
37
|
-
* Look at the item at the front of the queue, without removing it.
|
|
38
|
-
* @return {*|null} The item, or null when the queue is empty
|
|
39
|
-
*/
|
|
40
|
-
peek(): T | null;
|
|
41
|
-
/**
|
|
42
|
-
* Count the items in the queue.
|
|
43
|
-
* @return {number}
|
|
44
|
-
*/
|
|
45
|
-
size(): number;
|
|
46
|
-
/**
|
|
47
|
-
* Iterate over the items from the front of the queue to the back, without removing them.
|
|
48
|
-
* @return {Iterator}
|
|
49
|
-
*/
|
|
50
|
-
[Symbol.iterator](): Iterator<T>;
|
|
51
|
-
/**
|
|
52
|
-
* Convert an array to a Queue, the first value is at the front.
|
|
53
|
-
* @param {Array} [values=[]] The items to queue
|
|
54
|
-
* @param {IsArrayable} [listClass=LinkedList] The type of list used to store the items
|
|
55
|
-
* @param {Linker} [linkerClass=Linker] The class used to hold each queued item
|
|
56
|
-
* @returns {Queue}
|
|
57
|
-
*/
|
|
58
|
-
static fromArray: <T_1 = any>(values?: Array<T_1>, listClass?: any, linkerClass?: typeof Linker) => Queue<T_1>;
|
|
59
|
-
}
|
|
1
|
+
import { Linker } from '../linked-list/Linker';
|
|
2
|
+
import { IsArrayable } from '../../recipes/IsArrayable';
|
|
3
|
+
import { IsQueue } from '../../recipes/IsQueue';
|
|
4
|
+
/**
|
|
5
|
+
* A first-in-first-out collection: items are added to the back with enqueue and taken from the front with dequeue.
|
|
6
|
+
* Any value can be queued (it is stored as it is, whether it is a function, an object or null), and adding and taking
|
|
7
|
+
* are constant time. To queue tasks which are run as they are taken use TaskQueue.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Queue<T = any> implements IsQueue<T>, Iterable<T> {
|
|
10
|
+
/** The list which stores the queued items, the first is next to be dequeued. */
|
|
11
|
+
queuedList: IsArrayable<any>;
|
|
12
|
+
private readonly linkerClass;
|
|
13
|
+
/**
|
|
14
|
+
* Instantiate the queue, optionally with a list of items to start from.
|
|
15
|
+
* @param {IsArrayable|null} [queuedList=null] The list of linkers to start in this queue (the first is the front)
|
|
16
|
+
* @param {IsArrayable} [listClass=LinkedList] The type of list to create when no queued list is given
|
|
17
|
+
* @param {Linker} [linkerClass=Linker] The class used to hold each queued item
|
|
18
|
+
*/
|
|
19
|
+
constructor(queuedList?: IsArrayable<any> | null, listClass?: any, linkerClass?: typeof Linker);
|
|
20
|
+
/**
|
|
21
|
+
* Take the item from the front of the queue.
|
|
22
|
+
* @return {*|null} The item, or null when the queue is empty
|
|
23
|
+
*/
|
|
24
|
+
dequeue(): T | null;
|
|
25
|
+
/**
|
|
26
|
+
* Check whether the queue has no items.
|
|
27
|
+
* @return {boolean}
|
|
28
|
+
*/
|
|
29
|
+
empty(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Add an item to the back of the queue.
|
|
32
|
+
* @param {*} data The item to add
|
|
33
|
+
* @return {Queue} This queue, so that adding can be chained
|
|
34
|
+
*/
|
|
35
|
+
enqueue(data: T): this;
|
|
36
|
+
/**
|
|
37
|
+
* Look at the item at the front of the queue, without removing it.
|
|
38
|
+
* @return {*|null} The item, or null when the queue is empty
|
|
39
|
+
*/
|
|
40
|
+
peek(): T | null;
|
|
41
|
+
/**
|
|
42
|
+
* Count the items in the queue.
|
|
43
|
+
* @return {number}
|
|
44
|
+
*/
|
|
45
|
+
size(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Iterate over the items from the front of the queue to the back, without removing them.
|
|
48
|
+
* @return {Iterator}
|
|
49
|
+
*/
|
|
50
|
+
[Symbol.iterator](): Iterator<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Convert an array to a Queue, the first value is at the front.
|
|
53
|
+
* @param {Array} [values=[]] The items to queue
|
|
54
|
+
* @param {IsArrayable} [listClass=LinkedList] The type of list used to store the items
|
|
55
|
+
* @param {Linker} [linkerClass=Linker] The class used to hold each queued item
|
|
56
|
+
* @returns {Queue}
|
|
57
|
+
*/
|
|
58
|
+
static fromArray: <T_1 = any>(values?: Array<T_1>, listClass?: any, linkerClass?: typeof Linker) => Queue<T_1>;
|
|
59
|
+
}
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
6
6
|
exports.Queue = void 0
|
|
7
7
|
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
8
|
require('core-js/modules/esnext.iterator.for-each.js')
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const _LinkedList = require('../linked-list/LinkedList')
|
|
10
|
+
const _Linker = require('../linked-list/Linker')
|
|
11
11
|
/**
|
|
12
12
|
* @file queue
|
|
13
13
|
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
@@ -93,13 +93,15 @@ class Queue {
|
|
|
93
93
|
return {
|
|
94
94
|
next: () => {
|
|
95
95
|
const result = linkers.next()
|
|
96
|
-
return result.done
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
return result.done
|
|
97
|
+
? {
|
|
98
|
+
done: true,
|
|
99
|
+
value: undefined
|
|
100
|
+
}
|
|
101
|
+
: {
|
|
102
|
+
done: false,
|
|
103
|
+
value: result.value.data
|
|
104
|
+
}
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
}
|