|Perl: the Markov chain saw|
Re^4: Re-orderable keyed access structure?by BrowserUk (Pope)
|on Aug 15, 2004 at 02:51 UTC||Need Help??|
I appreciate your having stuck with me through this. Please understand that this is a gut reaction after first reading of your post (and having previously looked at a CPAN Heap implementation), rather than a fully thought through one. I will pursue this further.
Using a weighted heap, moving an item to the top of the heap requires either:
Contrast this with the simplicity of the splice operation.
Then contrast it with the efficiency of doing the linear operation in C, to recursively dereferencing linked lists implemented using perl hashes or arrays.
O(N) -v- O(log N) doesn't tell the complete story when the the former is performed in C code and the latter in Perl code. Especially, heavily structured OO Perl code.
Then take a look at the complexity (and the weight) of something like Heap::Priority.
The order does matter, because it is my cheap mechanism for retaining and propagating the weightings of the elements. One operation takes care of adjusting all the weights of all the affected items in the stack, because their weights are their positions.
For now, my "string list" mechanism looks like it will be easy to implement:
Accessing C via key calls for C to become top item getByKey( 'C' ); does:
This satisfies all my criteria, it's lightweight, pretty damn fast and easy to program.
It's only limitation (that I can see?) is the fixed length keys, but generalising that can be an exercise for another time.