Data structure for storing an array of strings in memory

I am considering a data structure for storing a large array of strings in memory. Rows will be inserted at the beginning of the program and will not be added or deleted while the program is running. The most important point is that the search procedure should be as fast as possible. Saving memory does not matter. I am inclined towards the standard hash_set structure from the standard library, which allows me to search for elements in the structure with approximately constant time. But this did not guarantee that this time would be short. Anyone suggest a better standard solution?

Many thanks!

+3
source share
7 answers

A Trie , . -

+3

, , , perfect hash -.

, - , , , . , , , , . , , . , , - ( Trie, -, Judy splay, ), . , .

, .

+2

, , google-sparsehash. / (re), , -/ . . performance. , -. ( : murmur2.)

.

- / "", , Directed Acyclic Word Graph Compact Directed Acyclic Word Graph, * , -, .

** : , , , .. - , (, , ..). *

+1

- , , , .

0

, , , , , , Raymond Chen .

0

- - try, . trie , - , . , . , .

, , : , , , , , , ( ) . , ( , ).

0

:

  • :
    • (char * s) .
    • .
    • .

This supports cache locality, allows you to efficiently search (it will search ~ 4 billion lines with 32 comparisons in space), and it is very simple to implement. There is no need to get fantasies from attempts, because they are complex and slower than they appear (especially if you have long lines).

Accidental side effect: in combination with http://blogs.msdn.com/b/oldnewthing/archive/2005/05/19/420038.aspx you will stop!

0
source

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


All Articles