annotate Collections/SimpleSet.cs @ 43:2baf3f949cfb

* Make sure that we use "." as our decimal separator when parsing doubles from XML (should fix warfoundry:#185 for Europe) * Automated cleanups no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sun, 04 Oct 2009 09:47:16 +0000
parents 0352fa33ee8f
children 9832caa89140
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
0352fa33ee8f Closes #8 - license code
IBBoard <dev@ibboard.co.uk>
parents: 3
diff changeset
1 // This file (SimpleSet.cs) is a part of the IBBoard library and is copyright 2009 IBBoard.
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
16
0352fa33ee8f Closes #8 - license code
IBBoard <dev@ibboard.co.uk>
parents: 3
diff changeset
3 // 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.
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.Collections;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.Collections.Generic;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 namespace IBBoard.Collections
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 public class SimpleSet<TYPE> : IEnumerable
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 private Dictionary<int, TYPE> dictionary;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 public SimpleSet()
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 dictionary = new Dictionary<int,TYPE>();
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 public bool Add(TYPE val)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 bool added = false;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 if (!dictionary.ContainsKey(val.GetHashCode()))
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 dictionary.Add(val.GetHashCode(), val);
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 added = true;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 return added;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 public bool AddRange(ICollection<TYPE> vals)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 bool added = false;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 foreach (TYPE val in vals)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 Add(val);
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 added = true;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 return added;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 public bool Remove(TYPE val)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 return dictionary.Remove(val.GetHashCode());
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 public bool Contains (TYPE item)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 return dictionary.ContainsKey(item.GetHashCode());
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 public void Clear ()
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 dictionary.Clear();
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 public int Count {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 get { return dictionary.Count; }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 public bool IsReadOnly {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 get { return false; }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 public IEnumerator GetEnumerator()
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 {
3
3dab3db95e4a Fix SimpleSet so that the enumerator works over the values in the set
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
71 return dictionary.Values.GetEnumerator();
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 }