performance - What's the best way to manipulate and store huge ordered lists or hashes? -
I have a simple order list that can contain 10 million items or more
Once the value is added to the list, it never changes Does I attach the item to the list, do not insert or delete anything.
I need to manipulate this large list, and it needs to be stored continuously Now I am using a database int => string to represent the list, but I think That's how I want a more efficient way to do this.
I can use a memcatch, but I think 2 functions are missing:
- Constant storage
- Any value Find the index for
It appears that you
The easiest way to do this in Perl is to tie a DBM file ( man perltie ) on a hash.
The sample code, Unchester, can almost certainly be improved:
use db_file; Tie% value2index, 'db_file', 'value2index'; Tie index number 2, 'db_file', 'index 2 value'; Sub index_count () {return scalar% value2index; } Sub value_exists () {my $ value = shift; Return is present ($ value2index {$ value}); } Sub append () {my $ value = shift; If (! Value_exits ($ value)) {# duplicate insertion is my $ index = index_count () + 1; $ Value2index {$ value} = $ index; $ Index value 2 {$ index} = $ value; }} Sub find_index () {my $ value = shift; Return $ value2index {$ value}; } Sub find_value () {my $ index = shift; Return $ Index2value {$ index}; } Do not take it in a multi-threaded environment, there are non-atomic operations.
Comments
Post a Comment