/** \file multiaa.d * \brief An associative array that allows multiple values per key. * * Written by Ben Hinkle and released to the public domain, as * explained at http://creativecommons.org/licenses/publicdomain * The red-black tree code is by Thomas Niemann. * Email comments and bug reports to ben.hinkle@gmail.com * * revision 1.2 */ module mintl.multiaa; private import mintl.share; private import mintl.adapter; private import mintl.sortedaa; private import mintl.hashaa; private import std.stdarg; private import std.boxer; //version = WithBox; /** An associative array of items with duplicate keys. * By default the backing container is a builtin associative array. */ struct MultiAA(Key, Value, ImplType = HashAA!(Key,Value[])) { alias MultiAA ContainerType; alias Value ValueType; alias Key IndexType; alias ImplType AdaptType; const bit isReadOnly = ImplType.isReadOnly; ImplType impl; size_t length() { size_t total = 0; foreach(Value[] val; impl) { total += val.length; } return total; } int opEquals(MultiAA c) { return impl == c.impl; } static if (!ImplType.isReadOnly) { void remove(Key key) { impl.remove(key); } void remove(Key key, Value val) { Value[]* vals = impl.get(key); if (vals) { size_t k; Value[] x = *vals; for(k = 0; k