algorithm - Search based on Second value in a map -


i have mapping of string id -> object. apart merely having insert , delete map, need find id lowest x-value (x-value member in class object instantiated).

initially thought create mapping x-value -> string id this. not much, because in case of remove operation, have anyway search second map particular id (so main problem now).

any suggestions efficiently? (time wise - memory not big constraint)

edit: think x-value id (for removal function) , remove second map using x-value. thing here - x-value float. idea use float key in map ?? maybe using fabs , precision value trick here floating point comparisons ?

edit #2: unfortunately remembered why above method might not work (i busy other stuff , forgot project while). x-value different map entries need not unique. string id primary key. need use multimap , use equal_range.

your solution of using auxiliary map isn't bad post suggests.

it true removal operation require lookup in second map. however, lookup can done in o(log n) time. unlikely deal breaker. if is, please post more details.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -