Redid the tree again.
[Gitrdone.git] / Multidict.cs
blob3b6bf4f4931fe3f875a63cc1f1b05b806bd66607
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
5 namespace Gitrdone
7 public class Multidict<KeyType, ValueType> : System.Collections.IEnumerable
9 protected Dictionary<KeyType, List<ValueType>> m_dict = new Dictionary<KeyType, List<ValueType>>();
11 public Multidict()
15 public List<ValueType> Get(KeyType key)
17 List<ValueType> items;
18 if (m_dict.TryGetValue(key, out items))
20 return items;
22 return null;
25 public bool Add(KeyType key, ValueType value)
27 return Add(key, value, false);
30 public bool Add(KeyType key, ValueType value, bool bAllowDups)
32 List<ValueType> items;
33 if (!m_dict.TryGetValue(key, out items))
35 items = new List<ValueType>();
36 m_dict[key] = items;
38 if (!items.Contains(value) || bAllowDups)
40 items.Add(value);
41 return true;
43 return false;
46 public System.Collections.IEnumerator GetEnumerator()
48 return m_dict.GetEnumerator();