collect-your-stuff
v2.1.2
Published
Use a variety of collections to collect your stuff when building code.
Maintainers
Readme
Collect your stuff (and go)!
Data allocation and manipulation.
Modules
Classes
Members
Constants
Functions
collect-your-stuff
All of the collections available.
Version: 1.0.0
Author: Joshua Heagle [email protected]
collect-your-stuff~collectYourStuff
All methods exported from this module are encapsulated within collect-your-stuff (this default export is the same set of classes as the named exports).
Kind: inner constant of collect-your-stuff
TreeLinkerIterator
Class TreeLinkerIterator returns the next value taking a left-first approach down a tree.
Kind: global class
- TreeLinkerIterator
- new TreeLinkerIterator(current, [boundaryParent])
- .next([value]) ⇒ IteratorResult.<IsTreeNode>
new TreeLinkerIterator(current, [boundaryParent])
Create an iterator starting at the given item.
| Param | Type | Description | | --- | --- | --- | | current | IsTreeNode | The item to start from. | | [boundaryParent] | IsTreeNode | null | The parent of the nodes to stay within (null for the top of a tree), the whole tree when not given. |
treeLinkerIterator.next([value]) ⇒ IteratorResult.<IsTreeNode>
Get the current item and move on to the following one (left-first, down each branch).
Kind: instance method of TreeLinkerIterator
Returns: IteratorResult.<IsTreeNode> - The current item, or done when there are no more.
| Param | Type | Description | | --- | --- | --- | | [value] | * | Not used, present to match the Iterator interface. |
Runnable
Identify a class that can be run.
Kind: global class
- Runnable
- new Runnable([data])
- instance
- static
- .isRunnable(thing) ⇒ boolean
new Runnable([data])
Instantiate a Runnable class.
| Param | Type | Default | Description | | --- | --- | --- | --- | | [data] | * | | The task (a function) or the data which the task returns. |
runnable.data
The task (or data) this runnable holds.
Kind: instance property of Runnable
runnable.task ⇒ function
Retrieve the data which should be formed as a task.
Kind: instance property of Runnable
runnable.run() ⇒ *
Run the runnable task.
Kind: instance method of Runnable
Runnable.isRunnable(thing) ⇒ boolean
Check if a given thing is Runnable
Kind: static method of Runnable
| Param | Type | Description | | --- | --- | --- | | thing | * | The value to check, or nothing to check whether this class is Runnable. |
LinkerIterator
Class LinkerIterator returns the next value when using linkers of linked type lists.
Kind: global class
- LinkerIterator
- new LinkerIterator(current)
- .next([value]) ⇒ IteratorResult.<IsLinker>
new LinkerIterator(current)
Create an iterator starting at the given item.
| Param | Type | Description | | --- | --- | --- | | current | IsLinker | The item to start from. |
linkerIterator.next([value]) ⇒ IteratorResult.<IsLinker>
Get the current item and move on to the following one.
Kind: instance method of LinkerIterator
Returns: IteratorResult.<IsLinker> - The current item, or done when there are no more.
| Param | Type | Description | | --- | --- | --- | | [value] | * | Not used, present to match the Iterator interface. |
DoubleLinkerIterator
Class DoubleLinkerIterator returns the next value when using linkers of linked type lists.
Kind: global class
- DoubleLinkerIterator
- new DoubleLinkerIterator(current)
- .next([value]) ⇒ IteratorResult.<IsDoubleLinker>
new DoubleLinkerIterator(current)
Create an iterator starting at the given item.
| Param | Type | Description | | --- | --- | --- | | current | IsDoubleLinker | The item to start from. |
doubleLinkerIterator.next([value]) ⇒ IteratorResult.<IsDoubleLinker>
Get the current item and move on to the following one.
Kind: instance method of DoubleLinkerIterator
Returns: IteratorResult.<IsDoubleLinker> - The current item, or done when there are no more.
| Param | Type | Description | | --- | --- | --- | | [value] | * | Not used, present to match the Iterator interface. |
ArrayIterator
Class ArrayIterator returns the next value when using elements of array type list.
Kind: global class
- ArrayIterator
- new ArrayIterator(innerList, [index])
- .next([value]) ⇒ IteratorResult.<IsElement>
new ArrayIterator(innerList, [index])
Create an iterator over the given array.
| Param | Type | Default | Description | | --- | --- | --- | --- | | innerList | Array.<IsElement> | | The elements to iterate over. | | [index] | number | 0 | The position to start from. |
arrayIterator.next([value]) ⇒ IteratorResult.<IsElement>
Get the next element, moving the iterator forward.
Kind: instance method of ArrayIterator
Returns: IteratorResult.<IsElement> - The next element, or done when there are no more.
| Param | Type | Description | | --- | --- | --- | | [value] | * | Not used, present to match the Iterator interface. |
TaskStack
Store a collection of tasks (Stackables) which can only be inserted and removed from the top: pop() takes the task from the top and RUNS it. For a plain last-in-first-out collection of items use Stack.
Kind: global class
- TaskStack
- new TaskStack([stackedList], [listClass], [stackableClass])
- .empty() ⇒ boolean
- .top() ⇒ Stackable
- .pop() ⇒ Stackable | null
- .push(stackable)
- .remove() ⇒ Stackable | null
- .size() ⇒ number
new TaskStack([stackedList], [listClass], [stackableClass])
Instantiate the state with the starter stacked list.
| Param | Type | Default | Description | | --- | --- | --- | --- | | [stackedList] | Iterable | LinkedList | | The list of stackables to start in this stack. | | [listClass] | IsArrayable | LinkedList | The type of list to create when no stacked list is given. | | [stackableClass] | Stackable | Stackable | The class used to wrap stacked items. |
taskStack.empty() ⇒ boolean
Return true if the stack is empty (there are no tasks in the stacked list)
Kind: instance method of TaskStack
taskStack.top() ⇒ Stackable
Take a look at the next stacked task
Kind: instance method of TaskStack
taskStack.pop() ⇒ Stackable | null
Remove the next stacked task and return it.
Kind: instance method of TaskStack
taskStack.push(stackable)
Push a stackable task to the top of the stack.
Kind: instance method of TaskStack
| Param | Type | Description | | --- | --- | --- | | stackable | Stackable | * | Add a new stackable to the top of the stack |
taskStack.remove() ⇒ Stackable | null
Remove the next stacked task and return it.
Kind: instance method of TaskStack
taskStack.size() ⇒ number
Get the size of the current stack.
Kind: instance method of TaskStack
Stackable ⇐ Linker
Stackable represents a runnable entry in stack.
Kind: global class
Extends: Linker
- Stackable ⇐ Linker
- new Stackable([stackData])
- instance
- .data
- .next
- .task ⇒ *
- .classType
- .run() ⇒ *
- static
- .fromArray([values], [classType]) ⇒ Object
new Stackable([stackData])
Create a stackable item that can be used in a stack.
| Param | Type | Default | Description | | --- | --- | --- | --- | | [stackData] | Object | {} | The settings for the new stackable. | | [stackData.task] | * | | The data to be stored in this stackable | | [stackData.next] | Stackable | null | | The reference to the next stackable if any | | [stackData.ready] | boolean | function | false | Indicate if the stackable is ready to run |
stackable.data
The task (or data) this stackable holds.
Kind: instance property of Stackable
Overrides: data
stackable.next
The stackable below this one, or null when this is the bottom.
Kind: instance property of Stackable
Overrides: next
stackable.task ⇒ *
Retrieve the data which should be formed as a task.
Kind: instance property of Stackable
stackable.classType
The class used to create this instance, so that it can be recognized as valid without an instanceof check.
Kind: instance property of Stackable
Overrides: classType
stackable.run() ⇒ *
Run the stacked task.
Kind: instance method of Stackable
Stackable.fromArray([values], [classType]) ⇒ Object
Convert an array into Stackable instances, return the head and tail Stackables.
Kind: static method of Stackable
| Param | Type | Default | Description | | --- | --- | --- | --- | | [values] | Array | [] | Provide an array of data that will be converted to a chain of stackable linkers. | | [classType] | IsLinker | Stackable | Provide the type of IsLinker to use. |
Stack
A last-in-first-out collection: items are added to the top with push and taken from the top with pop. Any value can be stacked (it is stored as it is, whether it is a function, an object or null), and adding and taking are constant time. To stack tasks which are run as they are taken use TaskStack.
Kind: global class
- Stack
- new Stack([stackedList], [listClass], [linkerClass])
- .empty() ⇒ boolean
- .peek() ⇒ * | null
- .pop() ⇒ * | null
- .push(data) ⇒ Stack
- .size() ⇒ number
- .top() ⇒ * | null
new Stack([stackedList], [listClass], [linkerClass])
Instantiate the stack, optionally with a list of items to start from.
| Param | Type | Default | Description | | --- | --- | --- | --- | | [stackedList] | IsArrayable | null | | The list of linkers to start in this stack (the first is the top) | | [listClass] | IsArrayable | LinkedList | The type of list to create when no stacked list is given | | [linkerClass] | Linker | Linker | The class used to hold each stacked item |
stack.empty() ⇒ boolean
Check whether the stack has no items.
Kind: instance method of Stack
stack.peek() ⇒ * | null
Look at the item on the top of the stack, without removing it.
Kind: instance method of Stack
Returns: * | null - The item, or null when the stack is empty
stack.pop() ⇒ * | null
Take the item from the top of the stack.
Kind: instance method of Stack
Returns: * | null - The item, or null when the stack is empty
stack.push(data) ⇒ Stack
Add an item to the top of the stack.
Kind: instance method of Stack
Returns: Stack - This stack, so that adding can be chained
| Param | Type | Description | | --- | --- | --- | | data | * | The item to add |
stack.size() ⇒ number
Count the items in the stack.
Kind: instance method of Stack
stack.top() ⇒ * | null
The item on the top of the stack (the same as peek).
Kind: instance method of Stack
Returns: * | null - The item, or null when the stack is empty
TaskQueue
Maintain a series of queued tasks (Queueables): dequeue() takes the next task from the front and RUNS it, giving each task in turn a chance to run (a task which is not ready, or which has not finished, is placed at the back again). This is a task scheduler, for a plain first-in-first-out collection of items use Queue.
Kind: global class
- TaskQueue
- new TaskQueue(queuedList, [listClass], [queueableClass])
- .dequeue() ⇒ completeResponse | *
- .empty() ⇒ boolean
- .enqueue(queueable)
- .peek() ⇒ Queueable
- .remove() ⇒ Queueable | null
- .size() ⇒ number
new TaskQueue(queuedList, [listClass], [queueableClass])
Instantiate the queue with the given queue list.
| Param | Type | Default | Description | | --- | --- | --- | --- | | queuedList | Iterable | LinkedList | | Give the list of queueables to start in this queue. | | [listClass] | IsArrayable | LinkedList | The type of list to create when no queued list is given. | | [queueableClass] | Queueable | Queueable | The class used to wrap queued items. |
taskQueue.dequeue() ⇒ completeResponse | *
Take a queued task from the front of the queue and run it if ready. A task which is not ready yet is kept in the queue (never dropped), a task which is still running is reported as blocking and left to finish on its own, and completed tasks are discarded.
Kind: instance method of TaskQueue
taskQueue.empty() ⇒ boolean
Return true if the queue is empty (there are no tasks in the queue list)
Kind: instance method of TaskQueue
taskQueue.enqueue(queueable)
Add a queued task to the end of the queue
Kind: instance method of TaskQueue
| Param | Type | Description | | --- | --- | --- | | queueable | Queueable | Add a new queueable to the end of the queue |
taskQueue.peek() ⇒ Queueable
Take a look at the next queued task
Kind: instance method of TaskQueue
taskQueue.remove() ⇒ Queueable | null
Remove the next queued item and return it.
Kind: instance method of TaskQueue
taskQueue.size() ⇒ number
Get the length of the current queue.
Kind: instance method of TaskQueue
Queueable ⇐ Linker
Queueable represents a runnable entry in a queue.
Kind: global class
Extends: Linker
- Queueable ⇐ Linker
- new Queueable([queueableData])
- instance
- .data
- .next
- .complete
- .ready
- .running
- .isReady ⇒ boolean
- .task ⇒ *
- .classType
- .markCompleted([completeResponse]) ⇒ completeResponse
- .run() ⇒ completeResponse
- static
- .fromArray(values, [classType]) ⇒ Object
new Queueable([queueableData])
Create a queueable item that can be used in a queue.
| Param | Type | Default | Description | | --- | --- | --- | --- | | [queueableData] | Object | {} | The settings for the new queueable. | | [queueableData.task] | * | | The data to be stored in this queueable | | [queueableData.next] | Queueable | null | | The reference to the next queueable if any | | [queueableData.ready] | boolean | function | false | Indicate if the queueable is ready to run |
queueable.data
The task (or data) this queueable holds.
Kind: instance property of Queueable
Overrides: data
queueable.next
The queueable after this one, or null when this is the last.
Kind: instance property of Queueable
Overrides: next
queueable.complete
Whether this queueable has been run to completion.
Kind: instance property of Queueable
queueable.ready
Whether this queueable may run, or a function which answers that when asked.
Kind: instance property of Queueable
queueable.running
Whether this queueable is running right now.
Kind: instance property of Queueable
queueable.isReady ⇒ boolean
Check ready state.
Kind: instance property of Queueable
queueable.task ⇒ *
Retrieve the data which should be formed as a task.
Kind: instance property of Queueable
queueable.classType
The class used to create this instance, so that it can be recognized as valid without an instanceof check.
Kind: instance property of Queueable
Overrides: classType
queueable.markCompleted([completeResponse]) ⇒ completeResponse
Set this queueable as completed.
Kind: instance method of Queueable
| Param | Type | Default | Description | | --- | --- | --- | --- | | [completeResponse] | Object | {} | The result to report for the task. | | [completeResponse.success] | * | true | Indicate when the task failed (use false) or give a success message | | [completeResponse.error] | * | false | Indicate a task was error-free (use false) or give an error message | | [completeResponse.context] | * | | Provide additional data in the response |
queueable.run() ⇒ completeResponse
Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
Kind: instance method of Queueable
Queueable.fromArray(values, [classType]) ⇒ Object
Convert an array into Queueable instances, return the head and tail Queueables.
Kind: static method of Queueable
| Param | Type | Default | Description | | --- | --- | --- | --- | | values | Array | | Provide an array of data that will be converted to a chain of queueable linkers. | | [classType] | IsLinker | Queueable | Provide the type of IsLinker to use. |
Queue
A first-in-first-out collection: items are added to the back with enqueue and taken from the front with dequeue. Any value can be queued (it is stored as it is, whether it is a function, an object or null), and adding and taking are constant time. To queue tasks which are run as they are taken use TaskQueue.
Kind: global class
- Queue
- new Queue([queuedList], [listClass], [linkerClass])
- .dequeue() ⇒ * | null
- .empty() ⇒ boolean
- .enqueue(data) ⇒ Queue
- .peek() ⇒ * | null
- .size() ⇒ number
new Queue([queuedList], [listClass], [linkerClass])
Instantiate the queue, optionally with a list of items to start from.
| Param | Type | Default | Description | | --- | --- | --- | --- | | [queuedList] | IsArrayable | null | | The list of linkers to start in this queue (the first is the front) | | [listClass] | IsArrayable | LinkedList | The type of list to create when no queued list is given | | [linkerClass] | Linker | Linker | The class used to hold each queued item |
queue.dequeue() ⇒ * | null
Take the item from the front of the queue.
Kind: instance method of Queue
Returns: * | null - The item, or null when the queue is empty
queue.empty() ⇒ boolean
Check whether the queue has no items.
Kind: instance method of Queue
queue.enqueue(data) ⇒ Queue
Add an item to the back of the queue.
Kind: instance method of Queue
Returns: Queue - This queue, so that adding can be chained
| Param | Type | Description | | --- | --- | --- | | data | * | The item to add |
queue.peek() ⇒ * | null
Look at the item at the front of the queue, without removing it.
Kind: instance method of Queue
Returns: * | null - The item, or null when the queue is empty
queue.size() ⇒ number
Count the items in the queue.
Kind: instance method of Queue
TreeLinker ⇐ DoubleLinker
TreeLinker represents a node in a LinkedTreeList having a parent (or root) and child nodes.
Kind: global class
Extends: DoubleLinker
new TreeLinker([settings], listClass)
Create the new TreeLinker instance, provide the data and optionally set references for next, prev, parent, or children.
| Param | Type | Default | Description | | --- | --- | --- | --- | | [settings] | Object | {} | The settings for the new tree node. | | [settings.data] | * | | The data to be stored in this tree node | | [settings.next] | TreeLinker | | The reference to the next linker if any | | [settings.prev] | TreeLinker | | The reference to the previous linker if any | | [settings.children] | LinkedTreeList | | The references to child linkers if any | | [settings.parent] | TreeLinker | | The reference to a parent linker if any | | listClass | IsArrayable.<IsTreeNode> | | Give the type of list to use for storing the children |
treeLinker.classType
The class used to create this instance, so that it can be recognized as valid without an instanceof check.
Kind: instance property of TreeLinker
Overrides: classType
treeLinker.data
The data stored in this tree node.
Kind: instance property of TreeLinker
Overrides: data
treeLinker.next
The sibling after this node, or null when this is the last child.
Kind: instance property of TreeLinker
Overrides: next
treeLinker.prev
The sibling before this node, or null when this is the first child.
Kind: instance property of TreeLinker
Overrides: prev
treeLinker.parent
The node this node is a child of, or null for a root node.
Kind: instance property of TreeLinker
treeLinker.children
The list of the children of this node, or null when it has none.
Kind: instance property of TreeLinker
treeLinker.childrenFromArray(children, listClass) ⇒ LinkedTreeList | null
Create the children for this tree from an array. Each child becomes a tree linker with this node as its parent: an existing linker is kept as it is, an object with a data property gives the settings of the linker, and anything else is the data of the linker.
Kind: instance method of TreeLinker
| Param | Type | Default | Description | | --- | --- | --- | --- | | children | Array | null | | Provide an array of data / linker references to be children of this tree node. | | listClass | IsArrayable.<IsTreeNode> | | Give the type of list to use for storing the children |
TreeLinker.fromArray([values], [classType]) ⇒ Object
Convert an array into DoubleLinker instances, return the head and tail DoubleLinkers.
Kind: static method of TreeLinker
| Param | Type | Default | Description | | --- | --- | --- | --- | | [values] | Array | [] | Provide an array of data that will be converted to a chain of tree-linkers. | | [classType] | IsTreeNode | TreeLinker | Provide the type of IsTreeNode to use. |
LinkedTreeList ⇐ DoublyLinkedList
LinkedTreeList represents a collection stored with a root and spreading in branching (tree) formation.
Kind: global class
Extends: DoublyLinkedList
- LinkedTreeList ⇐ DoublyLinkedList
- new LinkedTreeList([linkerClass])
- .classType
- .innerList
- .initialized
- .tailCache
- .countCache
- .ownerNode
- .list ⇒ TreeLinker
- .first ⇒ TreeLinker
- .last ⇒ TreeLinker
- .length ⇒ number
- .parent ⇒ TreeLinker | null
- .parent
- .rootParent ⇒ TreeLinker
- .initialize(initialList) ⇒ LinkedTreeList
- .setChildren(item, [children])
- .adopt(newNode) ⇒ TreeLinker
- .insertAfter(node, newNode) ⇒ LinkedTreeList
- .insertBefore(node, newNode) ⇒ LinkedTreeList
- .append(node, after) ⇒ TreeLinker
- .prepend(node, before) ⇒ TreeLinker
- .remove(node) ⇒ TreeLinker | null
- .reset() ⇒ TreeLinker
- .item(index) ⇒ TreeLinker | null
- .forEach(callback, thisArg) ⇒ LinkedTreeList
- .indexOfElement(node) ⇒ number
new LinkedTreeList([linkerClass])
Create the new LinkedTreeList instance, configure the list class.
| Param | Type | Default | Description | | --- | --- | --- | --- | | [linkerClass] | TreeLinker | TreeLinker | The class used to wrap given data as tree linkers. |
linkedTreeList.classType
The class used to create this instance, so that it can be recognized as valid without an instanceof check.
Kind: instance property of LinkedTreeList
Overrides: classType
linkedTreeList.innerList
A linker of the list (null when the list is empty); the head is found by walking back from it.
Kind: instance property of LinkedTreeList
Overrides: innerList
linkedTreeList.initialized
Whether the inner list has been initialized (it can only be initialized once).
Kind: instance property of LinkedTreeList
Overrides: initialized
linkedTreeList.tailCache
The last linker, remembered so that adding to the end does not need to walk the whole list (null when not known yet).
Kind: instance property of LinkedTreeList
Overrides: tailCache
linkedTreeList.countCache
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).
Kind: instance property of LinkedTreeList
Overrides: countCache
linkedTreeList.ownerNode
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).
Kind: instance property of LinkedTreeList
linkedTreeList.list ⇒ TreeLinker
Retrieve the innerList used (the list itself, not a copy).
Kind: instance property of LinkedTreeList
Overrides: list
linkedTreeList.first ⇒ TreeLinker
Retrieve the first TreeLinker in the list.
Kind: instance property of LinkedTreeList
Overrides: first
linkedTreeList.last ⇒ TreeLinker
Retrieve the last TreeLinker in the list. The end is remembered, so this does not walk the list.
Kind: instance property of LinkedTreeList
Overrides: last
linkedTreeList.length ⇒ number
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 (call reset() after linkers were changed directly).
Kind: instance property of LinkedTreeList
Overrides: length
linkedTreeList.parent ⇒ TreeLinker | null
Get the parent of this tree list: the node these linkers are the children of (remembered even while the list is empty), or null for the linkers at the top of a tree.
Kind: instance property of LinkedTreeList
linkedTreeList.parent
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 children. Linkers added to the list later get this parent too.
Kind: instance property of LinkedTreeList
| Param | Type | Description | | --- | --- | --- | | parent | TreeLinker | null | The new node to use as the parent for this group of children |
linkedTreeList.rootParent ⇒ TreeLinker
Return the root parent of the entire tree.
Kind: instance property of LinkedTreeList
linkedTreeList.initialize(initialList) ⇒ LinkedTreeList
Initialize the inner list, should only run once.
Kind: instance method of LinkedTreeList
Overrides: initialize
| Param | Type | Description | | --- | --- | --- | | initialList | TreeLinker | Give the list of tree-linkers to start in this linked-tree-list. |
linkedTreeList.setChildren(item, [children])
Set the children on a parent item.
Kind: instance method of LinkedTreeList
Throws:
- Error When the item is not one of the linkers of this list
| Param | Type | Default | Description | | --- | --- | --- | --- | | item | TreeLinker | | The TreeLinker node (one of the linkers of this list) that will be the parent of the children | | [children] | LinkedTreeList | null | | The LinkedTreeList which has the child nodes to use, or null to remove the children of the item |
linkedTreeList.adopt(newNode) ⇒ TreeLinker
Make a linker of the given node (or data) and make this list's parent its parent.
Kind: instance method of LinkedTreeList
| Param | Type | Description | | --- | --- | --- | | newNode | TreeLinker | * | The node (or data) which is being added to this list |
linkedTreeList.insertAfter(node, newNode) ⇒ LinkedTreeList
Insert a new node (or data) after a node. The new node gets the parent of this list.
Kind: instance method of LinkedTreeList
Overrides: insertAfter
| Param | Type | Description | | --- | --- | --- | | node | TreeLinker | * | The existing node as reference, or null to insert at the start of the list | | newNode | TreeLinker | * | The new node to go after the existing node |
linkedTreeList.insertBefore(node, newNode) ⇒ LinkedTreeList
Insert a new node (or data) before a node. The new node gets the parent of this list.
Kind: instance method of LinkedTreeList
Overrides: insertBefore
| Param | Type | Description | | --- | --- | --- | | node | TreeLinker | * | The existing node as reference, or null to insert at the end of the list | | newNode | TreeLinker | * | The new node to go before the existing node |
linkedTreeList.append(node, after) ⇒ TreeLinker
Add a node (or data) after the given (or last) node in the list.
Kind: instance method of LinkedTreeList
Overrides: append
| Param | Type | Description | | --- | --- | --- | | node | TreeLinker | * | The new node to add to the end of the list | | after | TreeLinker | The existing last node |
linkedTreeList.prepend(node, before) ⇒ TreeLinker
Add a node (or data) before the given (or first) node in the list.
Kind: instance method of LinkedTreeList
Overrides: prepend
| Param | Type | Description | | --- | --- | --- | | node | TreeLinker | * | The new node to add to the start of the list | | before | TreeLinker | The existing first node |
linkedTreeList.remove(node) ⇒ TreeLinker | null
Remove a linker from this linked list. The removed node no longer has a parent.
Kind: instance method of LinkedTreeList
Overrides: remove
Returns: TreeLinker | null - The removed node, or null when there was nothing to remove
| Param | Type | Description | | --- | --- | --- | | node | TreeLinker | The node we wish to remove (and it will be returned after removal) |
linkedTreeList.reset() ⇒ TreeLinker
Refresh all references (the head, the end and the length) by walking the list once, and return the head. The list's own methods keep these up to date, so this is only needed after linkers were changed directly.
Kind: instance method of LinkedTreeList
Overrides: reset
linkedTreeList.item(index) ⇒ TreeLinker | null
Retrieve a TreeLinker item from this list by numeric index, otherwise return null.
Kind: instance method of LinkedTreeList
Overrides: item
| Param | Type | Description | | --- | --- | --- | | index | number | The integer number for retrieving a node by position. |
linkedTreeList.forEach(callback, thisArg) ⇒ LinkedTreeList
Be able to run forEach on this LinkedTreeList to iterate over the TreeLinker Items.
Kind: instance method of LinkedTreeList
Overrides: forEach
Returns: LinkedTreeList - The list which was iterated.
| Param | Type | Description | | --- | --- | --- | | callback | forEachCallback | The function to call for-each tree node | | thisArg | LinkedTreeList | Optional, 'this' reference |
linkedTreeList.indexOfElement(node) ⇒ number
Find the position of an element which must be in this list.
Kind: instance method of LinkedTreeList
Overrides: indexOfElement
Throws:
- Error When the element is not in this list
| Param | Type | Description | | --- | --- | --- | | node | ArrayElement | The element to find |
Linker ⇐ ArrayElement
Linker represents a node in a LinkedList.
Kind: global class
Extends: ArrayElement
- Linker ⇐ ArrayElement
- new Linker([nodeData])
- instance
- static
- .fromArray([values], [classType]) ⇒ Object
new Linker([nodeData])
Create the new Linker instance, provide the data and optionally give the next Linker.
| Param | Type | Default | Description | | --- | --- | --- | --- | | [nodeData] | Object | {} | The settings for the new linker. | | [nodeData.data] | * | | The data to be stored in this linker | | [nodeData.next] | Linker | null | | The reference to the next linker if any |
linker.classType
The class used to create this instance, so that it can be recognized as valid without an instanceof check.
Kind: instance property of Linker
Overrides: classType
linker.data
The data stored in this linker.
Kind: instance property of Linker
Overrides: data
linker.next
The linker after this one, or null when this is the last.
Kind: instance property of Linker
Linker.fromArray([values], [classType]) ⇒ Object
Convert an array into Linker instances, return the head and tail Linkers.
Kind: static method of Linker
| Param | Type | Default | Description | | --- | --- | --- | --- | | [values] | Array | [] | Provide an array of data that will be converted to a chain of linkers. | | [classType] | IsLinker | Linker | Provide the type of IsLinker to use. |
LinkedList ⇐ Arrayable
LinkedList represents a collection stored as a LinkedList with next references.
Kind: global class
Extends: Arrayable
- LinkedList ⇐ Arrayable
- new LinkedList([linkerClass])
- .classType
- .innerList
- .initialized
- .tailCache
- .countCache
- .list ⇒ Linker
- .first ⇒ Linker
- .last ⇒ Linker
- .length ⇒ number
- .initialize(initialList) ⇒ LinkedList
- .insertAfter(node, newNode) ⇒ LinkedList
- .insertBefore(node, newNode) ⇒ LinkedList
- .append(node, after) ⇒ Linker
- .prepend(node, before) ⇒ Linker
- .remove(node) ⇒ Linker | null
- .reset() ⇒ Linker | null
- .item(index) ⇒ Linker | null
- .forEach(callback, thisArg) ⇒ LinkedList
- .indexOfElement(node) ⇒ number
new LinkedList([linkerClass])
Create the new LinkedList instance.
| Param | Type | Default | Description | | --- | --- | --- | --- | | [linkerClass] | Linker | Linker | The class used to wrap given data as linkers. |
linkedList.classType
The class used to create this instance, so that it can be recognized as valid without an instanceof check.
Kind: instance property of LinkedList
Overrides: classType
linkedList.innerList
The first linker of the list (null when the list is empty), from which the whole list is reached.
Kind: instance property of LinkedList
Overrides: innerList
linkedList.initialized
Whether the inner list has been initialized (it can only be initialized once).
Kind: instance property of LinkedList
Overrides: initialized
linkedList.tailCache
The last linker, remembered so that adding to the end does not need to walk the whole list (null when not known yet).
Kind: instance property of LinkedList
linkedList.countCache
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).
Kind: instance property of LinkedList
linkedList.list ⇒ Linker
Retrieve the innerList used (the list itself, not a copy).
Kind: instance property of LinkedList
Overrides: list
linkedList.first ⇒ Linker
Retrieve the first Linker in the list.
Kind: instance property of LinkedList
Overrides: first
linkedList.last ⇒ Linker
Retrieve the last Linker in the list. The end is remembered, so this does not walk the list.
Kind: instance property of LinkedList
Overrides: last
linkedList.length ⇒ number
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 (call reset() after linkers were changed directly).
Kind: instance property of LinkedList
Overrides: length
linkedList.initialize(initialList) ⇒ LinkedList
Initialize the inner list, should only run once.
Kind: instance method of LinkedList
Overrides: initialize
| Param | Type | Description | | --- | --- | --- | | initialList | Linker | Array | Give the list of linkers to start in this linked-list. |
linkedList.insertAfter(node, newNode) ⇒ LinkedList
Insert a new node (or data) after a node.
Kind: instance method of LinkedList
Overrides: insertAfter
| Param | Type | Description | | --- | --- | --- | | node | Linker | * | The existing node as reference, or null to insert at the start of the list | | newNode | Linker | * | The new node to go after the existing node |
linkedList.insertBefore(node, newNode) ⇒ LinkedList
Insert a new node (or data) before a node.
Kind: instance method of LinkedList
Overrides: insertBefore
Throws:
- Error When the reference node is not in this list
| Param | Type | Description | | --- | --- | --- | | node | Linker | * | The existing node as reference, or null to insert at the end of the list | | newNode | Linker | * | The new node to go before the existing node |
linkedList.append(node, after) ⇒ Linker
Add a node (or data) after the given (or last) node in the list.
Kind: instance method of LinkedList
Overrides: append
| Param | Type | Description | | --- | --- | --- | | node | Linker | * | The new node to add to the end of the list | | after | Linker | The existing last node |
linkedList.prepend(node, before) ⇒ Linker
Add a node (or data) before the given (or first) node in the list.
Kind: instance method of LinkedList
Overrides: prepend
| Param | Type | Description | | --- | --- | --- | | node | Linker | * | The new node to add to the start of the list | | before | Linker | The existing first node |
linkedList.remove(node) ⇒ Linker | null
Remove a linker from this linked list.
Kind: instance method of LinkedList
Overrides: remove
Returns: Linker | null - The removed node, or null when it was not in this list (nothing is removed)
| Param | Type | Description | | --- | --- | --- | | node | Linker | The node we wish to remove (and it will be returned after removal) |
linkedList.reset() ⇒ Linker | null
Refresh the remembered end and length of the list by walking it once. The list's own methods keep these up to date, so this is only needed af
