In web applications you mostly get into this kind of situations where you need a code or API which acts as Hashtable and since you want it lightning fast, it must be in the memory instead of disk storage. So how would you create an In Memory Hashtable for Strings for a large set.
I had enough experience with hashtable to understand that the whole bottleneck is going to be the hash function which maps Strings to LongInts. After some brainstorming I got the solution. So here we go:
1. Create a Trie and provide to methods to set and retrieve the values. Something like this:
bool insert(String s)
long retrieve(String s)
bool exist(String s)
2. Create a list of String to be inserted in the beginning and use a file to perform the operation.
3. Once you are done with the initial setup now you can put your Hashtable live to answer your queries.
4. Create a daemon and put the above code into it.
5. Whenever you want to shoot a query invoke the daemon and call the retrieve function.
I hope the main problem would be figuring out the appropriate solution and writing a code for daemon and hashtable won't be a problem.
This can be implemented in many ways and on any architecture. But since mostly the servers are located on Linux machines, mostly it'll be useful on Linux environment with C being the underlying language. However I admit that if you use Java or Python it will be much easier to code. I used unix message passing mechanism to handle IPC.
Anybody wants the working code then write to me here
I had enough experience with hashtable to understand that the whole bottleneck is going to be the hash function which maps Strings to LongInts. After some brainstorming I got the solution. So here we go:
1. Create a Trie and provide to methods to set and retrieve the values. Something like this:
bool insert(String s)
long retrieve(String s)
bool exist(String s)
2. Create a list of String to be inserted in the beginning and use a file to perform the operation.
3. Once you are done with the initial setup now you can put your Hashtable live to answer your queries.
4. Create a daemon and put the above code into it.
5. Whenever you want to shoot a query invoke the daemon and call the retrieve function.
I hope the main problem would be figuring out the appropriate solution and writing a code for daemon and hashtable won't be a problem.
This can be implemented in many ways and on any architecture. But since mostly the servers are located on Linux machines, mostly it'll be useful on Linux environment with C being the underlying language. However I admit that if you use Java or Python it will be much easier to code. I used unix message passing mechanism to handle IPC.
Anybody wants the working code then write to me here
No comments:
Post a Comment