Hashtable with MultiDimensional Key in C#

I think a better approach is to encapsulate the many fields of your multi-dimensional key into a class / struct. For example struct Key { public readonly int Dimension1; public readonly bool Dimension2; public Key(int p1, bool p2) { Dimension1 = p1; Dimension2 = p2; } // Equals and GetHashCode ommitted } Now you can … Read more

Hash tables in MATLAB

Consider using MATLAB’s map class: containers.Map. Here is a brief overview: Creation: >> keys = {‘Jan’, ‘Feb’, ‘Mar’, ‘Apr’, ‘May’, ‘Jun’, … ‘Jul’, ‘Aug’, ‘Sep’, ‘Oct’, ‘Nov’, ‘Dec’, ‘Annual’}; >> values = {327.2, 368.2, 197.6, 178.4, 100.0, 69.9, … 32.3, 37.3, 19.0, 37.0, 73.2, 110.9, 1551.0}; >> rainfallMap = containers.Map(keys, values) rainfallMap = containers.Map handle … Read more

PSCustomObject to Hashtable

Shouldn’t be too hard. Something like this should do the trick: # Create a PSCustomObject (ironically using a hashtable) $ht1 = @{ A = ‘a’; B = ‘b’; DateTime = Get-Date } $theObject = new-object psobject -Property $ht1 # Convert the PSCustomObject back to a hashtable $ht2 = @{} $theObject.psobject.properties | Foreach { $ht2[$_.Name] = … Read more

Associative arrays in Shell scripts

Another option, if portability is not your main concern, is to use associative arrays that are built in to the shell. This should work in bash 4.0 (available now on most major distros, though not on OS X unless you install it yourself), ksh, and zsh: declare -A newmap newmap[name]=”Irfan Zulfiqar” newmap[designation]=SSE newmap[company]=”My Own Company” … Read more

.NET HashTable Vs Dictionary – Can the Dictionary be as fast?

System.Collections.Generic.Dictionary<TKey, TValue> and System.Collections.Hashtable classes both maintain a hash table data structure internally. None of them guarantee preserving the order of items. Leaving boxing/unboxing issues aside, most of the time, they should have very similar performance. The primary structural difference between them is that Dictionary relies on chaining (maintaining a list of items for each … Read more