CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   Ordered HashTable (http://www.cfd-online.com/Forums/openfoam/60942-ordered-hashtable.html)

olesen January 4, 2007 05:15

I'm looking for a means of mai
 
I'm looking for a means of maintaining a hash in the inserted (created) order.
Here is an example of the (undesirable) behaviour that I'm currently seeing:

HashTable<label> hash;
for (label i=0; i < 10; i++)
{
hash.insert(word("key" + Foam::name(i)), i);
}

Info << hash << endl;
---
Results in

10
(
key8 8
key9 9
key6 6
key7 7
key4 4
key5 5
key2 2
key3 3
key0 0
key1 1
)

At the moment, the first, rather inelegant, workaround I came up is to combine a HashTable<label> (for the keyword lookup) and a Map<entry> (to maintain the insertion order).

The net effect is something like HashTable<entry,word,hash<label> >, but a bit clumsier.

Any hints about a better way?

Thanks,
/mark

olesen January 4, 2007 05:17

Note: the email version of the
 
Note: the email version of the posting is terribly mangled. Please see the web version


All times are GMT -4. The time now is 13:03.