Thanks so much, my fault for judging a function by its name =P (I actually may have even read the description and just totally missed that it did what I’m asking for… Either way, many thanks.)
I’m now trying to figure out how to implement the hashing for my bag, and how to initialize the HashMaps themselves. Are there any good example projects that show how to do this? I might be having trouble here more because I’m a C++ noob and less because I’m a JUCE noob, but any help here would certainly be appreciated.
First, one of the template parameters is “TypeOfCriticalSectionToUse”. I’ve done a little research on mutexes and what “critical sections” are, and I’ve tried looking at the critical section JUCE class, but that hasn’t helped me figure out exactly what I’m supposed to be passing into the template.
Any examples out there where I can see someone actually using the JUCE HashMap class so I can see how it’s done?
Second, looks like I need to create a MyHashGenerator class, as per the documentation:
You can also specify a class to supply a hash function that converts a key value into an hashed integer. This class must have the form:
int generateHash (MyKeyType [key](https://docs.juce.com/develop/namespaceBlocksProtocol.html#a01895711c2ff4b9a8ed600aab5c6dd79af802cb6422dd92bb3cfae224c869b6da), int upperLimit) const
// The function must return a value 0 <= x < upperLimit
return someFunctionOfMyKeyType ([key](https://docs.juce.com/develop/namespaceBlocksProtocol.html#a01895711c2ff4b9a8ed600aab5c6dd79af802cb6422dd92bb3cfae224c869b6da)) % upperLimit;
And then I need to tell the HashMap to use that function, which seems to happen both in the template-syntax, and in the constructor?
HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::HashMap ( int numberOfSlots = defaultHashTableSize,
HashFunctionType hashFunction = HashFunctionType())
I’ve specified the custom hash function here by just turning each int into a string, combining them, and then using the DefaultHashFunction for Strings:
int generateHash (TwoInts key, int upperLimit) const
return juce::DefaultHashFunctions::generateHash (toHash,upperLimit);
But then… how exactly do I pass that into the template and constructor? My guess would be that it’s something like:
With it initialized in the initialization list of the constructor for the class, similarly to this:
: translator(1152, MyHashGenerator::generateHash()),
But those are really just semi-educated guesses.
Thanks very much for any help.