-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2a1661d
Showing
11 changed files
with
2,306 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/dist | ||
/node_modules | ||
|
||
.env | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/src | ||
/node_modules | ||
|
||
.env | ||
.DS_Store | ||
|
||
tsconfig.json | ||
tsup.config.ts | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Andrés Leiva | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Heap happens | ||
|
||
Need a fast and efficient heap/priority queue in your JavaScript/TypeScript projects? Look no further! | ||
|
||
This package offers a simple, flexible, and performant implementation of the Heap data structure, ready to tackle your most demanding tasks. | ||
|
||
## Examples | ||
|
||
Push, top and change higher priority comparator method. | ||
|
||
```ts | ||
const heap = new Heap<number>(); | ||
|
||
heap.push(404); | ||
heap.push(200); | ||
heap.push(500); | ||
|
||
console.log(heap.top()); // 500 | ||
heap.changeHigherPriorityComparator((a, b) => a < b); | ||
console.log(heap.top()); // 200 | ||
``` | ||
|
||
Default custom comparator and toSortedArray method. | ||
|
||
```ts | ||
const heap = new Heap<Profile>({ | ||
comparator: (a, b) => a.points > b.points | ||
// if a.points is greater than b.points, then 'a' has higher priority | ||
}); | ||
|
||
heap.push({ name: "Avi", points: 500 }); | ||
heap.push({ name: "Foo", points: 900 }); | ||
heap.push({ name: "Bar", points: 700 }); | ||
|
||
console.log(heap.top()); // { name: "Foo", points: 900 } | ||
console.log(heap.toSortedArray(profile => profile.name)); // ["Foo", "Bar", "Avi"] | ||
``` | ||
|
||
## Docs | ||
|
||
For better examples and details about the methods and good practices, please see the following [documentation website](https://heap-happens.netlify.app/). | ||
|
||
## Contributing | ||
|
||
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. | ||
|
||
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". | ||
Don't forget to give the project a star! Thanks again! | ||
|
||
1. Fork the Project | ||
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) | ||
3. Commit your Changes (`git commit -m 'feat: add some AmazingFeature'`) | ||
4. Push to the Branch (`git push origin feature/AmazingFeature`) | ||
5. Open a Pull Request | ||
|
||
## License | ||
Distributed under the MIT License. See `LICENSE.txt` for more information. | ||
|
||
## Contact | ||
Aleiva - [@aleiva17](https://github.com/aleiva17) - aleiva1700@gmail.com |
Oops, something went wrong.