Creating Some Interesting Data Storage Templates
Today I've spent a good bit of time adding two interesting (and useful) data storage template classes to CKit. The reason I added them today was that I had noticed their use in a few other projects I've been working on, and they are just complex enough to cause 'clutter' in the project and not enough to be a significant part of the project. They're right where I find the things to strip for re-use.
The first is a 1:1 map where the data is added with a simple put() command but the underlying data structure is really two STL std::map objects - one going from keys to values and the reverse going from values to keys. This 'bi-directional' map allows me to be able to quickly and easily get a key for a value and a value for a key. In a few of my projects I do encoding mapping or translational mappings - where the map is 1:1, but it's as often that I need to go in the 'reverse' direction as the 'forward' direction. Scanning the map was far too inefficient and the size of these guys wasn't an issue, so it made sense to have two 'opposing' maps and place (and remove) the data in pairs using both maps.
The second is a many:many cross-reference map where the pairings do not have to be unique - similarly to the STL multimap, but in this case, the data is maps of std::sets which makes it easy to get iterators on the values for a key - or the keys for a value. This guy is used in a project of mine where there are several representations of the same thing, and a 1:many is a simplistic case of the many:many. I'm not sure if I'll go back and retrofit the code in the projects for these new template classes, but it's nice to have them should the need arise again.