tags:

views:

156

answers:

3

I would like to use the partitions of a graph as the key to a std::map

I could represent this as a std vector of nodes. Or I could convert it into a more compact 'custom' binary format (bitset?), or a string representation.

For simplicitiy's sake, we can say there is no inherent order to partitions of a graph.

Which will be fastest in terms of insertions and lookups (note the size of this map will be in the order of a billion nodes)

+1  A: 

The only way to reliably answer this question is the only way to answer ANY optimization question: Try it and see.

That said, I doubt there'd be much difference between the two, so long as there is an efficient comparison operator you can use.

Billy ONeal
+4  A: 

Keep your key type, but use boost's unordered_map and write your own hash() function for your graph partition.

For example, if order doesn't matter, you can hash each node in a way that is invariant to order. If you post how you are encoding it now, we can help more with this.

Inverse
Currently a partition is stored as array of 64 bit integers where each long comprises a group and each bit in that long denotes whether a node is a member of that group. E.g. 0101, 1010 Would mean nodes 0 and 2 belong to group 0 and nodes 1 and 3 belong to group 1 of the partition
zenna
+3  A: 

If you're going to have that many entries and performance is critical, I would suggest to definitely use unordered_map.

If you are using C++1x it's in the standard library; otherwise you can get it from boost.

If performance is really critical you can go even further and use boost::intrusive. It contains "intrusive" versions of the standard library containers: they copy the pointers of the values you insert instead of the values themselves. If the values are large you'll get a big performance benefit.

Andreas Bonini