Mercurial > repos > IBBoard
view Collections/SimpleSet.cs @ 59:c6ed77f263a6
Re #24: Add limit objects
* Add default constructor that doesn't set a limit (so it always returns whatever is passed to GetLimit())
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 24 Oct 2009 19:49:47 +0000 |
parents | 0352fa33ee8f |
children | 9832caa89140 |
line wrap: on
line source
// This file (SimpleSet.cs) is a part of the IBBoard library and is copyright 2009 IBBoard. // // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. using System; using System.Collections; using System.Collections.Generic; namespace IBBoard.Collections { public class SimpleSet<TYPE> : IEnumerable { private Dictionary<int, TYPE> dictionary; public SimpleSet() { dictionary = new Dictionary<int,TYPE>(); } public bool Add(TYPE val) { bool added = false; if (!dictionary.ContainsKey(val.GetHashCode())) { dictionary.Add(val.GetHashCode(), val); added = true; } return added; } public bool AddRange(ICollection<TYPE> vals) { bool added = false; foreach (TYPE val in vals) { Add(val); added = true; } return added; } public bool Remove(TYPE val) { return dictionary.Remove(val.GetHashCode()); } public bool Contains (TYPE item) { return dictionary.ContainsKey(item.GetHashCode()); } public void Clear () { dictionary.Clear(); } public int Count { get { return dictionary.Count; } } public bool IsReadOnly { get { return false; } } public IEnumerator GetEnumerator() { return dictionary.Values.GetEnumerator(); } } }