Nested Containers

Caporegime
Joined
18 Oct 2002
Posts
32,625
I've just needed to code an unordeded_map to a (ordered) map to an unordered_map to a vector of classes that are wrappers around an atomic variable (atomics can't be copied for use in vectors).

To make things more interesting most of the keys are customs structs with their own hash functions, and there are several different namespaces required!
Ugly as heck to define but in use it is quite simple:
Code:
myResults[key1][key2][key3][index].increment();  // thread safe counting of events

What level of nesting have you required in a project?
 
That's pretty absurd. A vector of wrappers around atomics seems reasonable enough, but can you really want a hash table of trees of hash tables instead of one big hash table?

Code:
unordered_map<tuple<key1,key2,key3>,vector<wrapper>>

I've put vectors in a hash table, and stopped a colleague putting hash tables into a hash table, but that's as far as the nesting of containers has gone.

Inheritance on the other hand, I think we're eight levels deep in places, and that's far worse. Someone before me really liked inheritance :(

I could make a single hash but I like the fact that the data is separated by distinct categories, I generate some statistics at different levels.

Inheritance I will rarely go more than 2 deep, an interface and an implementation.
 
Back
Top Bottom