Skip to content

Commit

Permalink
add isEmpty
Browse files Browse the repository at this point in the history
add length alias
add offer alias
update README.md
  • Loading branch information
keriati committed Jan 3, 2024
1 parent 91c1a3c commit 22bfd68
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 22 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@ const lowest = queue.pop(); // returns item with lowest priority

- **constructor(items?: [T, Priority][]):** Initialize a new MinBucketQueue with optional initial items.
- **push(item: T, priority: Priority):** Adds an item to the queue with an associated priority.
- **pop(): T | undefined:** Removes and returns the item with the minimum priority. Returns undefined if the queue is empty.
- **add(item: T, priority: Priority):** Alias for push.
- **offer(item: T, priority: Priority):** Alias for push.
- **pop(): T | undefined:** Removes and returns the item with the minimum priority. Returns undefined if the queue is empty.
- **poll(): T | undefined:** Alias for pop.
- **peek(): T | undefined:** Returns the item with the minimum priority without removing it from the queue.
- **clear():** Removes all items from the queue.
- **refill(items: [T, Priority][]):** Clears the queue and adds the provided items.
- **has(item: T):** Checks if the queue contains the specified item.
- **contains(item: T):** Alias for has.
- **toArray(): T[]:** Returns an array containing all the items in the queue.
- **get size(): number:** Returns the number of items in the queue.
- **isEmpty(): boolean:** Returns `true` if the queue is empty, otherwise returns `false`.
- **size: number:** Contains the number of items in the queue.
- **length: number:** Contains the number of items in the queue.

### MaxBucketQueue<T>

Expand All @@ -84,16 +87,19 @@ const lowest = queue.pop(); // returns item with lowest priority

- **constructor(items?: [T, Priority][]):** Initialize a new MaxBucketQueue with optional initial items.
- **push(item: T, priority: Priority):** Adds an item to the queue with an associated priority.
- **pop(): T | undefined:** Removes and returns the item with the maximum priority. Returns undefined if the queue is empty.
- **add(item: T, priority: Priority):** Alias for push.
- **offer(item: T, priority: Priority):** Alias for push.
- **pop(): T | undefined:** Removes and returns the item with the maximum priority. Returns undefined if the queue is empty.
- **poll(): T | undefined:** Alias for pop.
- **peek(): T | undefined:** Returns the item with the maximum priority without removing it from the queue.
- **clear():** Removes all items from the queue.
- **refill(items: [T, Priority][]):** Clears the queue and adds the provided items.
- **has(item: T):** Checks if the queue contains the specified item.
- **contains(item: T):** Alias for has.
- **toArray(): T[]:** Returns an array containing all the items in the queue.
- **get size(): number:** Returns the number of items in the queue.
- **isEmpty(): boolean:** Returns `true` if the queue is empty, otherwise returns `false`.
- **size: number:** Contains the number of items in the queue.
- **length: number:** Contains the number of items in the queue.

## License

Expand Down
3 changes: 3 additions & 0 deletions dist/index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ declare abstract class BucketQueue<T> {
abstract push(item: T, priority: Priority): void;
abstract pop(): T | undefined;
add(item: T, priority: Priority): void;
offer(item: T, priority: Priority): void;
poll(): T | undefined;
peek(): T | undefined;
clear(): void;
refill(items: [T, Priority][]): void;
has(item: T): boolean;
contains: (item: T) => boolean;
toArray(): T[];
isEmpty: () => boolean;
get size(): number;
get length(): number;
}

declare class MaxBucketQueue<T> extends BucketQueue<T> {
Expand Down
3 changes: 3 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ declare abstract class BucketQueue<T> {
abstract push(item: T, priority: Priority): void;
abstract pop(): T | undefined;
add(item: T, priority: Priority): void;
offer(item: T, priority: Priority): void;
poll(): T | undefined;
peek(): T | undefined;
clear(): void;
refill(items: [T, Priority][]): void;
has(item: T): boolean;
contains: (item: T) => boolean;
toArray(): T[];
isEmpty: () => boolean;
get size(): number;
get length(): number;
}

declare class MaxBucketQueue<T> extends BucketQueue<T> {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 22bfd68

Please sign in to comment.