UNPKG

structs

Version:

A collection of general purpose data structures for JavaScript/TypeScript

128 lines (126 loc) 3.81 kB
/*! * structs v0.1.1 * A collection of general purpose data structures for JavaScript/TypeScript * Copyright (c) 2021 Mayank Verma * Released under the MIT License */ declare class HashSet<T extends string | number | bigint> { #private; constructor(values?: T[]); /** * @returns Length of the HashSet. */ len(): number; /** * Inserts value to the HashSet. If the value already exists in the HashSet it * will return false, else true. * * @remarks * This method throws an error if the provided value is not of valid type, * i.e string, number or bigint. * * @param Value - Value to insert * @param throwError - Boolean specifying whether to throw TypeError on invalid * insert type or not, defaults to false. * @returns boolean */ insert(value: T, throwError?: boolean): boolean; /** * Removes value from the HashSet. Returns true or false depending on whether * given value was successfully removed from the HashSet or not. * * @param value - Value to remove * @returns boolean */ remove(value: T): boolean; /** * Returns true or false depending on whether given value exists in * the HashSet or not. * * @param value - Value to check * @returns boolean */ contains(value: T): boolean; /** * Clears the HashSet and returns all values in an iterator. * * @returns iterator */ drain(): IterableIterator<T>; /** * Clears the HashSet and returns true. * * @returns true */ clear(): true; /** * Returns values of HashSet in an array * * @returns array */ toArray(): T[]; /** * Iterates over values of the HashSet and invokes the function for each value. * * @param function The function invoked per iteration. * @returns null */ forEach(callback: (value: T) => void): void; /** * Performs union between two HashSets and returns the result in a new HashSet * * @param otherHashSet HashSet to perform union against * @returns HashSet */ union(otherHashSet: HashSet<T>): HashSet<T>; /** * Performs intersection between two HashSets and returns the result in a new HashSet * * @param otherHashSet HashSet to perform intersection against * @returns HashSet */ intersection(otherHashSet: HashSet<T>): HashSet<T>; /** * Performs difference between two HashSets and returns the result in a new HashSet * * @param otherHashSet HashSet to perform difference against * @returns HashSet */ difference(otherHashSet: HashSet<T>): HashSet<T>; /** * Checks if two HashSets are equal * * @param otherHashSet HashSet to check equality against * @returns boolean */ equals(otherHashSet: HashSet<T>): boolean; /** * Checks if the HashSet is a subset of another HashSet * * @param otherHashSet HashSet to check against * @returns boolean */ isSubsetOf(otherHashSet: HashSet<T>): boolean; /** * Checks if the HashSet is a strict subset of another HashSet * * @param otherHashSet HashSet to check against * @returns boolean */ isStrictSubsetOf(otherHashSet: HashSet<T>): boolean; /** * Checks if the HashSet is a superset of another HashSet * * @param otherHashSet HashSet to check against * @returns boolean */ isSupersetOf(otherHashSet: HashSet<T>): boolean; /** * Checks if the HashSet is a strict superset of another HashSet * * @param otherHashSet HashSet to check against * @returns boolean */ isStrictSupersetOf(otherHashSet: HashSet<T>): boolean; } export { HashSet };