开发者

what type of data structure would be efficient for searching a process table

开发者 https://www.devze.com 2022-12-19 04:41 出处:网络
i have to search a process table which is populated by the names of processes running on a given set of ip adresses.

i have to search a process table which is populated by the names of processes running on a given set of ip adresses. currently i am using multimaps in C++ wi开发者_如何学编程th process name as key and ip address as the value. is there any other efficient data structure which can do the same task. also can i gain any sort of parallelism by using pthreads ? if so can anyone point me into a right direction


You do not need parallelism to access a data structure in RAM of several thousand entries. You can just lock over it (making sure only one process/thread accesses it at the time), and ensure the access is sufficient enough. Multimap is okay. A hashmap would be better though.


What is typical query to your table?

Try to use hashmap, it can be faster for big tables.

How do you store names and IP? UTF, string, char*? Ip as uint32 or string?

For readonly structure with a lot of read queries you can benefit from several threads.

upd: use std::unordered_multimap from #include <tr1/unordered_map>


Depending on the size of the table, you may find a hash table more efficient than the multimap container (which is implemented with a balanced binary tree).

The hash_multimap data structure implements a hash table STL container, and could be of use to you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号