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

Hashtables and key order

There is no built-in solution in PowerShell V1 / V2. You will want to use the .NET System.Collections.Specialized.OrderedDictionary: $order = New-Object System.Collections.Specialized.OrderedDictionary $order.Add(“Switzerland”, “Bern”) $order.Add(“Spain”, “Madrid”) $order.Add(“Italy”, “Rome”) $order.Add(“Germany”, “Berlin”) PS> $order Name Value —- —– Switzerland Bern Spain Madrid Italy Rome Germany Berlin In PowerShell V3 you can cast to [ordered]: PS> [ordered]@{“Switzerland”=”Bern”; “Spain”=”Madrid”; … Read more

Hashtable key within integer interval

No need to reinvent the wheel, use a NavigableMap. Example Code: final NavigableMap<Integer, String> map = new TreeMap<Integer, String>(); map.put(0, “Cry Baby”); map.put(6, “School Time”); map.put(16, “Got a car yet?”); map.put(21, “Tequila anyone?”); map.put(45, “Time to buy a corvette”); System.out.println(map.floorEntry(3).getValue()); System.out.println(map.floorEntry(10).getValue()); System.out.println(map.floorEntry(18).getValue()); Output: Cry Baby School Time Got a car yet?

ConcurrentHashMap and Hashtable in Java [duplicate]

ConcurrentHashMap and Hashtable locking mechanism Hashtable is belongs to the Collection framework; ConcurrentHashMap belongs to the Executor framework. Hashtable uses single lock for whole data. ConcurrentHashMap uses multiple locks on segment level (16 by default) instead of object level i.e. whole Map. ConcurrentHashMap locking is applied only for updates. In case of retrievals, it allows … Read more