@cute-dw/core
Version:
This TypeScript library is the main part of a more powerfull package designed for the fast WEB software development. The cornerstone of the library is the **DataStore** class, which might be useful when you need a full control of the data, but do not need
125 lines (124 loc) • 4.79 kB
TypeScript
import { Dictionary } from "./Dictionary";
/**
* **Hash table** (hash map) is a data structure which implements an _associative array_ abstract data type, a structure that can _map keys
* to values_. A hash table uses a _hash function_ to compute an index into an array of buckets or slots,
* from which the desired value can be found
*/
export declare class HashTable<K, V> implements Dictionary<K, V> {
private _hashSize;
private _buckets;
private _keys;
constructor();
private _initialize;
private _resize;
/**
* @override
*/
clear(): void;
/**
* @override
*/
isEmpty(): boolean;
/**
* @override
*/
get size(): number;
/**
* Returns the value to which the `key` is mapped in this dictionary, or `undefined` if this map contains no mapping for the key
* @param key The key whose associated value is to be returned
* @returns The value to which the specified key is mapped, or `undefined` if this map contains no mapping for the key
*/
get(key: K): V | undefined;
/**
* Returns the value to which the `key` is mapped in this dictionary, or `defaultValue` if this map contains no mapping for the key
* @param key The key whose associated value is to be returned
* @param defaultValue Default value that will be returned if there is no mapping for the `key`
* @returns The value to which the specified key is mapped, or `defaultValue` if this map contains no mapping for the key
*/
getOrDefault(key: K, defaultValue: V): V;
/**
* Tests if some key maps into the specified value in this hashtable
* @param key A key value
* @returns _true_ if the map contains the entry with the key `key`, or _false_ otherwise
* @see {@link contains}
* @see {@link containsKey}
*/
has(key: K): boolean;
/**
* Tests if some key maps into the specified value in this hashtable
* @param key A key value
* @returns _true_ if the map contains the entry with the key `key`, or _false_ otherwise
* @see {@link has}
* @see {@link containsKey}
*/
contains(key: K): boolean;
/**
* @override
* @see {@link has}
* @see {@link contains}
* @see {@link containsValue}
*/
containsKey(key: K): boolean;
/**
* @override
* @see {@link containsKey}
*/
containsValue(value: V): boolean;
/**
* Returns a `Set` view of the keys contained in this map
*/
keySet(): Set<K>;
/**
* Maps the specified key to the specified value in this hashtable
* @param key The hashtable key
* @param value The value
* @returns The previous value of the specified key in this hashtable, or `undefined` if it did not have one
* @throws `IllegalArgumentException` if the `key` or `value` is _null_ or _undefined_
* @see {@link set}
*/
put(key: K, value: V): V | undefined;
/**
* Copies all the mappings from the specified source map to this map
* @param map Source `Map` object
* @throws `NullPointerException` if the `map` is a nullish value
* @see {@link put}
*/
putAll(map: Map<K, V> | HashTable<K, V>): void;
/**
* Removes the key (and its corresponding value) from this hashtable
* @param key The key that needs to be removed
* @returns _true_ if the entry with the key `key` was deleted, or _false_ otherwise
* @see {@link remove}
*/
delete(key: K): boolean;
/**
* Maps the specified key to the specified value in this hashtable and returns a reference to `this` value.
* If a `key` or a `value` equals to _null_ or _undefined_ value operation is ignored.
* @param key A key of the key/value pair
* @param value A value of the key/value pair
* @returns `this` value
* @see {@link put}
*/
set(key: K, value: V): this;
/**
* Removes the key (and its corresponding value) from this hashtable
* @param key The key that needs to be removed
* @returns The value to which the key had been mapped in this hashtable, or `null` if the key did not have a mapping
* @throws `IllegalArgumentException` if the `key` is _null_ or _undefined_
*/
remove(key: K): V | undefined;
/**
* @override
*/
keys(): Array<K>;
/**
* @override
*/
values(): Array<V>;
/**
* Executes a `callBack` function for each entry in this dictionary
* @param callBack Function to call
* @param thisArg A reference to `this` object
*/
forEach(callBack: (value: V, key: K, map: HashTable<K, V>) => void, thisArg?: any): void;
}