Map<K1, K2, K3, V>
Map<K1, K2, K3, V> is a 3 key map. It implements an interface of IMap<K1, K2, K3, V>. It is recommended that you use the IMap interfaces if you prefer to not link to the class types (in parameter or field types). If it is needed, all Map types also implement the IDictionary interface. However, due to the potential performance loss for treating a Map as an IDictionary (see
Best Practices), it is recommended to not use the IDictionary interface unless you need to.
public Func<K1, K2, K3, V> DefaultGeneration
Allows you to specify a default generation when requesting new keys. See
DefaultGeneration.
var unitByLocationCache = new Map<int, int, int, List<Unit>>();
unitByLocationCache.DefaultGeneration = (x, y, z) => new List<Unit>();
foreach (var unit in GameUnits)
{
unitByLocationCache[unit.X, unit.Y, unit.Z].Add(unit);
}
public V DefaultValue
Allows you to specify a default value to return for nonexistent keys. See
DefaultValue.
public List<KeyValueSet<Tuple<K1, K2, K3>, V>> KeyValues
Return a strong types list of KeyValues. Each Map class have a version of KeyValues, simplifying iteration syntax.
public bool ContainsKey(K1 k1, K2 k2)
Returns true if the key pair was found.
public bool ContainsKey(K1 k1, K2 k2, K3 k3)
Returns true if the key pair was found.
Note that it is also possible to use child maps before they have values.
var map = new Map<int, int, int, int>();
// ... some time later
var child = map[1, 2]; // child is an IMap<K3, V>
if (child.ContainsKey(3))
{
// ....
}
// the above accomplishes the same as
if (map.ContainsKey(1, 2, 3))
{
// ...
}
public bool Remove(K1 k1, K2 k2)
Removes the key pair. Returns true if the key pair was found, else false.
public bool Remove(K1 k1, K2 k2, K3 k3)
Removes the key pair. Returns true if the key pair was found, else false.
- A special note on 'Remove'. Removing a key set also removes the parent key if there are no remaining siblings.
var map = new Map<int, int, int, int>();
map[1, 2, 3] = 4;
map[1, 2, 4] = 5;
Assert.IsTrue(map.Remove(1, 2, 3));
Assert.IsTrue(map.ContainsKey(1, 2));
Assert.IsTrue(map.ContainsKey(1, 2, 4));
Assert.IsTrue(map.Remove(1, 2, 4));
Assert.IsFalse(map.ContainsKey(1, 2));