Mercurial > repos > IBBoard
view Collections/SimpleSet.cs @ 33:8971a1c48dbf
Re #18 - Add rounding to half methods
* Add Floor method that rounds down to a half
* Add Ceiling method that rounds up to a half
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 17 May 2009 19:22:53 +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(); } } }