Git Product home page Git Product logo

fast-delete-heap's Introduction

fast-delete-heap

Priority queue / heap implementation which allows fast O(log N) random deletes.

Java's standard PriorityQueue has O(N) deletion, which makes it pretty inefficient in case of large queue and a lot of delete operations.

To allow fast deletes, this implementation maintains an extra item-to-heap-index map, which slows down inserts a bit.

Base heap implementation is inspired by https://algs4.cs.princeton.edu/24pq/

PriorityQueue vs FastDeletePriorityQueue benchmark:

Two tests:

  • insert N integers
  • delete all N integers
op impl 10K 100K 200K 1M
insert Java PQ 0.57 ± 0.20 ms 6.7 ± 2.4 ms 16.1 ± 6.8 ms 115 ± 48 ms
  Fast PQ 1.74 ± 0.70 ms 26.8 ± 16.9 ms 75 ± 22 ms 442 ± 102 ms
delete Java PQ 20.9 ± 2.1 ms 3600 ± 670 ms 17540 ± 6990 ms N/A
  Fast PQ 2.84 ± 1.32 ms 38 ± 12 ms 103 ± 53 ms 771 ± 163 ms

How to run benchmark: gw jmh

fast-delete-heap's People

Contributors

evgenyfwd avatar waypoint100 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.