Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
SortedSet.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #if NET35
19 
20 namespace System.Collections.Generic
21 {
22  [Serializable]
23  public class SortedSet<T> : ISet<T>, ICollection
24  {
25  private readonly SortedList<T, byte> _list;
26 
27  public SortedSet()
28  : this(Comparer<T>.Default)
29  { }
30 
31  public SortedSet(IComparer<T> comparer)
32  {
33  _list = new SortedList<T, byte>(comparer);
34  }
35 
36  public T Min { get { return (_list.Count) >= 1 ? _list.Keys[0] : default(T); } }
37 
38  public T Max { get { return (_list.Count) >= 1 ? _list.Keys[_list.Count - 1] : default(T); } }
39 
40 
46  public void Clear()
47  {
48  _list.Clear();
49  }
50 
51  public void CopyTo(T[] array, int arrayIndex)
52  {
53  _list.Keys.CopyTo(array, arrayIndex);
54  }
55 
56  public bool Remove(T item)
57  {
58  return _list.Remove(item);
59  }
60 
61  public bool Contains(T value)
62  {
63  return _list.ContainsKey(value);
64  }
65 
66  public bool Add(T item)
67  {
68  if (!_list.ContainsKey(item))
69  {
70  _list.Add(item, 0);
71  return true;
72  }
73  return false;
74  }
75 
76  public void UnionWith(IEnumerable<T> other)
77  {
78  foreach (var obj in other)
79  Add(obj);
80  }
81 
82  public IEnumerator<T> GetEnumerator()
83  {
84  return _list.Keys.GetEnumerator();
85  }
86 
87  public IComparer<T> Comparer { get { return _list.Comparer; } }
88 
89  public int Count
90  {
91  get { return _list.Count; }
92  }
93 
94  #region Explicit Interface Implementations
95 
96  void ICollection<T>.Add(T item)
97  {
98  Add(item);
99  }
100 
101  void ICollection.CopyTo(Array array, int index)
102  {
103  CopyTo((T[]) array, index);
104  }
105 
106  bool ICollection<T>.IsReadOnly
107  {
108  get { return false; }
109  }
110 
111  bool ICollection.IsSynchronized
112  {
113  get { return false; }
114  }
115 
116  object ICollection.SyncRoot
117  {
118  get { throw new NotSupportedException(); }
119  }
120 
121  IEnumerator IEnumerable.GetEnumerator()
122  {
123  return GetEnumerator();
124  }
125 
126  int ICollection.Count
127  {
128  get { return Count; }
129  }
130 
131  #endregion
132 
133  #region ISet<T> Implementation
134 
135  void ISet<T>.ExceptWith(IEnumerable<T> other)
136  {
137  foreach(var obj in other)
138  {
139  _list.Remove(obj);
140  }
141  }
142 
143  void ISet<T>.IntersectWith(IEnumerable<T> other)
144  {
145  throw new NotImplementedException();
146  }
147 
148  bool ISet<T>.IsProperSubsetOf(IEnumerable<T> other)
149  {
150  throw new NotImplementedException();
151  }
152 
153  bool ISet<T>.IsProperSupersetOf(IEnumerable<T> other)
154  {
155  throw new NotImplementedException();
156  }
157 
158  bool ISet<T>.IsSubsetOf(IEnumerable<T> other)
159  {
160  throw new NotImplementedException();
161  }
162 
163  bool ISet<T>.IsSupersetOf(IEnumerable<T> other)
164  {
165  throw new NotImplementedException();
166  }
167 
168  bool ISet<T>.Overlaps(IEnumerable<T> other)
169  {
170  throw new NotImplementedException();
171  }
172 
173  bool ISet<T>.SetEquals(IEnumerable<T> other)
174  {
175  throw new NotImplementedException();
176  }
177 
178  void ISet<T>.SymmetricExceptWith(IEnumerable<T> other)
179  {
180  throw new NotImplementedException();
181  }
182 
183  #endregion
184  }
185 }
186 
187 #endif