Priority Queue with a find function - Fastest Implementation

前端 未结 7 2150
一向
一向 2021-02-07 13:24

I am looking at implementing a priority queue with an added requirement, a find/search function which will tell whether an item is anywhere within the queue. So the functions wi

7条回答
  •  一向
    一向 (楼主)
    2021-02-07 13:34

    Store your data in the fastest container you've tested and use a bloom filter to test if something is in the container.

    I mated a bloom filter with a hash table in a previous project and it sped things up 400 times on hash tables with an average of roughly 10k items.

    The bloom filter has a few interesting properties:

    • If the answer is no from a bloom filter, it's 100% reliable.
    • If the answer is yes, you have to check the other data structure to make sure the item is actually present.
    • Make sure you pick a good hash function :)

提交回复
热议问题