जो आप चाहते हैं (बूस्ट का उपयोग किए बिना) मैं एक "आदेशित हैश" कहता हूं, जो अनिवार्य रूप से हैश का मैशप है और स्ट्रिंग या पूर्णांक कुंजी (या दोनों एक ही समय में) के साथ एक लिंक की गई सूची है। एक आदेश दिया गया हैश एक हैश के पूर्ण प्रदर्शन के साथ पुनरावृत्ति के दौरान तत्वों के क्रम को बनाए रखता है।
मैं एक अपेक्षाकृत नई सी ++ स्निपेट लाइब्रेरी को एक साथ रख रहा हूं जो सी ++ लाइब्रेरी डेवलपर्स के लिए सी ++ भाषा में छेद के रूप में दिखाई देता है। यहां जाएं:
https://github.com/cubiclesoft/cross-platform-cpp
ले लो:
templates/detachable_ordered_hash.cpp
templates/detachable_ordered_hash.h
templates/detachable_ordered_hash_util.h
उपयोगकर्ता नियंत्रित डेटा हैश में रखा जाएगा, तो आप भी चाहते हो सकता है:
security/security_csprng.cpp
security/security_csprng.h
यह आह्वान:
#include "templates/detachable_ordered_hash.h"
...
// The 47 is the nearest prime to a power of two
// that is close to your data size.
//
// If your brain hurts, just use the lookup table
// in 'detachable_ordered_hash.cpp'.
//
// If you don't care about some minimal memory thrashing,
// just use a value of 3. It'll auto-resize itself.
int y;
CubicleSoft::OrderedHash<int> TempHash(47);
// If you need a secure hash (many hashes are vulnerable
// to DoS attacks), pass in two randomly selected 64-bit
// integer keys. Construct with CSPRNG.
// CubicleSoft::OrderedHash<int> TempHash(47, Key1, Key2);
CubicleSoft::OrderedHashNode<int> *Node;
...
// Push() for string keys takes a pointer to the string,
// its length, and the value to store. The new node is
// pushed onto the end of the linked list and wherever it
// goes in the hash.
y = 80;
TempHash.Push("key1", 5, y++);
TempHash.Push("key22", 6, y++);
TempHash.Push("key3", 5, y++);
// Adding an integer key into the same hash just for kicks.
TempHash.Push(12345, y++);
...
// Finding a node and modifying its value.
Node = TempHash.Find("key1", 5);
Node->Value = y++;
...
Node = TempHash.FirstList();
while (Node != NULL)
{
if (Node->GetStrKey()) printf("%s => %d\n", Node->GetStrKey(), Node->Value);
else printf("%d => %d\n", (int)Node->GetIntKey(), Node->Value);
Node = Node->NextList();
}
मैं अपने शोध चरण के दौरान इस एसओ थ्रेड में भाग गया ताकि यह देखने के लिए कि ऑर्डर्ड हैश जैसी कुछ भी मुझे पहले से ही बड़ी पुस्तकालय में छोड़ने की आवश्यकता के बिना मौजूद है या नहीं। मैं निराश हो गया था। तो मैंने अपना खुद लिखा। और अब मैंने इसे साझा किया है।
std :: map के लिए तेज़ लुकअप टाइम का अच्छा हिस्सा इस तथ्य के साथ करना है कि इसे क्रम में क्रमबद्ध किया गया है, इसलिए यह बाइनरी खोज कर सकता है। बस आपका केक नहीं हो सकता है और इसे भी खा सकता है! – bobobobo
फिर आप का उपयोग करके क्या खत्म हो गया? – aggsol