I have a hash-table I use for random, keyed lookups, it works fine. I also
want to maintain a most recently used list of accesses to the table;
whenever an entry is accessed from the hash-table, update a corresponding
item in some other data construct such that the least frequently accessed
items can be removed from the hash-table at some later time.
My first idea (so far only..) is the obvious inefficient one, keep a list of
the hash-table keys. Whenever an item in the hash-table is accessed, move
its entry in the list to the head. Least used items are then found at the
end of the list. I imagine its expensive to find & delete particular items
within the list, so I was wondering if anyone could supply a hint for an
approach which might be more efficient.
Thanks,
Gregm
Roger Corman
Sent via Deja.com http://www.deja.com/
Before you buy.
Greg Menke wrote:
> Hi,
>
> I have a hash-table I use for random, keyed lookups, it works fine. I also
> want to maintain a most recently used list of accesses to the table;
> whenever an entry is accessed from the hash-table, update a corresponding
> item in some other data construct such that the least frequently accessed
> items can be removed from the hash-table at some later time.
>
> My first idea (so far only..) is the obvious inefficient one, keep a list of
> the hash-table keys. Whenever an item in the hash-table is accessed, move
> its entry in the list to the head. Least used items are then found at the
> end of the list. I imagine its expensive to find & delete particular items
> within the list, so I was wondering if anyone could supply a hint for an
> approach which might be more efficient.
Well, I have done this myself. They way I did it was to have the real data
items stored in a doubly linked list. The hash table's values were the
individual nodes of the list. Popping a node to the head of the list or moving
it up a slot are trivial, though in the second case, it might be more efficient
and simpler to just store the indices of an array, though that's not as
"correct."
The advantage of this approach is that there's never a halting operation..
dave