B
Brian Genisio
Hello all,
I need to use a hash table for quick lookup... What is the best way to
do it?
My current solution uses stl::map, where I essentially do the following
(not compilable code):
class MyObj;
struct MyObjList {
MyObj *object;
MyObjList *next;
}
stl::map<int, MyObjList*> objMap;
objMap[createHash(&Obj)]->obj = &Obj; // Storage
objMap[createHash(lookup_info)]; // lookup
Where createHash generates a non-unique integer, and I properly use the
list structure, to create a list of the objects with the same hash key.
While this method has _drastically_ reduced my lookup time, from a
standard scan (Comparison is expensive on this object), it feels clunky,
and there must be a better way to do this, aside from writing it
completely from scratch (STL MAP is probably better than I can do from
scratch, without a lot of work, I would immagine).
Any general ideas?
Thanks,
Brian
I need to use a hash table for quick lookup... What is the best way to
do it?
My current solution uses stl::map, where I essentially do the following
(not compilable code):
class MyObj;
struct MyObjList {
MyObj *object;
MyObjList *next;
}
stl::map<int, MyObjList*> objMap;
objMap[createHash(&Obj)]->obj = &Obj; // Storage
objMap[createHash(lookup_info)]; // lookup
Where createHash generates a non-unique integer, and I properly use the
list structure, to create a list of the objects with the same hash key.
While this method has _drastically_ reduced my lookup time, from a
standard scan (Comparison is expensive on this object), it feels clunky,
and there must be a better way to do this, aside from writing it
completely from scratch (STL MAP is probably better than I can do from
scratch, without a lot of work, I would immagine).
Any general ideas?
Thanks,
Brian