CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Ordered HashTable

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 4, 2007, 05:15
Default I'm looking for a means of mai
  #1
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
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 is offline   Reply With Quote

Old   January 4, 2007, 05:17
Default Note: the email version of the
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Note: the email version of the posting is terribly mangled. Please see the web version
olesen is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 15:10.