Nested Containers

Caporegime
Joined
18 Oct 2002
Posts
32,651
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 :(
 
On a similar(ish) note I've been playing around with what is probably closest described as a self linking? compound data structure that basically provides a higher level way to handle almost endlessly complex and nested data using a mixture of standard double linked list techniques and some old school C struct usage I saw John Carmack using - application programmers would probably have a fit but for game programming its incredibly fast.

I'm largely self taught so might be using some of the terminology wrong and never really taken to more modern techniques.
 
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