I am currently in the thinking process of the data structure I might use for a current project. I don’t need to delete items as i am loading a database,using it, and then exiting the program. The only constraint concerns search time.(memory in a second time but mainly time).
Overview on what I intend to do.
I am parsing files and extracting informations that I use to create various object.
After reading the files and creating the objects,i have a set of multiple objects that have references to other one as string.
The goal here is to find which net goes from one domain to another
E.g : text input file :
module Blabla
netTomodule Foo
domain 1
..../*Other parameters of the module*/
end module
module Foo
netTomodule Blabla
netTomodule Foo2
domain 2
..../*Other parameters of the module*/
end module
module Foo2
netTomodule Foo
domain 2
..../*Other parameters of the module*/
end module
After reading this I get 3 module objects Foo Foo2 and Blabla and their attributes are as follow :
class Module{
private :
string name;
int domain;
netlist * mynetlist;
...
}
My opinion and the thing i want to get advice on :
After thinking about this, i think that my best shot is to :
- When reading the file and extracting info, i should create a linked list of Module.
- Then with the number of Module i have read, i create an array that is double the size of that.
- For each module, I use a hash function to hash the module name and put a pointer to this module at the given index in the array
- Now when i will want to find a module, i just have to compute the hash value and get the pointer at the given index(or increment if its not the good module because of a collision previously in the making of the array)
This is basically an implematation of a hashtable or atleast what i know of a hashtable from my clasess.
My question is Is this a good thought ? Is there a hashtable library i can use that does that ? (i have heard and look for unordered_map and map but i don’t know if it fits my needs very well)
This is a huge text so i hope it is detailed enough, so thank you if you have the courage to read everything !
Just use any hash table that comes with your standard library or from boost. Most will have the
unordered_map(as specified by TR1 and proposed for C++0x) as does boost, but some will have astd::hash_maporstdext::hash_mapwith various implementation being slightly different, e.g. the original SGI vs. Microsoft.You don’t need to build a list, just put the objects directly in the hash table; it allows sequential iteration, though it will be in some fixed random order.