I have a hash table that is under heavy traffic. I want to add a timeout mechanism to hashtable, delete too old entries. My problems, - It should be easy - Eliminating the operation is not critical time. I mean (the timeout value is 1 hour), the delete operation can be performed after 1 hour or 1 hour 15 minutes. No problems.
My opinion is this: I create a large array (as a ring buffer) that stores the time and key of the hash table. When adding to the hash table using the array index, find the next time interval, if the array slot is empty, enter the insert time and HT -key, if the array slot is not empty, compare the insert time for the timeout.
if a timeout occurs, remove it from the Hashtable (if it has not yet been deleted); this is not a timeout, the increment index before searching for a slot for a slot or a slot with a timeout. When deleting from a hash table, there is no operation with a large array.
Soon, for each add operation to the Hashtable, you can remove one timeout from the hash table or do nothing.
What is your more elegant and lightweight solution?
Thanks for the help,
source
share