queue-set
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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 QueueSet

new 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 QueueSet

set.enqueue(value: Type): void

dequeue

Remove the first value from the QueueSet and return it. Returns undefined if the QueueSet is empty

set.dequeue(): Type | undefined

getNextItem

Get the next item in the QueueSet

set.getNextItem(): Type | undefined

toArray

Returns the set as an array

set.toArray(): Array<Type>

find

Find all elements in the set that the provided callback function returns true for

set.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 array

set.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

Readme

Keywords

Package Sidebar

Install

npm i queue-set

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

15.8 kB

Total Files

7

Last publish

Collaborators

  • smhtm