Queue Set
A queue that is also a set. I'm sure there's an actual name for this data structure that isn't QueueSet.Usage
Install
yarn add queue-set
Basic Example
const queueSet = new QueueSet<string>();
queueSet.enqueue("newItem");
console.log(queueSet.getNextItem()) // "newItem"
console.log(queueSet.dequeue()) // "newItem"
console.log(queueSet.size()) // 0
Constructor
Create a new QueueSetnew QueueSet<Type>(hashFunction?: HashFunction<Type>);
hashFunction
is an optional argument that hashes values in the QueueSet to tell if they are distinct. This defaults to JSON.stringify
(technically this isn't a hash function because it doesn't map values to a fixed size, but the important things is that there's a unique string for each value).enqueue
Add a value to the QueueSetset.enqueue(value: Type): void
dequeue
Remove the first value from the QueueSet and return it. Returns undefined if the QueueSet is emptyset.dequeue(): Type | undefined
getNextItem
Get the next item in the QueueSetset.getNextItem(): Type | undefined
toArray
Returns the set as an arrayset.toArray(): Array<Type>
find
Find all elements in the set that the provided callback function returns true forset.find(callbackFn: (element: Type, index?: number, queseSet?: QueueSet<Type>) => boolean): Array<Type>
removeBatch
Remove all elements in the queue that match any elements in the provided arrayset.removeBatch(items: Array<Type>): Array<Type>
Contributing
Install dependencies
yarn
or npm i
Build and watch for changes
yarn start
or npm run start
Create production bundle
yarn build
or npm run build