typescript-collections
Version:
A complete, fully tested data structure library written in TypeScript.
82 lines (81 loc) • 3.47 kB
TypeScript
import { default as Dictionary } from './Dictionary';
export default class LinkedDictionary<K, V> extends Dictionary<K, V> {
private head;
private tail;
constructor(toStrFunction?: (key: K) => string);
/**
* Inserts the new node to the 'tail' of the list, updating the
* neighbors, and moving 'this.tail' (the End of List indicator) that
* to the end.
*/
private appendToTail(entry);
/**
* Retrieves a linked dictionary from the table internally
*/
private getLinkedDictionaryPair(key);
/**
* Returns the value to which this dictionary maps the specified key.
* Returns undefined if this dictionary contains no mapping for this key.
* @param {Object} key key whose associated value is to be returned.
* @return {*} the value to which this dictionary maps the specified key or
* undefined if the map contains no mapping for this key.
*/
getValue(key: K): V | undefined;
/**
* Removes the mapping for this key from this dictionary if it is present.
* Also, if a value is present for this key, the entry is removed from the
* insertion ordering.
* @param {Object} key key whose mapping is to be removed from the
* dictionary.
* @return {*} previous value associated with specified key, or undefined if
* there was no mapping for key.
*/
remove(key: K): V | undefined;
/**
* Removes all mappings from this LinkedDictionary.
* @this {collections.LinkedDictionary}
*/
clear(): void;
/**
* Internal function used when updating an existing KeyValue pair.
* It places the new value indexed by key into the table, but maintains
* its place in the linked ordering.
*/
private replace(oldPair, newPair);
/**
* Associates the specified value with the specified key in this dictionary.
* If the dictionary previously contained a mapping for this key, the old
* value is replaced by the specified value.
* Updating of a key that already exists maintains its place in the
* insertion order into the map.
* @param {Object} key key with which the specified value is to be
* associated.
* @param {Object} value value to be associated with the specified key.
* @return {*} previous value associated with the specified key, or undefined if
* there was no mapping for the key or if the key/value are undefined.
*/
setValue(key: K, value: V): V | undefined;
/**
* Returns an array containing all of the keys in this LinkedDictionary, ordered
* by insertion order.
* @return {Array} an array containing all of the keys in this LinkedDictionary,
* ordered by insertion order.
*/
keys(): K[];
/**
* Returns an array containing all of the values in this LinkedDictionary, ordered by
* insertion order.
* @return {Array} an array containing all of the values in this LinkedDictionary,
* ordered by insertion order.
*/
values(): V[];
/**
* Executes the provided function once for each key-value pair
* present in this LinkedDictionary. It is done in the order of insertion
* into the LinkedDictionary
* @param {function(Object,Object):*} callback function to execute, it is
* invoked with two arguments: key and value. To break the iteration you can
* optionally return false.
*/
forEach(callback: (key: K, value: V) => any): void;
}