問題描述
我需要將原始鍵(int,可能是 long)映射到高性能哈希映射數(shù)據(jù)結(jié)構(gòu)中的結(jié)構(gòu)值.
I need to map primitive keys (int, maybe long) to struct values in a high-performance hash map data structure.
我的程序會(huì)有幾百張這樣的地圖,而每張地圖一般最多只有幾千個(gè)條目.但是,地圖會(huì)不斷刷新"或攪動(dòng)";想象一下,每秒處理數(shù)百萬條 add
和 delete
消息.
My program will have a few hundred of these maps, and each map will generally have at most a few thousand entries. However, the maps will be "refreshing" or "churning" constantly; imagine processing millions of add
and delete
messages a second.
C 或 C++ 中的哪些庫具有適合此用例的數(shù)據(jù)結(jié)構(gòu)?或者,您會(huì)如何推薦自己構(gòu)建?謝謝!
What libraries in C or C++ have a data structure that fits this use case? Or, how would you recommend building your own? Thanks!
推薦答案
我建議你試試 Google SparseHash(或 C11 版本 Google SparseHash-c11)并查看它是否適合您的需求.它們具有內(nèi)存高效的實(shí)現(xiàn)方式以及針對(duì)速度進(jìn)行了優(yōu)化的實(shí)現(xiàn)方式.我很久以前做過一個(gè)基準(zhǔn)測試,它是速度方面最好的哈希表實(shí)現(xiàn)(但也有缺點(diǎn)).
I would recommend you to try Google SparseHash (or the C11 version Google SparseHash-c11) and see if it suits your needs. They have a memory efficient implementation as well as one optimized for speed. I did a benchmark a long time ago, it was the best hashtable implementation available in terms of speed (however with drawbacks).
這篇關(guān)于超高性能C/C++哈希映射(表、字典)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!