dubc-ds-deque
v1.0.0
Published
Observable deque (linked list).
Readme
dubc-ds-deque
An observable deque (doubly-linked list.)
Constructor
constructor()Creates an empty deque. To pre-populate a deque, you can use the static
of method:
import { Deque } from "dubc-ds-deque"
const d = Deque.of("1", "2", "3")Properties
.first O(log n)
Returns the first value in the deque, or undefined if the deque
is empty.
.i O(1)
Returns an iterator over the values in the deque.
.last O(log n)
Returns the last value in the deque, or undefined if the deque
is empty.
.only O(1)
Returns the only value in the deque. If the deque doesn't have
exactly one element, throws an Error.
.size O(1)
Returns the number of values in the deque.
Methods
.clear() O(1)
Removes all values from the deque.
.hear(f:(event:DSEvent<T>)) O(1)
Adds a listener to the deque. Any time the deque changes (and only when the deque actually changes), the listener function will be called.
Returns a number that can be sent to unhear to stop receiving events.
.pop()
Removes the last value from the deque and returns it.
Returns undefined if the deque is empty.
.push(value:T) O(1)
Adds a value to the end of the deque.
.replace(i:Iterable<T>) O(k)
Replaces the content of this deque with new values.
.reversed() O(1)
Returns an iterable iterator over the values in the deque, in reverse sort order.
.shift() O(1)
Removes the first value from the deque and returns it.
Returns undefined if the deque is empty.
.unhear(n:number) O(1)
Removes the listener registered with the specified number.
.unshift(v:T) O(1)
Adds a value to the beginning of the deque.
Operations by Kind
Listeners
hear(eventHandler)get events when the deque changesunhear(n)stop listening for changes
Iterators
Dequeitself is an iterable, so you can use it directly infor...ofito get an iteratorreversed()to iterate backwards
Values
firstget the first valuelastget the last valueonlyget the only valuesizeget the number of values
Changing
popremove the last valuepushadd a value to the endshiftremove the first valueunshiftadd a value to the beginning
Bulk
clearremove all valuesreplace(values)clear the deque then add many values
