keyvaluepair - Create a time-based map in C -


so have map key -> struct

my key devices ip address , value(struct) hold devices ip address , time after amount of time has elapsed make key-value pair expire , deleted map.

i new @ wondering way go it.

i have googled around , seem find lot on time-based maps in java only

edit

after coming across this think may have create map items in , , have deque in parallel references each elem. periodically call clean , if has been in there longer x amount of time delete it.

is correcto r can suggest more optimal way of doing ?

i've used 3 approaches solve problem this.

  1. use periodic timer. once every time quantum, expiring elements , expire them. keep elements in timer wheels, see scheme 7 in paper ideas. overhead here periodic timer kick in when has nothing , buckets have constant memory overhead, efficient thing can if add , remove things map more expire elements it.

  2. check elements shortest expiry time. schedule timer kick in after amount of time. in timer, remove expired element , schedule next timer. reschedule timer every time new element added if expiration time shorter scheduled timer. keep elements in heap fast lookup of needs expire first. has quite large insertion , deletion overhead, pretty efficient when common deletion map through expiry.

  3. every time access map, check if element you're accessing expired. if is, throw away , pretend wasn't there in first place. quite inefficient because of calls check timestamp on every access , doesn't work if need perform action on expiry.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -