Skip to content

Commit

Permalink
docs(readme): update README file
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledosama999 committed Feb 25, 2021
1 parent 790d45b commit 3baaf49
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,71 @@
# priority-queue
A typescript package for priority queue data structure
# Binary heap
A package for general purpose binary heap data structure that can contain any type of data

# Installation
```bash
npm i binary-heap.js
```

# Usage
```js
const binaryHeap = new BinaryHeap(
(x) =>x
)

binaryHeap.insert(3);
binaryHeap.insert(5);
binaryHeap.insert(7);

binaryHeap.pop() // 7
binaryHeap.pop() // 5
binaryHeap.pop() // 3
binaryHeap.pop() // undefined
```

# Constructor

| Parameter | Type | Required| Default| Description |
| :--- | :----: | :---: | :---: | ---: |
| extractor | function | false | | function that extracts the key used for sorting elements in the heap (should be equal to identity for primitive data types) |
| iterator | IterableIterator | false| | Used to provide the heap with initial elements |
MaxHeap | boolean | false | true | determines the order of the heap (maximum or minimum)

Works with any data structure that implements the iteratable interface to provide it's elements
```js
// Works with arrays, maps, sets
const arr = [1,2,3];
const set = new Set([1,2,3])
const map = new Map();
map.set(1,1)
map.set(2,2)
map.set(3,3);

const binaryHeapOne = new BinaryHeap(
(x) =>x,
arr.values(),
false
);

const binaryHeapOne = new BinaryHeap(
(x) =>x,
sets.values(),
false
);

const binaryHeapOne = new BinaryHeap(
(x) =>x,
map.keys().values(),
false
)
```
Works with complex objects as long as you provide the right extractor

```js
const arr = [{id:1},{id:2},{id:3}];

const binaryHeap = new BinaryHeap(
(x) =>x.id,
arr.values(),
false
)
```

0 comments on commit 3baaf49

Please sign in to comment.