standard-data-structures
Version:
A collection of standard data-structures for node and browser
86 lines (85 loc) • 2.11 kB
TypeScript
import { Option } from '../immutable/option';
import { ICollection } from '../internals/iCollection';
/**
* A node for the linked list
*/
export declare class LinkedListNode<T> {
readonly value: T;
/**
* Left Node
*/
left: LinkedListNode<T> | undefined;
/**
* Right Node
*/
right: LinkedListNode<T> | undefined;
constructor(value: T);
}
/**
* A doubly linked list
*/
export declare class DoublyLinkedList<T> implements ICollection<T> {
/**
* Converts the doubly linked list into an array
*/
readonly asArray: T[];
/**
* Returns the first element of the list
*/
readonly head: T | undefined;
/**
* Returns true if the list is empty
*/
readonly isEmpty: boolean;
/**
* Returns the last element in the list
*/
readonly tail: T | undefined;
/**
* Creates a new DoublyLinkedList with the provided values.
*/
static of<A = never>(...t: A[]): DoublyLinkedList<A>;
/**
* Returns the size of the linked list
*/
length: number;
private headN;
private tailN;
private constructor();
/**
* Adds a new value to the list
*/
add(val: T): LinkedListNode<T>;
/**
* Cleans removes all the elements from the list
*/
empty(): void;
/**
* Refer [[ICollection.filter]]
*/
filter(F: (A: T) => boolean): ICollection<T>;
/**
* Converts the linked list into a value
*/
fold<C>(seed: C, f: (value: T, seed: C) => C): C;
/**
* Tests if the provided node is a part of the list or not in O(n) time complexity.
*/
isConnected(n: LinkedListNode<T>): boolean;
/**
* Transforms the values inside the list using the transformer function, creating a new list.
*/
map<B>(ab: (a: T) => B): ICollection<B>;
/**
* Removes the last inserted element
*/
pop(): Option<T>;
/**
* Removes the provided node from the list.
*/
remove(n: LinkedListNode<T>): void;
/**
* Remove the first element from the list
*/
shift(): Option<T>;
}