Priority queue that can be saved to disk?

I need to implement an application that has a priority queue that has over 100 M entries. My problem is that I cannot store all this data in memory, so I need to save it to disk. Is there a cache solution where I can store all this information on disk?

+3
source share
1 answer

I think you can solve this using a B-tree with a few minor changes.

B-trees are specifically designed to store sorted items on disk in such a way as to minimize the number of disk reads required to search for any item. Since they store their elements in sorted order, you can use them as priority queues, performing inserts as usual and finding the minimum element, taking the leftmost element in the tree (i.e., the first element of the leftmost node sheet).

In the B-tree of order d, you can find the minimum element using O (log d n) read and write to the disk, where n is the total number of elements. Inserting and removing will also require only O (log d n) read and write discs.

, node B-. node , . , , , node. extract-min: node . B-, , , - O (1).

, B- :

  • find-min: O (1)
  • insert: O (log d n)
  • extract-min: O (1)

, !

+1

Source: https://habr.com/ru/post/1762675/


All Articles