Multidimensional associative arrays in Bash

You can’t do what you’re trying to do: bash arrays are one-dimensional $ declare -A PERSONS $ declare -A PERSON $ PERSON[“FNAME”]=’John’ $ PERSON[“LNAME”]=’Andrew’ $ declare -p PERSON declare -A PERSON='([FNAME]=”John” [LNAME]=”Andrew” )’ $ PERSONS[1]=([FNAME]=”John” [LNAME]=”Andrew” ) bash: PERSONS[1]: cannot assign list to array member You can fake multidimensionality by composing a suitable array index … Read more

Hashtable to Dictionary syncroot .

If you are going strictly for compatability then Bryan is correct. This is the best way to maintain your current semantics on top of a Dictionary. Expanding on it though. The reason the SyncRoot property was not directly added to the generic dictionary is that it’s a dangerous way to do synchronization. It’s only slighly … Read more

Hashtable in C++?

If you’re using C++11, you have access to the <unordered_map> and <unordered_set> headers. These provide classes std::unordered_map and std::unordered_set. If you’re using C++03 with TR1, you have access to the classes std::tr1::unordered_map and std::tr1::unordered_set, using the same headers (unless you’re using GCC, in which case the headers are <tr1/unordered_map> and <tr1/unordered_set> instead). In all cases, … Read more

Hash function for a string

First, it usually does not matter that much in practice. Most hash functions are “good enough”. But if you really care, you should know that it is a research subject by itself. There are thousand of papers about that. You can still get a PhD today by studying & designing hashing algorithms. Your second hash … Read more