1
|
/*
|
2
|
Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
|
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
of this software and associated documentation files (the "Software"), to deal
|
5
|
in the Software without restriction, including without limitation the rights
|
6
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
copies of the Software, and to permit persons to whom the Software is
|
8
|
furnished to do so, subject to the following conditions:
|
9
|
|
10
|
The above copyright notice and this permission notice shall be included in
|
11
|
all copies or substantial portions of the Software.
|
12
|
|
13
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
SOFTWARE.
|
20
|
*/
|
21
|
|
22
|
using System;
|
23
|
using SCG = System.Collections.Generic;
|
24
|
namespace C5
|
25
|
{
|
26
|
/// <summary>
|
27
|
/// A generic collection, that can be enumerated backwards.
|
28
|
/// </summary>
|
29
|
public interface IDirectedEnumerable<T> : SCG.IEnumerable<T>
|
30
|
{
|
31
|
/// <summary>
|
32
|
/// Create a collection containing the same items as this collection, but
|
33
|
/// whose enumerator will enumerate the items backwards. The new collection
|
34
|
/// will become invalid if the original is modified. Method typically used as in
|
35
|
/// <code>foreach (T x in coll.Backwards()) {...}</code>
|
36
|
/// </summary>
|
37
|
/// <returns>The backwards collection.</returns>
|
38
|
IDirectedEnumerable<T> Backwards();
|
39
|
|
40
|
|
41
|
/// <summary>
|
42
|
/// <code>Forwards</code> if same, else <code>Backwards</code>
|
43
|
/// </summary>
|
44
|
/// <value>The enumeration direction relative to the original collection.</value>
|
45
|
EnumerationDirection Direction { get;}
|
46
|
}
|
47
|
|
48
|
/// <summary>
|
49
|
/// A generic collection that may be enumerated and can answer
|
50
|
/// efficiently how many items it contains. Like <code>IEnumerable<T></code>,
|
51
|
/// this interface does not prescribe any operations to initialize or update the
|
52
|
/// collection. The main usage for this interface is to be the return type of
|
53
|
/// query operations on generic collection.
|
54
|
/// </summary>
|
55
|
public interface ICollectionValue<T> : SCG.IEnumerable<T>, IShowable
|
56
|
{
|
57
|
/// <summary>
|
58
|
/// A flag bitmap of the events subscribable to by this collection.
|
59
|
/// </summary>
|
60
|
/// <value></value>
|
61
|
EventTypeEnum ListenableEvents { get;}
|
62
|
|
63
|
/// <summary>
|
64
|
/// A flag bitmap of the events currently subscribed to by this collection.
|
65
|
/// </summary>
|
66
|
/// <value></value>
|
67
|
EventTypeEnum ActiveEvents { get;}
|
68
|
|
69
|
/// <summary>
|
70
|
/// The change event. Will be raised for every change operation on the collection.
|
71
|
/// </summary>
|
72
|
event CollectionChangedHandler<T> CollectionChanged;
|
73
|
|
74
|
/// <summary>
|
75
|
/// The change event. Will be raised for every clear operation on the collection.
|
76
|
/// </summary>
|
77
|
event CollectionClearedHandler<T> CollectionCleared;
|
78
|
|
79
|
/// <summary>
|
80
|
/// The item added event. Will be raised for every individual addition to the collection.
|
81
|
/// </summary>
|
82
|
event ItemsAddedHandler<T> ItemsAdded;
|
83
|
|
84
|
/// <summary>
|
85
|
/// The item inserted event. Will be raised for every individual insertion to the collection.
|
86
|
/// </summary>
|
87
|
event ItemInsertedHandler<T> ItemInserted;
|
88
|
|
89
|
/// <summary>
|
90
|
/// The item removed event. Will be raised for every individual removal from the collection.
|
91
|
/// </summary>
|
92
|
event ItemsRemovedHandler<T> ItemsRemoved;
|
93
|
|
94
|
/// <summary>
|
95
|
/// The item removed at event. Will be raised for every individual removal at from the collection.
|
96
|
/// </summary>
|
97
|
event ItemRemovedAtHandler<T> ItemRemovedAt;
|
98
|
|
99
|
/// <summary>
|
100
|
///
|
101
|
/// </summary>
|
102
|
/// <value>True if this collection is empty.</value>
|
103
|
bool IsEmpty { get;}
|
104
|
|
105
|
/// <summary>
|
106
|
/// </summary>
|
107
|
/// <value>The number of items in this collection</value>
|
108
|
int Count { get;}
|
109
|
|
110
|
/// <summary>
|
111
|
/// The value is symbolic indicating the type of asymptotic complexity
|
112
|
/// in terms of the size of this collection (worst-case or amortized as
|
113
|
/// relevant).
|
114
|
/// </summary>
|
115
|
/// <value>A characterization of the speed of the
|
116
|
/// <code>Count</code> property in this collection.</value>
|
117
|
Speed CountSpeed { get;}
|
118
|
|
119
|
/// <summary>
|
120
|
/// Copy the items of this collection to a contiguous part of an array.
|
121
|
/// </summary>
|
122
|
/// <param name="array">The array to copy to</param>
|
123
|
/// <param name="index">The index at which to copy the first item</param>
|
124
|
void CopyTo(T[] array, int index);
|
125
|
|
126
|
/// <summary>
|
127
|
/// Create an array with the items of this collection (in the same order as an
|
128
|
/// enumerator would output them).
|
129
|
/// </summary>
|
130
|
/// <returns>The array</returns>
|
131
|
T[] ToArray();
|
132
|
|
133
|
/// <summary>
|
134
|
/// Apply a delegate to all items of this collection.
|
135
|
/// </summary>
|
136
|
/// <param name="action">The delegate to apply</param>
|
137
|
void Apply(Act<T> action);
|
138
|
|
139
|
|
140
|
/// <summary>
|
141
|
/// Check if there exists an item that satisfies a
|
142
|
/// specific predicate in this collection.
|
143
|
/// </summary>
|
144
|
/// <param name="predicate">A delegate
|
145
|
/// (<see cref="T:C5.Fun`2"/> with <code>R == bool</code>) defining the predicate</param>
|
146
|
/// <returns>True is such an item exists</returns>
|
147
|
bool Exists(Fun<T, bool> predicate);
|
148
|
|
149
|
/// <summary>
|
150
|
/// Check if there exists an item that satisfies a
|
151
|
/// specific predicate in this collection and return the first one in enumeration order.
|
152
|
/// </summary>
|
153
|
/// <param name="predicate">A delegate
|
154
|
/// (<see cref="T:C5.Fun`2"/> with <code>R == bool</code>) defining the predicate</param>
|
155
|
/// <param name="item"></param>
|
156
|
/// <returns>True is such an item exists</returns>
|
157
|
bool Find(Fun<T, bool> predicate, out T item);
|
158
|
|
159
|
|
160
|
/// <summary>
|
161
|
/// Check if all items in this collection satisfies a specific predicate.
|
162
|
/// </summary>
|
163
|
/// <param name="predicate">A delegate
|
164
|
/// (<see cref="T:C5.Fun`2"/> with <code>R == bool</code>) defining the predicate</param>
|
165
|
/// <returns>True if all items satisfies the predicate</returns>
|
166
|
bool All(Fun<T, bool> predicate);
|
167
|
|
168
|
/// <summary>
|
169
|
/// Choose some item of this collection.
|
170
|
/// <para>Implementations must assure that the item
|
171
|
/// returned may be efficiently removed.</para>
|
172
|
/// <para>Implementors may decide to implement this method in a way such that repeated
|
173
|
/// calls do not necessarily give the same result, i.e. so that the result of the following
|
174
|
/// test is undetermined:
|
175
|
/// <code>coll.Choose() == coll.Choose()</code></para>
|
176
|
/// </summary>
|
177
|
/// <exception cref="NoSuchItemException">if collection is empty.</exception>
|
178
|
/// <returns></returns>
|
179
|
T Choose();
|
180
|
|
181
|
/// <summary>
|
182
|
/// Create an enumerable, enumerating the items of this collection that satisfies
|
183
|
/// a certain condition.
|
184
|
/// </summary>
|
185
|
/// <param name="filter">The T->bool filter delegate defining the condition</param>
|
186
|
/// <returns>The filtered enumerable</returns>
|
187
|
SCG.IEnumerable<T> Filter(Fun<T, bool> filter);
|
188
|
}
|
189
|
|
190
|
|
191
|
|
192
|
/// <summary>
|
193
|
/// A sized generic collection, that can be enumerated backwards.
|
194
|
/// </summary>
|
195
|
public interface IDirectedCollectionValue<T> : ICollectionValue<T>, IDirectedEnumerable<T>
|
196
|
{
|
197
|
/// <summary>
|
198
|
/// Create a collection containing the same items as this collection, but
|
199
|
/// whose enumerator will enumerate the items backwards. The new collection
|
200
|
/// will become invalid if the original is modified. Method typically used as in
|
201
|
/// <code>foreach (T x in coll.Backwards()) {...}</code>
|
202
|
/// </summary>
|
203
|
/// <returns>The backwards collection.</returns>
|
204
|
new IDirectedCollectionValue<T> Backwards();
|
205
|
|
206
|
/// <summary>
|
207
|
/// Check if there exists an item that satisfies a
|
208
|
/// specific predicate in this collection and return the first one in enumeration order.
|
209
|
/// </summary>
|
210
|
/// <param name="predicate">A delegate
|
211
|
/// (<see cref="T:C5.Fun`2"/> with <code>R == bool</code>) defining the predicate</param>
|
212
|
/// <param name="item"></param>
|
213
|
/// <returns>True is such an item exists</returns>
|
214
|
bool FindLast(Fun<T, bool> predicate, out T item);
|
215
|
}
|
216
|
|
217
|
|
218
|
/// <summary>
|
219
|
/// A generic collection to which one may add items. This is just the intersection
|
220
|
/// of the main stream generic collection interfaces and the priority queue interface,
|
221
|
/// <see cref="T:C5.ICollection`1"/> and <see cref="T:C5.IPriorityQueue`1"/>.
|
222
|
/// </summary>
|
223
|
public interface IExtensible<T> : ICollectionValue<T>, ICloneable
|
224
|
{
|
225
|
/// <summary>
|
226
|
/// If true any call of an updating operation will throw an
|
227
|
/// <code>ReadOnlyCollectionException</code>
|
228
|
/// </summary>
|
229
|
/// <value>True if this collection is read-only.</value>
|
230
|
bool IsReadOnly { get;}
|
231
|
|
232
|
//TODO: wonder where the right position of this is
|
233
|
/// <summary>
|
234
|
///
|
235
|
/// </summary>
|
236
|
/// <value>False if this collection has set semantics, true if bag semantics.</value>
|
237
|
bool AllowsDuplicates { get;}
|
238
|
|
239
|
//TODO: wonder where the right position of this is. And the semantics.
|
240
|
/// <summary>
|
241
|
/// (Here should be a discussion of the role of equalityComparers. Any ).
|
242
|
/// </summary>
|
243
|
/// <value>The equalityComparer used by this collection to check equality of items.
|
244
|
/// Or null (????) if collection does not check equality at all or uses a comparer.</value>
|
245
|
SCG.IEqualityComparer<T> EqualityComparer { get;}
|
246
|
|
247
|
//ItemEqualityTypeEnum ItemEqualityType {get ;}
|
248
|
|
249
|
//TODO: find a good name
|
250
|
|
251
|
/// <summary>
|
252
|
/// By convention this is true for any collection with set semantics.
|
253
|
/// </summary>
|
254
|
/// <value>True if only one representative of a group of equal items
|
255
|
/// is kept in the collection together with the total count.</value>
|
256
|
bool DuplicatesByCounting { get;}
|
257
|
|
258
|
/// <summary>
|
259
|
/// Add an item to this collection if possible. If this collection has set
|
260
|
/// semantics, the item will be added if not already in the collection. If
|
261
|
/// bag semantics, the item will always be added.
|
262
|
/// </summary>
|
263
|
/// <param name="item">The item to add.</param>
|
264
|
/// <returns>True if item was added.</returns>
|
265
|
bool Add(T item);
|
266
|
|
267
|
/// <summary>
|
268
|
/// Add the elements from another collection with a more specialized item type
|
269
|
/// to this collection. If this
|
270
|
/// collection has set semantics, only items not already in the collection
|
271
|
/// will be added.
|
272
|
/// </summary>
|
273
|
/// <typeparam name="U">The type of items to add</typeparam>
|
274
|
/// <param name="items">The items to add</param>
|
275
|
void AddAll<U>(SCG.IEnumerable<U> items) where U : T;
|
276
|
|
277
|
//void Clear(); // for priority queue
|
278
|
//int Count why not?
|
279
|
/// <summary>
|
280
|
/// Check the integrity of the internal data structures of this collection.
|
281
|
/// <i>This is only relevant for developers of the library</i>
|
282
|
/// </summary>
|
283
|
/// <returns>True if check was passed.</returns>
|
284
|
bool Check();
|
285
|
}
|
286
|
|
287
|
/// <summary>
|
288
|
/// The simplest interface of a main stream generic collection
|
289
|
/// with lookup, insertion and removal operations.
|
290
|
/// </summary>
|
291
|
public interface ICollection<T> : IExtensible<T>, SCG.ICollection<T>
|
292
|
{
|
293
|
//This is somewhat similar to the RandomAccess marker itf in java
|
294
|
/// <summary>
|
295
|
/// The value is symbolic indicating the type of asymptotic complexity
|
296
|
/// in terms of the size of this collection (worst-case or amortized as
|
297
|
/// relevant).
|
298
|
/// <para>See <see cref="T:C5.Speed"/> for the set of symbols.</para>
|
299
|
/// </summary>
|
300
|
/// <value>A characterization of the speed of lookup operations
|
301
|
/// (<code>Contains()</code> etc.) of the implementation of this collection.</value>
|
302
|
Speed ContainsSpeed { get;}
|
303
|
|
304
|
/// <summary>
|
305
|
/// </summary>
|
306
|
/// <value>The number of items in this collection</value>
|
307
|
new int Count { get; }
|
308
|
|
309
|
/// <summary>
|
310
|
/// If true any call of an updating operation will throw an
|
311
|
/// <code>ReadOnlyCollectionException</code>
|
312
|
/// </summary>
|
313
|
/// <value>True if this collection is read-only.</value>
|
314
|
new bool IsReadOnly { get; }
|
315
|
|
316
|
/// <summary>
|
317
|
/// Add an item to this collection if possible. If this collection has set
|
318
|
/// semantics, the item will be added if not already in the collection. If
|
319
|
/// bag semantics, the item will always be added.
|
320
|
/// </summary>
|
321
|
/// <param name="item">The item to add.</param>
|
322
|
/// <returns>True if item was added.</returns>
|
323
|
new bool Add(T item);
|
324
|
|
325
|
/// <summary>
|
326
|
/// Copy the items of this collection to a contiguous part of an array.
|
327
|
/// </summary>
|
328
|
/// <param name="array">The array to copy to</param>
|
329
|
/// <param name="index">The index at which to copy the first item</param>
|
330
|
new void CopyTo(T[] array, int index);
|
331
|
|
332
|
/// <summary>
|
333
|
/// The unordered collection hashcode is defined as the sum of
|
334
|
/// <code>h(hashcode(item))</code> over the items
|
335
|
/// of the collection, where the function <code>h</code> is a function from
|
336
|
/// int to int of the form <code> t -> (a0*t+b0)^(a1*t+b1)^(a2*t+b2)</code>, where
|
337
|
/// the ax and bx are the same for all collection classes.
|
338
|
/// <para>The current implementation uses fixed values for the ax and bx,
|
339
|
/// specified as constants in the code.</para>
|
340
|
/// </summary>
|
341
|
/// <returns>The unordered hashcode of this collection.</returns>
|
342
|
int GetUnsequencedHashCode();
|
343
|
|
344
|
|
345
|
/// <summary>
|
346
|
/// Compare the contents of this collection to another one without regards to
|
347
|
/// the sequence order. The comparison will use this collection's itemequalityComparer
|
348
|
/// to compare individual items.
|
349
|
/// </summary>
|
350
|
/// <param name="otherCollection">The collection to compare to.</param>
|
351
|
/// <returns>True if this collection and that contains the same items.</returns>
|
352
|
bool UnsequencedEquals(ICollection<T> otherCollection);
|
353
|
|
354
|
|
355
|
/// <summary>
|
356
|
/// Check if this collection contains (an item equivalent to according to the
|
357
|
/// itemequalityComparer) a particular value.
|
358
|
/// </summary>
|
359
|
/// <param name="item">The value to check for.</param>
|
360
|
/// <returns>True if the items is in this collection.</returns>
|
361
|
new bool Contains(T item);
|
362
|
|
363
|
|
364
|
/// <summary>
|
365
|
/// Count the number of items of the collection equal to a particular value.
|
366
|
/// Returns 0 if and only if the value is not in the collection.
|
367
|
/// </summary>
|
368
|
/// <param name="item">The value to count.</param>
|
369
|
/// <returns>The number of copies found.</returns>
|
370
|
int ContainsCount(T item);
|
371
|
|
372
|
|
373
|
/// <summary>
|
374
|
///
|
375
|
/// </summary>
|
376
|
/// <returns></returns>
|
377
|
ICollectionValue<T> UniqueItems();
|
378
|
|
379
|
/// <summary>
|
380
|
///
|
381
|
/// </summary>
|
382
|
/// <returns></returns>
|
383
|
ICollectionValue<KeyValuePair<T, int>> ItemMultiplicities();
|
384
|
|
385
|
/// <summary>
|
386
|
/// Check whether this collection contains all the values in another collection.
|
387
|
/// If this collection has bag semantics (<code>AllowsDuplicates==true</code>)
|
388
|
/// the check is made with respect to multiplicities, else multiplicities
|
389
|
/// are not taken into account.
|
390
|
/// </summary>
|
391
|
/// <param name="items">The </param>
|
392
|
/// <typeparam name="U"></typeparam>
|
393
|
/// <returns>True if all values in <code>items</code>is in this collection.</returns>
|
394
|
bool ContainsAll<U>(SCG.IEnumerable<U> items) where U : T;
|
395
|
|
396
|
|
397
|
/// <summary>
|
398
|
/// Check if this collection contains an item equivalent according to the
|
399
|
/// itemequalityComparer to a particular value. If so, return in the ref argument (a
|
400
|
/// binary copy of) the actual value found.
|
401
|
/// </summary>
|
402
|
/// <param name="item">The value to look for.</param>
|
403
|
/// <returns>True if the items is in this collection.</returns>
|
404
|
bool Find(ref T item);
|
405
|
|
406
|
|
407
|
//This should probably just be bool Add(ref T item); !!!
|
408
|
/// <summary>
|
409
|
/// Check if this collection contains an item equivalent according to the
|
410
|
/// itemequalityComparer to a particular value. If so, return in the ref argument (a
|
411
|
/// binary copy of) the actual value found. Else, add the item to the collection.
|
412
|
/// </summary>
|
413
|
/// <param name="item">The value to look for.</param>
|
414
|
/// <returns>True if the item was found (hence not added).</returns>
|
415
|
bool FindOrAdd(ref T item);
|
416
|
|
417
|
|
418
|
/// <summary>
|
419
|
/// Check if this collection contains an item equivalent according to the
|
420
|
/// itemequalityComparer to a particular value. If so, update the item in the collection
|
421
|
/// with a (binary copy of) the supplied value. If the collection has bag semantics,
|
422
|
/// it depends on the value of DuplicatesByCounting if this updates all equivalent copies in
|
423
|
/// the collection or just one.
|
424
|
/// </summary>
|
425
|
/// <param name="item">Value to update.</param>
|
426
|
/// <returns>True if the item was found and hence updated.</returns>
|
427
|
bool Update(T item);
|
428
|
|
429
|
/// <summary>
|
430
|
/// Check if this collection contains an item equivalent according to the
|
431
|
/// itemequalityComparer to a particular value. If so, update the item in the collection
|
432
|
/// with a (binary copy of) the supplied value. If the collection has bag semantics,
|
433
|
/// it depends on the value of DuplicatesByCounting if this updates all equivalent copies in
|
434
|
/// the collection or just one.
|
435
|
/// </summary>
|
436
|
/// <param name="item">Value to update.</param>
|
437
|
/// <param name="olditem">On output the olditem, if found.</param>
|
438
|
/// <returns>True if the item was found and hence updated.</returns>
|
439
|
bool Update(T item, out T olditem);
|
440
|
|
441
|
|
442
|
/// <summary>
|
443
|
/// Check if this collection contains an item equivalent according to the
|
444
|
/// itemequalityComparer to a particular value. If so, update the item in the collection
|
445
|
/// to with a binary copy of the supplied value; else add the value to the collection.
|
446
|
/// </summary>
|
447
|
/// <param name="item">Value to add or update.</param>
|
448
|
/// <returns>True if the item was found and updated (hence not added).</returns>
|
449
|
bool UpdateOrAdd(T item);
|
450
|
|
451
|
|
452
|
/// <summary>
|
453
|
/// Check if this collection contains an item equivalent according to the
|
454
|
/// itemequalityComparer to a particular value. If so, update the item in the collection
|
455
|
/// to with a binary copy of the supplied value; else add the value to the collection.
|
456
|
/// </summary>
|
457
|
/// <param name="item">Value to add or update.</param>
|
458
|
/// <param name="olditem">On output the olditem, if found.</param>
|
459
|
/// <returns>True if the item was found and updated (hence not added).</returns>
|
460
|
bool UpdateOrAdd(T item, out T olditem);
|
461
|
|
462
|
/// <summary>
|
463
|
/// Remove a particular item from this collection. If the collection has bag
|
464
|
/// semantics only one copy equivalent to the supplied item is removed.
|
465
|
/// </summary>
|
466
|
/// <param name="item">The value to remove.</param>
|
467
|
/// <returns>True if the item was found (and removed).</returns>
|
468
|
new bool Remove(T item);
|
469
|
|
470
|
|
471
|
/// <summary>
|
472
|
/// Remove a particular item from this collection if found. If the collection
|
473
|
/// has bag semantics only one copy equivalent to the supplied item is removed,
|
474
|
/// which one is implementation dependent.
|
475
|
/// If an item was removed, report a binary copy of the actual item removed in
|
476
|
/// the argument.
|
477
|
/// </summary>
|
478
|
/// <param name="item">The value to remove.</param>
|
479
|
/// <param name="removeditem">The value removed if any.</param>
|
480
|
/// <returns>True if the item was found (and removed).</returns>
|
481
|
bool Remove(T item, out T removeditem);
|
482
|
|
483
|
|
484
|
/// <summary>
|
485
|
/// Remove all items equivalent to a given value.
|
486
|
/// </summary>
|
487
|
/// <param name="item">The value to remove.</param>
|
488
|
void RemoveAllCopies(T item);
|
489
|
|
490
|
|
491
|
/// <summary>
|
492
|
/// Remove all items in another collection from this one. If this collection
|
493
|
/// has bag semantics, take multiplicities into account.
|
494
|
/// </summary>
|
495
|
/// <typeparam name="U"></typeparam>
|
496
|
/// <param name="items">The items to remove.</param>
|
497
|
void RemoveAll<U>(SCG.IEnumerable<U> items) where U : T;
|
498
|
|
499
|
//void RemoveAll(Fun<T, bool> predicate);
|
500
|
|
501
|
/// <summary>
|
502
|
/// Remove all items from this collection.
|
503
|
/// </summary>
|
504
|
new void Clear();
|
505
|
|
506
|
|
507
|
/// <summary>
|
508
|
/// Remove all items not in some other collection from this one. If this collection
|
509
|
/// has bag semantics, take multiplicities into account.
|
510
|
/// </summary>
|
511
|
/// <typeparam name="U"></typeparam>
|
512
|
/// <param name="items">The items to retain.</param>
|
513
|
void RetainAll<U>(SCG.IEnumerable<U> items) where U : T;
|
514
|
|
515
|
//void RetainAll(Fun<T, bool> predicate);
|
516
|
//IDictionary<T> UniqueItems()
|
517
|
}
|
518
|
|
519
|
|
520
|
|
521
|
/// <summary>
|
522
|
/// An editable collection maintaining a definite sequence order of the items.
|
523
|
///
|
524
|
/// <i>Implementations of this interface must compute the hash code and
|
525
|
/// equality exactly as prescribed in the method definitions in order to
|
526
|
/// be consistent with other collection classes implementing this interface.</i>
|
527
|
/// <i>This interface is usually implemented by explicit interface implementation,
|
528
|
/// not as ordinary virtual methods.</i>
|
529
|
/// </summary>
|
530
|
public interface ISequenced<T> : ICollection<T>, IDirectedCollectionValue<T>
|
531
|
{
|
532
|
/// <summary>
|
533
|
/// The hashcode is defined as <code>h(...h(h(h(x1),x2),x3),...,xn)</code> for
|
534
|
/// <code>h(a,b)=CONSTANT*a+b</code> and the x's the hash codes of the items of
|
535
|
/// this collection.
|
536
|
/// </summary>
|
537
|
/// <returns>The sequence order hashcode of this collection.</returns>
|
538
|
int GetSequencedHashCode();
|
539
|
|
540
|
|
541
|
/// <summary>
|
542
|
/// Compare this sequenced collection to another one in sequence order.
|
543
|
/// </summary>
|
544
|
/// <param name="otherCollection">The sequenced collection to compare to.</param>
|
545
|
/// <returns>True if this collection and that contains equal (according to
|
546
|
/// this collection's itemequalityComparer) in the same sequence order.</returns>
|
547
|
bool SequencedEquals(ISequenced<T> otherCollection);
|
548
|
}
|
549
|
|
550
|
|
551
|
|
552
|
/// <summary>
|
553
|
/// A sequenced collection, where indices of items in the order are maintained
|
554
|
/// </summary>
|
555
|
public interface IIndexed<T> : ISequenced<T>
|
556
|
{
|
557
|
/// <summary>
|
558
|
/// </summary>
|
559
|
/// <exception cref="IndexOutOfRangeException"> if <code>index</code> is negative or
|
560
|
/// >= the size of the collection.</exception>
|
561
|
/// <value>The <code>index</code>'th item of this list.</value>
|
562
|
/// <param name="index">the index to lookup</param>
|
563
|
T this[int index] { get;}
|
564
|
|
565
|
/// <summary>
|
566
|
///
|
567
|
/// </summary>
|
568
|
/// <value></value>
|
569
|
Speed IndexingSpeed { get;}
|
570
|
|
571
|
/// <summary>
|
572
|
/// </summary>
|
573
|
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
574
|
/// <value>The directed collection of items in a specific index interval.</value>
|
575
|
/// <param name="start">The low index of the interval (inclusive).</param>
|
576
|
/// <param name="count">The size of the range.</param>
|
577
|
IDirectedCollectionValue<T> this[int start, int count] { get;}
|
578
|
|
579
|
|
580
|
/// <summary>
|
581
|
/// Searches for an item in the list going forwards from the start.
|
582
|
/// </summary>
|
583
|
/// <param name="item">Item to search for.</param>
|
584
|
/// <returns>Index of item from start. A negative number if item not found,
|
585
|
/// namely the one's complement of the index at which the Add operation would put the item.</returns>
|
586
|
int IndexOf(T item);
|
587
|
|
588
|
|
589
|
/// <summary>
|
590
|
/// Searches for an item in the list going backwards from the end.
|
591
|
/// </summary>
|
592
|
/// <param name="item">Item to search for.</param>
|
593
|
/// <returns>Index of of item from the end. A negative number if item not found,
|
594
|
/// namely the two-complement of the index at which the Add operation would put the item.</returns>
|
595
|
int LastIndexOf(T item);
|
596
|
|
597
|
/// <summary>
|
598
|
/// Check if there exists an item that satisfies a
|
599
|
/// specific predicate in this collection and return the index of the first one.
|
600
|
/// </summary>
|
601
|
/// <param name="predicate">A delegate
|
602
|
/// (<see cref="T:C5.Fun`2"/> with <code>R == bool</code>) defining the predicate</param>
|
603
|
/// <returns>the index, if found, a negative value else</returns>
|
604
|
int FindIndex(Fun<T, bool> predicate);
|
605
|
|
606
|
/// <summary>
|
607
|
/// Check if there exists an item that satisfies a
|
608
|
/// specific predicate in this collection and return the index of the last one.
|
609
|
/// </summary>
|
610
|
/// <param name="predicate">A delegate
|
611
|
/// (<see cref="T:C5.Fun`2"/> with <code>R == bool</code>) defining the predicate</param>
|
612
|
/// <returns>the index, if found, a negative value else</returns>
|
613
|
int FindLastIndex(Fun<T, bool> predicate);
|
614
|
|
615
|
|
616
|
/// <summary>
|
617
|
/// Remove the item at a specific position of the list.
|
618
|
/// </summary>
|
619
|
/// <exception cref="IndexOutOfRangeException"> if <code>index</code> is negative or
|
620
|
/// >= the size of the collection.</exception>
|
621
|
/// <param name="index">The index of the item to remove.</param>
|
622
|
/// <returns>The removed item.</returns>
|
623
|
T RemoveAt(int index);
|
624
|
|
625
|
|
626
|
/// <summary>
|
627
|
/// Remove all items in an index interval.
|
628
|
/// </summary>
|
629
|
/// <exception cref="ArgumentOutOfRangeException"> if start or count
|
630
|
/// is negative or start+count > the size of the collection.</exception>
|
631
|
/// <param name="start">The index of the first item to remove.</param>
|
632
|
/// <param name="count">The number of items to remove.</param>
|
633
|
void RemoveInterval(int start, int count);
|
634
|
}
|
635
|
|
636
|
//TODO: decide if this should extend ICollection
|
637
|
/// <summary>
|
638
|
/// The interface describing the operations of a LIFO stack data structure.
|
639
|
/// </summary>
|
640
|
/// <typeparam name="T">The item type</typeparam>
|
641
|
public interface IStack<T> : IDirectedCollectionValue<T>
|
642
|
{
|
643
|
/// <summary>
|
644
|
///
|
645
|
/// </summary>
|
646
|
/// <value></value>
|
647
|
bool AllowsDuplicates { get;}
|
648
|
/// <summary>
|
649
|
/// Get the <code>index</code>'th element of the stack. The bottom of the stack has index 0.
|
650
|
/// </summary>
|
651
|
/// <param name="index"></param>
|
652
|
/// <returns></returns>
|
653
|
T this[int index] { get;}
|
654
|
/// <summary>
|
655
|
/// Push an item to the top of the stack.
|
656
|
/// </summary>
|
657
|
/// <param name="item">The item</param>
|
658
|
void Push(T item);
|
659
|
/// <summary>
|
660
|
/// Pop the item at the top of the stack from the stack.
|
661
|
/// </summary>
|
662
|
/// <returns>The popped item.</returns>
|
663
|
T Pop();
|
664
|
}
|
665
|
|
666
|
/// <summary>
|
667
|
/// The interface describing the operations of a FIFO queue data structure.
|
668
|
/// </summary>
|
669
|
/// <typeparam name="T">The item type</typeparam>
|
670
|
public interface IQueue<T> : IDirectedCollectionValue<T>
|
671
|
{
|
672
|
/// <summary>
|
673
|
///
|
674
|
/// </summary>
|
675
|
/// <value></value>
|
676
|
bool AllowsDuplicates { get;}
|
677
|
/// <summary>
|
678
|
/// Get the <code>index</code>'th element of the queue. The front of the queue has index 0.
|
679
|
/// </summary>
|
680
|
/// <param name="index"></param>
|
681
|
/// <returns></returns>
|
682
|
T this[int index] { get;}
|
683
|
/// <summary>
|
684
|
/// Enqueue an item at the back of the queue.
|
685
|
/// </summary>
|
686
|
/// <param name="item">The item</param>
|
687
|
void Enqueue(T item);
|
688
|
/// <summary>
|
689
|
/// Dequeue an item from the front of the queue.
|
690
|
/// </summary>
|
691
|
/// <returns>The item</returns>
|
692
|
T Dequeue();
|
693
|
}
|
694
|
|
695
|
|
696
|
/// <summary>
|
697
|
/// This is an indexed collection, where the item order is chosen by
|
698
|
/// the user at insertion time.
|
699
|
///
|
700
|
/// NBNBNB: we need a description of the view functionality here!
|
701
|
/// </summary>
|
702
|
public interface IList<T> : IIndexed<T>, IDisposable, SCG.IList<T>, System.Collections.IList
|
703
|
{
|
704
|
/// <summary>
|
705
|
/// </summary>
|
706
|
/// <exception cref="NoSuchItemException"> if this list is empty.</exception>
|
707
|
/// <value>The first item in this list.</value>
|
708
|
T First { get;}
|
709
|
|
710
|
/// <summary>
|
711
|
/// </summary>
|
712
|
/// <exception cref="NoSuchItemException"> if this list is empty.</exception>
|
713
|
/// <value>The last item in this list.</value>
|
714
|
T Last { get;}
|
715
|
|
716
|
/// <summary>
|
717
|
/// Since <code>Add(T item)</code> always add at the end of the list,
|
718
|
/// this describes if list has FIFO or LIFO semantics.
|
719
|
/// </summary>
|
720
|
/// <value>True if the <code>Remove()</code> operation removes from the
|
721
|
/// start of the list, false if it removes from the end.</value>
|
722
|
bool FIFO { get; set;}
|
723
|
|
724
|
/// <summary>
|
725
|
///
|
726
|
/// </summary>
|
727
|
bool IsFixedSize { get; }
|
728
|
|
729
|
/// <summary>
|
730
|
/// On this list, this indexer is read/write.
|
731
|
/// </summary>
|
732
|
/// <exception cref="IndexOutOfRangeException"> if index is negative or
|
733
|
/// >= the size of the collection.</exception>
|
734
|
/// <value>The index'th item of this list.</value>
|
735
|
/// <param name="index">The index of the item to fetch or store.</param>
|
736
|
new T this[int index] { get; set;}
|
737
|
|
738
|
#region Ambiguous calls when extending SCG.IList<T>
|
739
|
|
740
|
#region SCG.ICollection<T>
|
741
|
/// <summary>
|
742
|
///
|
743
|
/// </summary>
|
744
|
new int Count { get; }
|
745
|
|
746
|
/// <summary>
|
747
|
///
|
748
|
/// </summary>
|
749
|
new bool IsReadOnly { get; }
|
750
|
|
751
|
/// <summary>
|
752
|
///
|
753
|
/// </summary>
|
754
|
/// <param name="item"></param>
|
755
|
/// <returns></returns>
|
756
|
new bool Add(T item);
|
757
|
|
758
|
/// <summary>
|
759
|
///
|
760
|
/// </summary>
|
761
|
new void Clear();
|
762
|
|
763
|
/// <summary>
|
764
|
///
|
765
|
/// </summary>
|
766
|
/// <param name="item"></param>
|
767
|
/// <returns></returns>
|
768
|
new bool Contains(T item);
|
769
|
|
770
|
/// <summary>
|
771
|
///
|
772
|
/// </summary>
|
773
|
/// <param name="array"></param>
|
774
|
/// <param name="index"></param>
|
775
|
new void CopyTo(T[] array, int index);
|
776
|
|
777
|
/// <summary>
|
778
|
///
|
779
|
/// </summary>
|
780
|
/// <param name="item"></param>
|
781
|
/// <returns></returns>
|
782
|
new bool Remove(T item);
|
783
|
|
784
|
#endregion
|
785
|
|
786
|
#region SCG.IList<T> proper
|
787
|
|
788
|
/// <summary>
|
789
|
/// Searches for an item in the list going forwards from the start.
|
790
|
/// </summary>
|
791
|
/// <param name="item">Item to search for.</param>
|
792
|
/// <returns>Index of item from start. A negative number if item not found,
|
793
|
/// namely the one's complement of the index at which the Add operation would put the item.</returns>
|
794
|
new int IndexOf(T item);
|
795
|
|
796
|
/// <summary>
|
797
|
/// Remove the item at a specific position of the list.
|
798
|
/// </summary>
|
799
|
/// <exception cref="IndexOutOfRangeException"> if <code>index</code> is negative or
|
800
|
/// >= the size of the collection.</exception>
|
801
|
/// <param name="index">The index of the item to remove.</param>
|
802
|
/// <returns>The removed item.</returns>
|
803
|
new T RemoveAt(int index);
|
804
|
|
805
|
#endregion
|
806
|
|
807
|
#endregion
|
808
|
|
809
|
/*/// <summary>
|
810
|
/// Insert an item at a specific index location in this list.
|
811
|
/// </summary>
|
812
|
/// <exception cref="IndexOutOfRangeException"> if <code>index</code> is negative or
|
813
|
/// > the size of the collection.</exception>
|
814
|
/// <exception cref="DuplicateNotAllowedException"> if the list has
|
815
|
/// <code>AllowsDuplicates==false</code> and the item is
|
816
|
/// already in the list.</exception>
|
817
|
/// <param name="index">The index at which to insert.</param>
|
818
|
/// <param name="item">The item to insert.</param>
|
819
|
void Insert(int index, T item);*/
|
820
|
|
821
|
/// <summary>
|
822
|
/// Insert an item at the end of a compatible view, used as a pointer.
|
823
|
/// <para>The <code>pointer</code> must be a view on the same list as
|
824
|
/// <code>this</code> and the endpoitn of <code>pointer</code> must be
|
825
|
/// a valid insertion point of <code>this</code></para>
|
826
|
/// </summary>
|
827
|
/// <exception cref="IncompatibleViewException">If <code>pointer</code>
|
828
|
/// is not a view on the same list as <code>this</code></exception>
|
829
|
/// <exception cref="IndexOutOfRangeException"><b>??????</b> if the endpoint of
|
830
|
/// <code>pointer</code> is not inside <code>this</code></exception>
|
831
|
/// <exception cref="DuplicateNotAllowedException"> if the list has
|
832
|
/// <code>AllowsDuplicates==false</code> and the item is
|
833
|
/// already in the list.</exception>
|
834
|
/// <param name="pointer"></param>
|
835
|
/// <param name="item"></param>
|
836
|
void Insert(IList<T> pointer, T item);
|
837
|
|
838
|
/// <summary>
|
839
|
/// Insert an item at the front of this list.
|
840
|
/// <exception cref="DuplicateNotAllowedException"/> if the list has
|
841
|
/// <code>AllowsDuplicates==false</code> and the item is
|
842
|
/// already in the list.
|
843
|
/// </summary>
|
844
|
/// <param name="item">The item to insert.</param>
|
845
|
void InsertFirst(T item);
|
846
|
|
847
|
/// <summary>
|
848
|
/// Insert an item at the back of this list.
|
849
|
/// <exception cref="DuplicateNotAllowedException"/> if the list has
|
850
|
/// <code>AllowsDuplicates==false</code> and the item is
|
851
|
/// already in the list.
|
852
|
/// </summary>
|
853
|
/// <param name="item">The item to insert.</param>
|
854
|
void InsertLast(T item);
|
855
|
|
856
|
/// <summary>
|
857
|
/// Insert into this list all items from an enumerable collection starting
|
858
|
/// at a particular index.
|
859
|
/// </summary>
|
860
|
/// <exception cref="IndexOutOfRangeException"> if <code>index</code> is negative or
|
861
|
/// > the size of the collection.</exception>
|
862
|
/// <exception cref="DuplicateNotAllowedException"> if the list has
|
863
|
/// <code>AllowsDuplicates==false</code> and one of the items to insert is
|
864
|
/// already in the list.</exception>
|
865
|
/// <param name="index">Index to start inserting at</param>
|
866
|
/// <param name="items">Items to insert</param>
|
867
|
/// <typeparam name="U"></typeparam>
|
868
|
void InsertAll<U>(int index, SCG.IEnumerable<U> items) where U : T;
|
869
|
|
870
|
/// <summary>
|
871
|
/// Create a new list consisting of the items of this list satisfying a
|
872
|
/// certain predicate.
|
873
|
/// </summary>
|
874
|
/// <param name="filter">The filter delegate defining the predicate.</param>
|
875
|
/// <returns>The new list.</returns>
|
876
|
IList<T> FindAll(Fun<T, bool> filter);
|
877
|
|
878
|
/// <summary>
|
879
|
/// Create a new list consisting of the results of mapping all items of this
|
880
|
/// list. The new list will use the default equalityComparer for the item type V.
|
881
|
/// </summary>
|
882
|
/// <typeparam name="V">The type of items of the new list</typeparam>
|
883
|
/// <param name="mapper">The delegate defining the map.</param>
|
884
|
/// <returns>The new list.</returns>
|
885
|
IList<V> Map<V>(Fun<T, V> mapper);
|
886
|
|
887
|
/// <summary>
|
888
|
/// Create a new list consisting of the results of mapping all items of this
|
889
|
/// list. The new list will use a specified equalityComparer for the item type.
|
890
|
/// </summary>
|
891
|
/// <typeparam name="V">The type of items of the new list</typeparam>
|
892
|
/// <param name="mapper">The delegate defining the map.</param>
|
893
|
/// <param name="equalityComparer">The equalityComparer to use for the new list</param>
|
894
|
/// <returns>The new list.</returns>
|
895
|
IList<V> Map<V>(Fun<T, V> mapper, SCG.IEqualityComparer<V> equalityComparer);
|
896
|
|
897
|
/// <summary>
|
898
|
/// Remove one item from the list: from the front if <code>FIFO</code>
|
899
|
/// is true, else from the back.
|
900
|
/// <exception cref="NoSuchItemException"/> if this list is empty.
|
901
|
/// </summary>
|
902
|
/// <returns>The removed item.</returns>
|
903
|
T Remove();
|
904
|
|
905
|
/// <summary>
|
906
|
/// Remove one item from the front of the list.
|
907
|
/// <exception cref="NoSuchItemException"/> if this list is empty.
|
908
|
/// </summary>
|
909
|
/// <returns>The removed item.</returns>
|
910
|
T RemoveFirst();
|
911
|
|
912
|
/// <summary>
|
913
|
/// Remove one item from the back of the list.
|
914
|
/// <exception cref="NoSuchItemException"/> if this list is empty.
|
915
|
/// </summary>
|
916
|
/// <returns>The removed item.</returns>
|
917
|
T RemoveLast();
|
918
|
|
919
|
/// <summary>
|
920
|
/// Create a list view on this list.
|
921
|
/// <exception cref="ArgumentOutOfRangeException"/> if the view would not fit into
|
922
|
/// this list.
|
923
|
/// </summary>
|
924
|
/// <param name="start">The index in this list of the start of the view.</param>
|
925
|
/// <param name="count">The size of the view.</param>
|
926
|
/// <returns>The new list view.</returns>
|
927
|
IList<T> View(int start, int count);
|
928
|
|
929
|
/// <summary>
|
930
|
/// Create a list view on this list containing the (first) occurrence of a particular item.
|
931
|
/// <exception cref="NoSuchItemException"/> if the item is not in this list.
|
932
|
/// </summary>
|
933
|
/// <param name="item">The item to find.</param>
|
934
|
/// <returns>The new list view.</returns>
|
935
|
IList<T> ViewOf(T item);
|
936
|
|
937
|
/// <summary>
|
938
|
/// Create a list view on this list containing the last occurrence of a particular item.
|
939
|
/// <exception cref="NoSuchItemException"/> if the item is not in this list.
|
940
|
/// </summary>
|
941
|
/// <param name="item">The item to find.</param>
|
942
|
/// <returns>The new list view.</returns>
|
943
|
IList<T> LastViewOf(T item);
|
944
|
|
945
|
/// <summary>
|
946
|
/// Null if this list is not a view.
|
947
|
/// </summary>
|
948
|
/// <value>Underlying list for view.</value>
|
949
|
IList<T> Underlying { get;}
|
950
|
|
951
|
/// <summary>
|
952
|
/// </summary>
|
953
|
/// <value>Offset for this list view or 0 for an underlying list.</value>
|
954
|
int Offset { get;}
|
955
|
|
956
|
/// <summary>
|
957
|
///
|
958
|
/// </summary>
|
959
|
/// <value></value>
|
960
|
bool IsValid { get;}
|
961
|
|
962
|
/// <summary>
|
963
|
/// Slide this list view along the underlying list.
|
964
|
/// </summary>
|
965
|
/// <exception cref="NotAViewException"> if this list is not a view.</exception>
|
966
|
/// <exception cref="ArgumentOutOfRangeException"> if the operation
|
967
|
/// would bring either end of the view outside the underlying list.</exception>
|
968
|
/// <param name="offset">The signed amount to slide: positive to slide
|
969
|
/// towards the end.</param>
|
970
|
IList<T> Slide(int offset);
|
971
|
|
972
|
/// <summary>
|
973
|
/// Slide this list view along the underlying list, changing its size.
|
974
|
///
|
975
|
/// </summary>
|
976
|
/// <exception cref="NotAViewException"> if this list is not a view.</exception>
|
977
|
/// <exception cref="ArgumentOutOfRangeException"> if the operation
|
978
|
/// would bring either end of the view outside the underlying list.</exception>
|
979
|
/// <param name="offset">The signed amount to slide: positive to slide
|
980
|
/// towards the end.</param>
|
981
|
/// <param name="size">The new size of the view.</param>
|
982
|
IList<T> Slide(int offset, int size);
|
983
|
|
984
|
/// <summary>
|
985
|
///
|
986
|
/// </summary>
|
987
|
/// <param name="offset"></param>
|
988
|
/// <returns></returns>
|
989
|
bool TrySlide(int offset);
|
990
|
|
991
|
/// <summary>
|
992
|
///
|
993
|
/// </summary>
|
994
|
/// <param name="offset"></param>
|
995
|
/// <param name="size"></param>
|
996
|
/// <returns></returns>
|
997
|
bool TrySlide(int offset, int size);
|
998
|
|
999
|
/// <summary>
|
1000
|
///
|
1001
|
/// <para>Returns null if <code>otherView</code> is strictly to the left of this view</para>
|
1002
|
/// </summary>
|
1003
|
/// <param name="otherView"></param>
|
1004
|
/// <exception cref="IncompatibleViewException">If otherView does not have the same underlying list as this</exception>
|
1005
|
/// <exception cref="ArgumentOutOfRangeException">If <code>otherView</code> is strictly to the left of this view</exception>
|
1006
|
/// <returns></returns>
|
1007
|
IList<T> Span(IList<T> otherView);
|
1008
|
|
1009
|
/// <summary>
|
1010
|
/// Reverse the list so the items are in the opposite sequence order.
|
1011
|
/// </summary>
|
1012
|
void Reverse();
|
1013
|
|
1014
|
/// <summary>
|
1015
|
/// Check if this list is sorted according to the default sorting order
|
1016
|
/// for the item type T, as defined by the <see cref="T:C5.Comparer`1"/> class
|
1017
|
/// </summary>
|
1018
|
/// <exception cref="NotComparableException">if T is not comparable</exception>
|
1019
|
/// <returns>True if the list is sorted, else false.</returns>
|
1020
|
bool IsSorted();
|
1021
|
|
1022
|
/// <summary>
|
1023
|
/// Check if this list is sorted according to a specific sorting order.
|
1024
|
/// </summary>
|
1025
|
/// <param name="comparer">The comparer defining the sorting order.</param>
|
1026
|
/// <returns>True if the list is sorted, else false.</returns>
|
1027
|
bool IsSorted(SCG.IComparer<T> comparer);
|
1028
|
|
1029
|
/// <summary>
|
1030
|
/// Sort the items of the list according to the default sorting order
|
1031
|
/// for the item type T, as defined by the <see cref="T:C5.Comparer`1"/> class
|
1032
|
/// </summary>
|
1033
|
/// <exception cref="NotComparableException">if T is not comparable</exception>
|
1034
|
void Sort();
|
1035
|
|
1036
|
/// <summary>
|
1037
|
/// Sort the items of the list according to a specified sorting order.
|
1038
|
/// <para>The sorting does not perform duplicate elimination or identify items
|
1039
|
/// according to the comparer or itemequalityComparer. I.e. the list as an
|
1040
|
/// unsequenced collection with binary equality, will not change.
|
1041
|
/// </para>
|
1042
|
/// </summary>
|
1043
|
/// <param name="comparer">The comparer defining the sorting order.</param>
|
1044
|
void Sort(SCG.IComparer<T> comparer);
|
1045
|
|
1046
|
|
1047
|
/// <summary>
|
1048
|
/// Randomly shuffle the items of this list.
|
1049
|
/// </summary>
|
1050
|
void Shuffle();
|
1051
|
|
1052
|
|
1053
|
/// <summary>
|
1054
|
/// Shuffle the items of this list according to a specific random source.
|
1055
|
/// </summary>
|
1056
|
/// <param name="rnd">The random source.</param>
|
1057
|
void Shuffle(Random rnd);
|
1058
|
}
|
1059
|
|
1060
|
|
1061
|
/// <summary>
|
1062
|
/// The base type of a priority queue handle
|
1063
|
/// </summary>
|
1064
|
/// <typeparam name="T"></typeparam>
|
1065
|
public interface IPriorityQueueHandle<T>
|
1066
|
{
|
1067
|
//TODO: make abstract and prepare for double dispatch:
|
1068
|
//public virtual bool Delete(IPriorityQueue<T> q) { throw new InvalidFooException();}
|
1069
|
//bool Replace(T item);
|
1070
|
}
|
1071
|
|
1072
|
|
1073
|
/// <summary>
|
1074
|
/// A generic collection of items prioritized by a comparison (order) relation.
|
1075
|
/// Supports adding items and reporting or removing extremal elements.
|
1076
|
/// <para>
|
1077
|
///
|
1078
|
/// </para>
|
1079
|
/// When adding an item, the user may choose to have a handle allocated for this item in the queue.
|
1080
|
/// The resulting handle may be used for deleting the item even if not extremal, and for replacing the item.
|
1081
|
/// A priority queue typically only holds numeric priorities associated with some objects
|
1082
|
/// maintained separately in other collection objects.
|
1083
|
/// </summary>
|
1084
|
public interface IPriorityQueue<T> : IExtensible<T>
|
1085
|
{
|
1086
|
/// <summary>
|
1087
|
/// Find the current least item of this priority queue.
|
1088
|
/// </summary>
|
1089
|
/// <returns>The least item.</returns>
|
1090
|
T FindMin();
|
1091
|
|
1092
|
|
1093
|
/// <summary>
|
1094
|
/// Remove the least item from this priority queue.
|
1095
|
/// </summary>
|
1096
|
/// <returns>The removed item.</returns>
|
1097
|
T DeleteMin();
|
1098
|
|
1099
|
|
1100
|
/// <summary>
|
1101
|
/// Find the current largest item of this priority queue.
|
1102
|
/// </summary>
|
1103
|
/// <returns>The largest item.</returns>
|
1104
|
T FindMax();
|
1105
|
|
1106
|
|
1107
|
/// <summary>
|
1108
|
/// Remove the largest item from this priority queue.
|
1109
|
/// </summary>
|
1110
|
/// <returns>The removed item.</returns>
|
1111
|
T DeleteMax();
|
1112
|
|
1113
|
/// <summary>
|
1114
|
/// The comparer object supplied at creation time for this collection
|
1115
|
/// </summary>
|
1116
|
/// <value>The comparer</value>
|
1117
|
SCG.IComparer<T> Comparer { get;}
|
1118
|
/// <summary>
|
1119
|
/// Get or set the item corresponding to a handle. Throws exceptions on
|
1120
|
/// invalid handles.
|
1121
|
/// </summary>
|
1122
|
/// <param name="handle"></param>
|
1123
|
/// <returns></returns>
|
1124
|
T this[IPriorityQueueHandle<T> handle] { get; set;}
|
1125
|
|
1126
|
/// <summary>
|
1127
|
/// Check if the entry corresponding to a handle is in the priority queue.
|
1128
|
/// </summary>
|
1129
|
/// <param name="handle"></param>
|
1130
|
/// <param name="item"></param>
|
1131
|
/// <returns></returns>
|
1132
|
bool Find(IPriorityQueueHandle<T> handle, out T item);
|
1133
|
|
1134
|
/// <summary>
|
1135
|
/// Add an item to the priority queue, receiving a
|
1136
|
/// handle for the item in the queue,
|
1137
|
/// or reusing an existing unused handle.
|
1138
|
/// </summary>
|
1139
|
/// <param name="handle">On output: a handle for the added item.
|
1140
|
/// On input: null for allocating a new handle, or a currently unused handle for reuse.
|
1141
|
/// A handle for reuse must be compatible with this priority queue,
|
1142
|
/// by being created by a priority queue of the same runtime type, but not
|
1143
|
/// necessarily the same priority queue object.</param>
|
1144
|
/// <param name="item"></param>
|
1145
|
/// <returns></returns>
|
1146
|
bool Add(ref IPriorityQueueHandle<T> handle, T item);
|
1147
|
|
1148
|
/// <summary>
|
1149
|
/// Delete an item with a handle from a priority queue
|
1150
|
/// </summary>
|
1151
|
/// <param name="handle">The handle for the item. The handle will be invalidated, but reusable.</param>
|
1152
|
/// <returns>The deleted item</returns>
|
1153
|
T Delete(IPriorityQueueHandle<T> handle);
|
1154
|
|
1155
|
/// <summary>
|
1156
|
/// Replace an item with a handle in a priority queue with a new item.
|
1157
|
/// Typically used for changing the priority of some queued object.
|
1158
|
/// </summary>
|
1159
|
/// <param name="handle">The handle for the old item</param>
|
1160
|
/// <param name="item">The new item</param>
|
1161
|
/// <returns>The old item</returns>
|
1162
|
T Replace(IPriorityQueueHandle<T> handle, T item);
|
1163
|
|
1164
|
/// <summary>
|
1165
|
/// Find the current least item of this priority queue.
|
1166
|
/// </summary>
|
1167
|
/// <param name="handle">On return: the handle of the item.</param>
|
1168
|
/// <returns>The least item.</returns>
|
1169
|
T FindMin(out IPriorityQueueHandle<T> handle);
|
1170
|
|
1171
|
/// <summary>
|
1172
|
/// Find the current largest item of this priority queue.
|
1173
|
/// </summary>
|
1174
|
/// <param name="handle">On return: the handle of the item.</param>
|
1175
|
/// <returns>The largest item.</returns>
|
1176
|
|
1177
|
T FindMax(out IPriorityQueueHandle<T> handle);
|
1178
|
|
1179
|
/// <summary>
|
1180
|
/// Remove the least item from this priority queue.
|
1181
|
/// </summary>
|
1182
|
/// <param name="handle">On return: the handle of the removed item.</param>
|
1183
|
/// <returns>The removed item.</returns>
|
1184
|
|
1185
|
T DeleteMin(out IPriorityQueueHandle<T> handle);
|
1186
|
|
1187
|
/// <summary>
|
1188
|
/// Remove the largest item from this priority queue.
|
1189
|
/// </summary>
|
1190
|
/// <param name="handle">On return: the handle of the removed item.</param>
|
1191
|
/// <returns>The removed item.</returns>
|
1192
|
T DeleteMax(out IPriorityQueueHandle<T> handle);
|
1193
|
}
|
1194
|
|
1195
|
|
1196
|
|
1197
|
/// <summary>
|
1198
|
/// A sorted collection, i.e. a collection where items are maintained and can be searched for in sorted order.
|
1199
|
/// Thus the sequence order is given as a sorting order.
|
1200
|
///
|
1201
|
/// <para>The sorting order is defined by a comparer, an object of type IComparer<T>
|
1202
|
/// (<see cref="T:C5.IComparer`1"/>). Implementors of this interface will normally let the user
|
1203
|
/// define the comparer as an argument to a constructor.
|
1204
|
/// Usually there will also be constructors without a comparer argument, in which case the
|
1205
|
/// comparer should be the defalt comparer for the item type, <see cref="P:C5.Comparer`1.Default"/>.</para>
|
1206
|
///
|
1207
|
/// <para>The comparer of the sorted collection is available as the <code>Comparer</code> property
|
1208
|
/// (<see cref="P:C5.ISorted`1.Comparer"/>).</para>
|
1209
|
///
|
1210
|
/// <para>The methods are grouped according to
|
1211
|
/// <list>
|
1212
|
/// <item>Extrema: report or report and delete an extremal item. This is reminiscent of simplified priority queues.</item>
|
1213
|
/// <item>Nearest neighbor: report predecessor or successor in the collection of an item. Cut belongs to this group.</item>
|
1214
|
/// <item>Range: report a view of a range of elements or remove all elements in a range.</item>
|
1215
|
/// <item>AddSorted: add a collection of items known to be sorted in the same order (should be faster) (to be removed?)</item>
|
1216
|
/// </list>
|
1217
|
/// </para>
|
1218
|
///
|
1219
|
/// <para>Since this interface extends ISequenced<T>, sorted collections will also have an
|
1220
|
/// item equalityComparer (<see cref="P:C5.IExtensible`1.EqualityComparer"/>). This equalityComparer will not be used in connection with
|
1221
|
/// the inner workings of the sorted collection, but will be used if the sorted collection is used as
|
1222
|
/// an item in a collection of unsequenced or sequenced collections,
|
1223
|
/// (<see cref="T:C5.ICollection`1"/> and <see cref="T:C5.ISequenced`1"/>)</para>
|
1224
|
///
|
1225
|
/// <para>Note that code may check if two sorted collections has the same sorting order
|
1226
|
/// by checking if the Comparer properties are equal. This is done a few places in this library
|
1227
|
/// for optimization purposes.</para>
|
1228
|
/// </summary>
|
1229
|
public interface ISorted<T> : ISequenced<T>
|
1230
|
{
|
1231
|
/// <summary>
|
1232
|
/// Find the current least item of this sorted collection.
|
1233
|
/// </summary>
|
1234
|
/// <exception cref="NoSuchItemException"> if the collection is empty.</exception>
|
1235
|
/// <returns>The least item.</returns>
|
1236
|
T FindMin();
|
1237
|
|
1238
|
|
1239
|
/// <summary>
|
1240
|
/// Remove the least item from this sorted collection.
|
1241
|
/// </summary>
|
1242
|
/// <exception cref="NoSuchItemException"> if the collection is empty.</exception>
|
1243
|
/// <returns>The removed item.</returns>
|
1244
|
T DeleteMin();
|
1245
|
|
1246
|
|
1247
|
/// <summary>
|
1248
|
/// Find the current largest item of this sorted collection.
|
1249
|
/// </summary>
|
1250
|
/// <exception cref="NoSuchItemException"> if the collection is empty.</exception>
|
1251
|
/// <returns>The largest item.</returns>
|
1252
|
T FindMax();
|
1253
|
|
1254
|
|
1255
|
/// <summary>
|
1256
|
/// Remove the largest item from this sorted collection.
|
1257
|
/// </summary>
|
1258
|
/// <exception cref="NoSuchItemException"> if the collection is empty.</exception>
|
1259
|
/// <returns>The removed item.</returns>
|
1260
|
T DeleteMax();
|
1261
|
|
1262
|
/// <summary>
|
1263
|
/// The comparer object supplied at creation time for this sorted collection.
|
1264
|
/// </summary>
|
1265
|
/// <value>The comparer</value>
|
1266
|
SCG.IComparer<T> Comparer { get; }
|
1267
|
|
1268
|
/// <summary>
|
1269
|
/// Find the strict predecessor of item in the sorted collection,
|
1270
|
/// that is, the greatest item in the collection smaller than the item.
|
1271
|
/// </summary>
|
1272
|
/// <param name="item">The item to find the predecessor for.</param>
|
1273
|
/// <param name="res">The predecessor, if any; otherwise the default value for T.</param>
|
1274
|
/// <returns>True if item has a predecessor; otherwise false.</returns>
|
1275
|
bool TryPredecessor(T item, out T res);
|
1276
|
|
1277
|
|
1278
|
/// <summary>
|
1279
|
/// Find the strict successor of item in the sorted collection,
|
1280
|
/// that is, the least item in the collection greater than the supplied value.
|
1281
|
/// </summary>
|
1282
|
/// <param name="item">The item to find the successor for.</param>
|
1283
|
/// <param name="res">The successor, if any; otherwise the default value for T.</param>
|
1284
|
/// <returns>True if item has a successor; otherwise false.</returns>
|
1285
|
bool TrySuccessor(T item, out T res);
|
1286
|
|
1287
|
|
1288
|
/// <summary>
|
1289
|
/// Find the weak predecessor of item in the sorted collection,
|
1290
|
/// that is, the greatest item in the collection smaller than or equal to the item.
|
1291
|
/// </summary>
|
1292
|
/// <param name="item">The item to find the weak predecessor for.</param>
|
1293
|
/// <param name="res">The weak predecessor, if any; otherwise the default value for T.</param>
|
1294
|
/// <returns>True if item has a weak predecessor; otherwise false.</returns>
|
1295
|
bool TryWeakPredecessor(T item, out T res);
|
1296
|
|
1297
|
|
1298
|
/// <summary>
|
1299
|
/// Find the weak successor of item in the sorted collection,
|
1300
|
/// that is, the least item in the collection greater than or equal to the supplied value.
|
1301
|
/// </summary>
|
1302
|
/// <param name="item">The item to find the weak successor for.</param>
|
1303
|
/// <param name="res">The weak successor, if any; otherwise the default value for T.</param>
|
1304
|
/// <returns>True if item has a weak successor; otherwise false.</returns>
|
1305
|
bool TryWeakSuccessor(T item, out T res);
|
1306
|
|
1307
|
|
1308
|
/// <summary>
|
1309
|
/// Find the strict predecessor in the sorted collection of a particular value,
|
1310
|
/// that is, the largest item in the collection less than the supplied value.
|
1311
|
/// </summary>
|
1312
|
/// <exception cref="NoSuchItemException"> if no such element exists (the
|
1313
|
/// supplied value is less than or equal to the minimum of this collection.)</exception>
|
1314
|
/// <param name="item">The item to find the predecessor for.</param>
|
1315
|
/// <returns>The predecessor.</returns>
|
1316
|
T Predecessor(T item);
|
1317
|
|
1318
|
|
1319
|
/// <summary>
|
1320
|
/// Find the strict successor in the sorted collection of a particular value,
|
1321
|
/// that is, the least item in the collection greater than the supplied value.
|
1322
|
/// </summary>
|
1323
|
/// <exception cref="NoSuchItemException"> if no such element exists (the
|
1324
|
/// supplied value is greater than or equal to the maximum of this collection.)</exception>
|
1325
|
/// <param name="item">The item to find the successor for.</param>
|
1326
|
/// <returns>The successor.</returns>
|
1327
|
T Successor(T item);
|
1328
|
|
1329
|
|
1330
|
/// <summary>
|
1331
|
/// Find the weak predecessor in the sorted collection of a particular value,
|
1332
|
/// that is, the largest item in the collection less than or equal to the supplied value.
|
1333
|
/// </summary>
|
1334
|
/// <exception cref="NoSuchItemException"> if no such element exists (the
|
1335
|
/// supplied value is less than the minimum of this collection.)</exception>
|
1336
|
/// <param name="item">The item to find the weak predecessor for.</param>
|
1337
|
/// <returns>The weak predecessor.</returns>
|
1338
|
T WeakPredecessor(T item);
|
1339
|
|
1340
|
|
1341
|
/// <summary>
|
1342
|
/// Find the weak successor in the sorted collection of a particular value,
|
1343
|
/// that is, the least item in the collection greater than or equal to the supplied value.
|
1344
|
/// </summary>
|
1345
|
/// <exception cref="NoSuchItemException"> if no such element exists (the
|
1346
|
/// supplied value is greater than the maximum of this collection.)</exception>
|
1347
|
///<param name="item">The item to find the weak successor for.</param>
|
1348
|
/// <returns>The weak successor.</returns>
|
1349
|
T WeakSuccessor(T item);
|
1350
|
|
1351
|
|
1352
|
/// <summary>
|
1353
|
/// Given a "cut" function from the items of the sorted collection to <code>int</code>
|
1354
|
/// whose only sign changes when going through items in increasing order
|
1355
|
/// can be
|
1356
|
/// <list>
|
1357
|
/// <item>from positive to zero</item>
|
1358
|
/// <item>from positive to negative</item>
|
1359
|
/// <item>from zero to negative</item>
|
1360
|
/// </list>
|
1361
|
/// The "cut" function is supplied as the <code>CompareTo</code> method
|
1362
|
/// of an object <code>c</code> implementing
|
1363
|
/// <code>IComparable<T></code>.
|
1364
|
/// A typical example is the case where <code>T</code> is comparable and
|
1365
|
/// <code>cutFunction</code> is itself of type <code>T</code>.
|
1366
|
/// <para>This method performs a search in the sorted collection for the ranges in which the
|
1367
|
/// "cut" function is negative, zero respectively positive. If <code>T</code> is comparable
|
1368
|
/// and <code>c</code> is of type <code>T</code>, this is a safe way (no exceptions thrown)
|
1369
|
/// to find predecessor and successor of <code>c</code>.
|
1370
|
/// </para>
|
1371
|
/// <para> If the supplied cut function does not satisfy the sign-change condition,
|
1372
|
/// the result of this call is undefined.
|
1373
|
/// </para>
|
1374
|
///
|
1375
|
/// </summary>
|
1376
|
/// <param name="cutFunction">The cut function <code>T</code> to <code>int</code>, given
|
1377
|
/// by the <code>CompareTo</code> method of an object implementing
|
1378
|
/// <code>IComparable<T></code>.</param>
|
1379
|
/// <param name="low">Returns the largest item in the collection, where the
|
1380
|
/// cut function is positive (if any).</param>
|
1381
|
/// <param name="lowIsValid">Returns true if the cut function is positive somewhere
|
1382
|
/// on this collection.</param>
|
1383
|
/// <param name="high">Returns the least item in the collection, where the
|
1384
|
/// cut function is negative (if any).</param>
|
1385
|
/// <param name="highIsValid">Returns true if the cut function is negative somewhere
|
1386
|
/// on this collection.</param>
|
1387
|
/// <returns>True if the cut function is zero somewhere
|
1388
|
/// on this collection.</returns>
|
1389
|
bool Cut(IComparable<T> cutFunction, out T low, out bool lowIsValid, out T high, out bool highIsValid);
|
1390
|
|
1391
|
|
1392
|
/// <summary>
|
1393
|
/// Query this sorted collection for items greater than or equal to a supplied value.
|
1394
|
/// <para>The returned collection is not a copy but a view into the collection.</para>
|
1395
|
/// <para>The view is fragile in the sense that changes to the underlying collection will
|
1396
|
/// invalidate the view so that further operations on the view throws InvalidView exceptions.</para>
|
1397
|
/// </summary>
|
1398
|
/// <param name="bot">The lower bound (inclusive).</param>
|
1399
|
/// <returns>The result directed collection.</returns>
|
1400
|
IDirectedEnumerable<T> RangeFrom(T bot);
|
1401
|
|
1402
|
|
1403
|
/// <summary>
|
1404
|
/// Query this sorted collection for items between two supplied values.
|
1405
|
/// <para>The returned collection is not a copy but a view into the collection.</para>
|
1406
|
/// <para>The view is fragile in the sense that changes to the underlying collection will
|
1407
|
/// invalidate the view so that further operations on the view throws InvalidView exceptions.</para>
|
1408
|
/// </summary>
|
1409
|
/// <param name="bot">The lower bound (inclusive).</param>
|
1410
|
/// <param name="top">The upper bound (exclusive).</param>
|
1411
|
/// <returns>The result directed collection.</returns>
|
1412
|
IDirectedEnumerable<T> RangeFromTo(T bot, T top);
|
1413
|
|
1414
|
|
1415
|
/// <summary>
|
1416
|
/// Query this sorted collection for items less than a supplied value.
|
1417
|
/// <para>The returned collection is not a copy but a view into the collection.</para>
|
1418
|
/// <para>The view is fragile in the sense that changes to the underlying collection will
|
1419
|
/// invalidate the view so that further operations on the view throws InvalidView exceptions.</para>
|
1420
|
/// </summary>
|
1421
|
/// <param name="top">The upper bound (exclusive).</param>
|
1422
|
/// <returns>The result directed collection.</returns>
|
1423
|
IDirectedEnumerable<T> RangeTo(T top);
|
1424
|
|
1425
|
|
1426
|
/// <summary>
|
1427
|
/// Create a directed collection with the same items as this collection.
|
1428
|
/// <para>The returned collection is not a copy but a view into the collection.</para>
|
1429
|
/// <para>The view is fragile in the sense that changes to the underlying collection will
|
1430
|
/// invalidate the view so that further operations on the view throws InvalidView exceptions.</para>
|
1431
|
/// </summary>
|
1432
|
/// <returns>The result directed collection.</returns>
|
1433
|
IDirectedCollectionValue<T> RangeAll();
|
1434
|
|
1435
|
|
1436
|
//TODO: remove now that we assume that we can check the sorting order?
|
1437
|
/// <summary>
|
1438
|
/// Add all the items from another collection with an enumeration order that
|
1439
|
/// is increasing in the items.
|
1440
|
/// </summary>
|
1441
|
/// <exception cref="ArgumentException"> if the enumerated items turns out
|
1442
|
/// not to be in increasing order.</exception>
|
1443
|
/// <param name="items">The collection to add.</param>
|
1444
|
/// <typeparam name="U"></typeparam>
|
1445
|
void AddSorted<U>(SCG.IEnumerable<U> items) where U : T;
|
1446
|
|
1447
|
|
1448
|
/// <summary>
|
1449
|
/// Remove all items of this collection above or at a supplied threshold.
|
1450
|
/// </summary>
|
1451
|
/// <param name="low">The lower threshold (inclusive).</param>
|
1452
|
void RemoveRangeFrom(T low);
|
1453
|
|
1454
|
|
1455
|
/// <summary>
|
1456
|
/// Remove all items of this collection between two supplied thresholds.
|
1457
|
/// </summary>
|
1458
|
/// <param name="low">The lower threshold (inclusive).</param>
|
1459
|
/// <param name="hi">The upper threshold (exclusive).</param>
|
1460
|
void RemoveRangeFromTo(T low, T hi);
|
1461
|
|
1462
|
|
1463
|
/// <summary>
|
1464
|
/// Remove all items of this collection below a supplied threshold.
|
1465
|
/// </summary>
|
1466
|
/// <param name="hi">The upper threshold (exclusive).</param>
|
1467
|
void RemoveRangeTo(T hi);
|
1468
|
}
|
1469
|
|
1470
|
|
1471
|
|
1472
|
/// <summary>
|
1473
|
/// A collection where items are maintained in sorted order together
|
1474
|
/// with their indexes in that order.
|
1475
|
/// </summary>
|
1476
|
public interface IIndexedSorted<T> : ISorted<T>, IIndexed<T>
|
1477
|
{
|
1478
|
/// <summary>
|
1479
|
/// Determine the number of items at or above a supplied threshold.
|
1480
|
/// </summary>
|
1481
|
/// <param name="bot">The lower bound (inclusive)</param>
|
1482
|
/// <returns>The number of matcing items.</returns>
|
1483
|
int CountFrom(T bot);
|
1484
|
|
1485
|
|
1486
|
/// <summary>
|
1487
|
/// Determine the number of items between two supplied thresholds.
|
1488
|
/// </summary>
|
1489
|
/// <param name="bot">The lower bound (inclusive)</param>
|
1490
|
/// <param name="top">The upper bound (exclusive)</param>
|
1491
|
/// <returns>The number of matcing items.</returns>
|
1492
|
int CountFromTo(T bot, T top);
|
1493
|
|
1494
|
|
1495
|
/// <summary>
|
1496
|
/// Determine the number of items below a supplied threshold.
|
1497
|
/// </summary>
|
1498
|
/// <param name="top">The upper bound (exclusive)</param>
|
1499
|
/// <returns>The number of matcing items.</returns>
|
1500
|
int CountTo(T top);
|
1501
|
|
1502
|
|
1503
|
/// <summary>
|
1504
|
/// Query this sorted collection for items greater than or equal to a supplied value.
|
1505
|
/// </summary>
|
1506
|
/// <param name="bot">The lower bound (inclusive).</param>
|
1507
|
/// <returns>The result directed collection.</returns>
|
1508
|
new IDirectedCollectionValue<T> RangeFrom(T bot);
|
1509
|
|
1510
|
|
1511
|
/// <summary>
|
1512
|
/// Query this sorted collection for items between two supplied values.
|
1513
|
/// </summary>
|
1514
|
/// <param name="bot">The lower bound (inclusive).</param>
|
1515
|
/// <param name="top">The upper bound (exclusive).</param>
|
1516
|
/// <returns>The result directed collection.</returns>
|
1517
|
new IDirectedCollectionValue<T> RangeFromTo(T bot, T top);
|
1518
|
|
1519
|
|
1520
|
/// <summary>
|
1521
|
/// Query this sorted collection for items less than a supplied value.
|
1522
|
/// </summary>
|
1523
|
/// <param name="top">The upper bound (exclusive).</param>
|
1524
|
/// <returns>The result directed collection.</returns>
|
1525
|
new IDirectedCollectionValue<T> RangeTo(T top);
|
1526
|
|
1527
|
|
1528
|
/// <summary>
|
1529
|
/// Create a new indexed sorted collection consisting of the items of this
|
1530
|
/// indexed sorted collection satisfying a certain predicate.
|
1531
|
/// </summary>
|
1532
|
/// <param name="predicate">The filter delegate defining the predicate.</param>
|
1533
|
/// <returns>The new indexed sorted collection.</returns>
|
1534
|
IIndexedSorted<T> FindAll(Fun<T, bool> predicate);
|
1535
|
|
1536
|
|
1537
|
/// <summary>
|
1538
|
/// Create a new indexed sorted collection consisting of the results of
|
1539
|
/// mapping all items of this list.
|
1540
|
/// <exception cref="ArgumentException"/> if the map is not increasing over
|
1541
|
/// the items of this collection (with respect to the two given comparison
|
1542
|
/// relations).
|
1543
|
/// </summary>
|
1544
|
/// <param name="mapper">The delegate definging the map.</param>
|
1545
|
/// <param name="comparer">The comparion relation to use for the result.</param>
|
1546
|
/// <returns>The new sorted collection.</returns>
|
1547
|
IIndexedSorted<V> Map<V>(Fun<T, V> mapper, SCG.IComparer<V> comparer);
|
1548
|
}
|
1549
|
|
1550
|
|
1551
|
|
1552
|
/// <summary>
|
1553
|
/// The type of a sorted collection with persistence
|
1554
|
/// </summary>
|
1555
|
public interface IPersistentSorted<T> : ISorted<T>, IDisposable
|
1556
|
{
|
1557
|
/// <summary>
|
1558
|
/// Make a (read-only) snap shot of this collection.
|
1559
|
/// </summary>
|
1560
|
/// <returns>The snap shot.</returns>
|
1561
|
ISorted<T> Snapshot();
|
1562
|
}
|
1563
|
|
1564
|
|
1565
|
|
1566
|
/*************************************************************************/
|
1567
|
/// <summary>
|
1568
|
/// A dictionary with keys of type K and values of type V. Equivalent to a
|
1569
|
/// finite partial map from K to V.
|
1570
|
/// </summary>
|
1571
|
public interface IDictionary<K, V> : ICollectionValue<KeyValuePair<K, V>>, ICloneable
|
1572
|
{
|
1573
|
/// <summary>
|
1574
|
/// The key equalityComparer.
|
1575
|
/// </summary>
|
1576
|
/// <value></value>
|
1577
|
SCG.IEqualityComparer<K> EqualityComparer { get;}
|
1578
|
|
1579
|
/// <summary>
|
1580
|
/// Indexer for dictionary.
|
1581
|
/// </summary>
|
1582
|
/// <exception cref="NoSuchItemException"> if no entry is found. </exception>
|
1583
|
/// <value>The value corresponding to the key</value>
|
1584
|
V this[K key] { get; set;}
|
1585
|
|
1586
|
|
1587
|
/// <summary>
|
1588
|
///
|
1589
|
/// </summary>
|
1590
|
/// <value>True if dictionary is read-only</value>
|
1591
|
bool IsReadOnly { get;}
|
1592
|
|
1593
|
|
1594
|
/// <summary>
|
1595
|
///
|
1596
|
/// </summary>
|
1597
|
/// <value>A collection containg the all the keys of the dictionary</value>
|
1598
|
ICollectionValue<K> Keys { get;}
|
1599
|
|
1600
|
|
1601
|
/// <summary>
|
1602
|
///
|
1603
|
/// </summary>
|
1604
|
/// <value>A collection containing all the values of the dictionary</value>
|
1605
|
ICollectionValue<V> Values { get;}
|
1606
|
|
1607
|
/// <summary>
|
1608
|
///
|
1609
|
/// </summary>
|
1610
|
/// <value>A delegate of type <see cref="T:C5.Fun`2"/> defining the partial function from K to V give by the dictionary.</value>
|
1611
|
Fun<K, V> Fun { get; }
|
1612
|
|
1613
|
|
1614
|
//TODO: resolve inconsistency: Add thows exception if key already there, AddAll ignores keys already There?
|
1615
|
/// <summary>
|
1616
|
/// Add a new (key, value) pair (a mapping) to the dictionary.
|
1617
|
/// </summary>
|
1618
|
/// <exception cref="DuplicateNotAllowedException"> if there already is an entry with the same key. </exception>>
|
1619
|
/// <param name="key">Key to add</param>
|
1620
|
/// <param name="val">Value to add</param>
|
1621
|
void Add(K key, V val);
|
1622
|
|
1623
|
/// <summary>
|
1624
|
/// Add the entries from a collection of <see cref="T:C5.KeyValuePair`2"/> pairs to this dictionary.
|
1625
|
/// </summary>
|
1626
|
/// <exception cref="DuplicateNotAllowedException">
|
1627
|
/// If the input contains duplicate keys or a key already present in this dictionary.</exception>
|
1628
|
/// <param name="entries"></param>
|
1629
|
void AddAll<U, W>(SCG.IEnumerable<KeyValuePair<U, W>> entries)
|
1630
|
where U : K
|
1631
|
where W : V
|
1632
|
;
|
1633
|
|
1634
|
/// <summary>
|
1635
|
/// The value is symbolic indicating the type of asymptotic complexity
|
1636
|
/// in terms of the size of this collection (worst-case or amortized as
|
1637
|
/// relevant).
|
1638
|
/// <para>See <see cref="T:C5.Speed"/> for the set of symbols.</para>
|
1639
|
/// </summary>
|
1640
|
/// <value>A characterization of the speed of lookup operations
|
1641
|
/// (<code>Contains()</code> etc.) of the implementation of this dictionary.</value>
|
1642
|
Speed ContainsSpeed { get;}
|
1643
|
|
1644
|
/// <summary>
|
1645
|
/// Check whether this collection contains all the values in another collection.
|
1646
|
/// If this collection has bag semantics (<code>AllowsDuplicates==true</code>)
|
1647
|
/// the check is made with respect to multiplicities, else multiplicities
|
1648
|
/// are not taken into account.
|
1649
|
/// </summary>
|
1650
|
/// <param name="items">The </param>
|
1651
|
/// <returns>True if all values in <code>items</code>is in this collection.</returns>
|
1652
|
bool ContainsAll<H>(SCG.IEnumerable<H> items) where H : K;
|
1653
|
|
1654
|
/// <summary>
|
1655
|
/// Remove an entry with a given key from the dictionary
|
1656
|
/// </summary>
|
1657
|
/// <param name="key">The key of the entry to remove</param>
|
1658
|
/// <returns>True if an entry was found (and removed)</returns>
|
1659
|
bool Remove(K key);
|
1660
|
|
1661
|
|
1662
|
/// <summary>
|
1663
|
/// Remove an entry with a given key from the dictionary and report its value.
|
1664
|
/// </summary>
|
1665
|
/// <param name="key">The key of the entry to remove</param>
|
1666
|
/// <param name="val">On exit, the value of the removed entry</param>
|
1667
|
/// <returns>True if an entry was found (and removed)</returns>
|
1668
|
bool Remove(K key, out V val);
|
1669
|
|
1670
|
|
1671
|
/// <summary>
|
1672
|
/// Remove all entries from the dictionary
|
1673
|
/// </summary>
|
1674
|
void Clear();
|
1675
|
|
1676
|
|
1677
|
/// <summary>
|
1678
|
/// Check if there is an entry with a specified key
|
1679
|
/// </summary>
|
1680
|
/// <param name="key">The key to look for</param>
|
1681
|
/// <returns>True if key was found</returns>
|
1682
|
bool Contains(K key);
|
1683
|
|
1684
|
|
1685
|
/// <summary>
|
1686
|
/// Check if there is an entry with a specified key and report the corresponding
|
1687
|
/// value if found. This can be seen as a safe form of "val = this[key]".
|
1688
|
/// </summary>
|
1689
|
/// <param name="key">The key to look for</param>
|
1690
|
/// <param name="val">On exit, the value of the entry</param>
|
1691
|
/// <returns>True if key was found</returns>
|
1692
|
bool Find(K key, out V val);
|
1693
|
|
1694
|
/// <summary>
|
1695
|
/// Check if there is an entry with a specified key and report the corresponding
|
1696
|
/// value if found. This can be seen as a safe form of "val = this[key]".
|
1697
|
/// </summary>
|
1698
|
/// <param name="key">The key to look for</param>
|
1699
|
/// <param name="val">On exit, the value of the entry</param>
|
1700
|
/// <returns>True if key was found</returns>
|
1701
|
bool Find(ref K key, out V val);
|
1702
|
|
1703
|
|
1704
|
/// <summary>
|
1705
|
/// Look for a specific key in the dictionary and if found replace the value with a new one.
|
1706
|
/// This can be seen as a non-adding version of "this[key] = val".
|
1707
|
/// </summary>
|
1708
|
/// <param name="key">The key to look for</param>
|
1709
|
/// <param name="val">The new value</param>
|
1710
|
/// <returns>True if key was found</returns>
|
1711
|
bool Update(K key, V val); //no-adding
|
1712
|
|
1713
|
|
1714
|
/// <summary>
|
1715
|
/// Look for a specific key in the dictionary and if found replace the value with a new one.
|
1716
|
/// This can be seen as a non-adding version of "this[key] = val" reporting the old value.
|
1717
|
/// </summary>
|
1718
|
/// <param name="key">The key to look for</param>
|
1719
|
/// <param name="val">The new value</param>
|
1720
|
/// <param name="oldval">The old value if any</param>
|
1721
|
/// <returns>True if key was found</returns>
|
1722
|
bool Update(K key, V val, out V oldval); //no-adding
|
1723
|
|
1724
|
/// <summary>
|
1725
|
/// Look for a specific key in the dictionary. If found, report the corresponding value,
|
1726
|
/// else add an entry with the key and the supplied value.
|
1727
|
/// </summary>
|
1728
|
/// <param name="key">The key to look for</param>
|
1729
|
/// <param name="val">On entry the value to add if the key is not found.
|
1730
|
/// On exit the value found if any.</param>
|
1731
|
/// <returns>True if key was found</returns>
|
1732
|
bool FindOrAdd(K key, ref V val); //mixture
|
1733
|
|
1734
|
|
1735
|
/// <summary>
|
1736
|
/// Update value in dictionary corresponding to key if found, else add new entry.
|
1737
|
/// More general than "this[key] = val;" by reporting if key was found.
|
1738
|
/// </summary>
|
1739
|
/// <param name="key">The key to look for</param>
|
1740
|
/// <param name="val">The value to add or replace with.</param>
|
1741
|
/// <returns>True if key was found and value updated.</returns>
|
1742
|
bool UpdateOrAdd(K key, V val);
|
1743
|
|
1744
|
|
1745
|
/// <summary>
|
1746
|
/// Update value in dictionary corresponding to key if found, else add new entry.
|
1747
|
/// More general than "this[key] = val;" by reporting if key was found.
|
1748
|
/// </summary>
|
1749
|
/// <param name="key">The key to look for</param>
|
1750
|
/// <param name="val">The value to add or replace with.</param>
|
1751
|
/// <param name="oldval">The old value if any</param>
|
1752
|
/// <returns>True if key was found and value updated.</returns>
|
1753
|
bool UpdateOrAdd(K key, V val, out V oldval);
|
1754
|
|
1755
|
|
1756
|
/// <summary>
|
1757
|
/// Check the integrity of the internal data structures of this dictionary.
|
1758
|
/// Only avaliable in DEBUG builds???
|
1759
|
/// </summary>
|
1760
|
/// <returns>True if check does not fail.</returns>
|
1761
|
bool Check();
|
1762
|
}
|
1763
|
|
1764
|
|
1765
|
|
1766
|
/// <summary>
|
1767
|
/// A dictionary with sorted keys.
|
1768
|
/// </summary>
|
1769
|
public interface ISortedDictionary<K, V> : IDictionary<K, V>
|
1770
|
{
|
1771
|
/// <summary>
|
1772
|
///
|
1773
|
/// </summary>
|
1774
|
/// <value></value>
|
1775
|
new ISorted<K> Keys { get;}
|
1776
|
|
1777
|
/// <summary>
|
1778
|
/// Find the current least item of this sorted collection.
|
1779
|
/// </summary>
|
1780
|
/// <exception cref="NoSuchItemException"> if the collection is empty.</exception>
|
1781
|
/// <returns>The least item.</returns>
|
1782
|
KeyValuePair<K, V> FindMin();
|
1783
|
|
1784
|
|
1785
|
/// <summary>
|
1786
|
/// Remove the least item from this sorted collection.
|
1787
|
/// </summary>
|
1788
|
/// <exception cref="NoSuchItemException"> if the collection is empty.</exception>
|
1789
|
/// <returns>The removed item.</returns>
|
1790
|
KeyValuePair<K, V> DeleteMin();
|
1791
|
|
1792
|
|
1793
|
/// <summary>
|
1794
|
/// Find the current largest item of this sorted collection.
|
1795
|
/// </summary>
|
1796
|
/// <exception cref="NoSuchItemException"> if the collection is empty.</exception>
|
1797
|
/// <returns>The largest item.</returns>
|
1798
|
KeyValuePair<K, V> FindMax();
|
1799
|
|
1800
|
|
1801
|
/// <summary>
|
1802
|
/// Remove the largest item from this sorted collection.
|
1803
|
/// </summary>
|
1804
|
/// <exception cref="NoSuchItemException"> if the collection is empty.</exception>
|
1805
|
/// <returns>The removed item.</returns>
|
1806
|
KeyValuePair<K, V> DeleteMax();
|
1807
|
|
1808
|
/// <summary>
|
1809
|
/// The key comparer used by this dictionary.
|
1810
|
/// </summary>
|
1811
|
/// <value></value>
|
1812
|
SCG.IComparer<K> Comparer { get;}
|
1813
|
|
1814
|
/// <summary>
|
1815
|
/// Find the entry in the dictionary whose key is the
|
1816
|
/// predecessor of the specified key.
|
1817
|
/// </summary>
|
1818
|
/// <param name="key">The key</param>
|
1819
|
/// <param name="res">The predecessor, if any</param>
|
1820
|
/// <returns>True if key has a predecessor</returns>
|
1821
|
bool TryPredecessor(K key, out KeyValuePair<K, V> res);
|
1822
|
|
1823
|
/// <summary>
|
1824
|
/// Find the entry in the dictionary whose key is the
|
1825
|
/// successor of the specified key.
|
1826
|
/// </summary>
|
1827
|
/// <param name="key">The key</param>
|
1828
|
/// <param name="res">The successor, if any</param>
|
1829
|
/// <returns>True if the key has a successor</returns>
|
1830
|
bool TrySuccessor(K key, out KeyValuePair<K, V> res);
|
1831
|
|
1832
|
/// <summary>
|
1833
|
/// Find the entry in the dictionary whose key is the
|
1834
|
/// weak predecessor of the specified key.
|
1835
|
/// </summary>
|
1836
|
/// <param name="key">The key</param>
|
1837
|
/// <param name="res">The predecessor, if any</param>
|
1838
|
/// <returns>True if key has a weak predecessor</returns>
|
1839
|
bool TryWeakPredecessor(K key, out KeyValuePair<K, V> res);
|
1840
|
|
1841
|
/// <summary>
|
1842
|
/// Find the entry in the dictionary whose key is the
|
1843
|
/// weak successor of the specified key.
|
1844
|
/// </summary>
|
1845
|
/// <param name="key">The key</param>
|
1846
|
/// <param name="res">The weak successor, if any</param>
|
1847
|
/// <returns>True if the key has a weak successor</returns>
|
1848
|
bool TryWeakSuccessor(K key, out KeyValuePair<K, V> res);
|
1849
|
|
1850
|
/// <summary>
|
1851
|
/// Find the entry with the largest key less than a given key.
|
1852
|
/// </summary>
|
1853
|
/// <exception cref="NoSuchItemException"> if there is no such entry. </exception>
|
1854
|
/// <param name="key">The key to compare to</param>
|
1855
|
/// <returns>The entry</returns>
|
1856
|
KeyValuePair<K, V> Predecessor(K key);
|
1857
|
|
1858
|
|
1859
|
/// <summary>
|
1860
|
/// Find the entry with the least key greater than a given key.
|
1861
|
/// </summary>
|
1862
|
/// <exception cref="NoSuchItemException"> if there is no such entry. </exception>
|
1863
|
/// <param name="key">The key to compare to</param>
|
1864
|
/// <returns>The entry</returns>
|
1865
|
KeyValuePair<K, V> Successor(K key);
|
1866
|
|
1867
|
|
1868
|
/// <summary>
|
1869
|
/// Find the entry with the largest key less than or equal to a given key.
|
1870
|
/// </summary>
|
1871
|
/// <exception cref="NoSuchItemException"> if there is no such entry. </exception>
|
1872
|
/// <param name="key">The key to compare to</param>
|
1873
|
/// <returns>The entry</returns>
|
1874
|
KeyValuePair<K, V> WeakPredecessor(K key);
|
1875
|
|
1876
|
|
1877
|
/// <summary>
|
1878
|
/// Find the entry with the least key greater than or equal to a given key.
|
1879
|
/// </summary>
|
1880
|
/// <exception cref="NoSuchItemException"> if there is no such entry. </exception>
|
1881
|
/// <param name="key">The key to compare to</param>
|
1882
|
/// <returns>The entry</returns>
|
1883
|
KeyValuePair<K, V> WeakSuccessor(K key);
|
1884
|
|
1885
|
/// <summary>
|
1886
|
/// Given a "cut" function from the items of the sorted collection to <code>int</code>
|
1887
|
/// whose only sign changes when going through items in increasing order
|
1888
|
/// can be
|
1889
|
/// <list>
|
1890
|
/// <item>from positive to zero</item>
|
1891
|
/// <item>from positive to negative</item>
|
1892
|
/// <item>from zero to negative</item>
|
1893
|
/// </list>
|
1894
|
/// The "cut" function is supplied as the <code>CompareTo</code> method
|
1895
|
/// of an object <code>c</code> implementing
|
1896
|
/// <code>IComparable<K></code>.
|
1897
|
/// A typical example is the case where <code>K</code> is comparable and
|
1898
|
/// <code>c</code> is itself of type <code>K</code>.
|
1899
|
/// <para>This method performs a search in the sorted collection for the ranges in which the
|
1900
|
/// "cut" function is negative, zero respectively positive. If <code>K</code> is comparable
|
1901
|
/// and <code>c</code> is of type <code>K</code>, this is a safe way (no exceptions thrown)
|
1902
|
/// to find predecessor and successor of <code>c</code>.
|
1903
|
/// </para>
|
1904
|
/// <para> If the supplied cut function does not satisfy the sign-change condition,
|
1905
|
/// the result of this call is undefined.
|
1906
|
/// </para>
|
1907
|
///
|
1908
|
/// </summary>
|
1909
|
/// <param name="cutFunction">The cut function <code>K</code> to <code>int</code>, given
|
1910
|
/// by the <code>CompareTo</code> method of an object implementing
|
1911
|
/// <code>IComparable<K></code>.</param>
|
1912
|
/// <param name="lowEntry">Returns the largest item in the collection, where the
|
1913
|
/// cut function is positive (if any).</param>
|
1914
|
/// <param name="lowIsValid">Returns true if the cut function is positive somewhere
|
1915
|
/// on this collection.</param>
|
1916
|
/// <param name="highEntry">Returns the least item in the collection, where the
|
1917
|
/// cut function is negative (if any).</param>
|
1918
|
/// <param name="highIsValid">Returns true if the cut function is negative somewhere
|
1919
|
/// on this collection.</param>
|
1920
|
/// <returns>True if the cut function is zero somewhere
|
1921
|
/// on this collection.</returns>
|
1922
|
bool Cut(IComparable<K> cutFunction, out KeyValuePair<K, V> lowEntry, out bool lowIsValid, out KeyValuePair<K, V> highEntry, out bool highIsValid);
|
1923
|
|
1924
|
/// <summary>
|
1925
|
/// Query this sorted collection for items greater than or equal to a supplied value.
|
1926
|
/// <para>The returned collection is not a copy but a view into the collection.</para>
|
1927
|
/// <para>The view is fragile in the sense that changes to the underlying collection will
|
1928
|
/// invalidate the view so that further operations on the view throws InvalidView exceptions.</para>
|
1929
|
/// </summary>
|
1930
|
/// <param name="bot">The lower bound (inclusive).</param>
|
1931
|
/// <returns>The result directed collection.</returns>
|
1932
|
IDirectedEnumerable<KeyValuePair<K, V>> RangeFrom(K bot);
|
1933
|
|
1934
|
|
1935
|
/// <summary>
|
1936
|
/// Query this sorted collection for items between two supplied values.
|
1937
|
/// <para>The returned collection is not a copy but a view into the collection.</para>
|
1938
|
/// <para>The view is fragile in the sense that changes to the underlying collection will
|
1939
|
/// invalidate the view so that further operations on the view throws InvalidView exceptions.</para>
|
1940
|
/// </summary>
|
1941
|
/// <param name="lowerBound">The lower bound (inclusive).</param>
|
1942
|
/// <param name="upperBound">The upper bound (exclusive).</param>
|
1943
|
/// <returns>The result directed collection.</returns>
|
1944
|
IDirectedEnumerable<KeyValuePair<K, V>> RangeFromTo(K lowerBound, K upperBound);
|
1945
|
|
1946
|
|
1947
|
/// <summary>
|
1948
|
/// Query this sorted collection for items less than a supplied value.
|
1949
|
/// <para>The returned collection is not a copy but a view into the collection.</para>
|
1950
|
/// <para>The view is fragile in the sense that changes to the underlying collection will
|
1951
|
/// invalidate the view so that further operations on the view throws InvalidView exceptions.</para>
|
1952
|
/// </summary>
|
1953
|
/// <param name="top">The upper bound (exclusive).</param>
|
1954
|
/// <returns>The result directed collection.</returns>
|
1955
|
IDirectedEnumerable<KeyValuePair<K, V>> RangeTo(K top);
|
1956
|
|
1957
|
|
1958
|
/// <summary>
|
1959
|
/// Create a directed collection with the same items as this collection.
|
1960
|
/// <para>The returned collection is not a copy but a view into the collection.</para>
|
1961
|
/// <para>The view is fragile in the sense that changes to the underlying collection will
|
1962
|
/// invalidate the view so that further operations on the view throws InvalidView exceptions.</para>
|
1963
|
/// </summary>
|
1964
|
/// <returns>The result directed collection.</returns>
|
1965
|
IDirectedCollectionValue<KeyValuePair<K, V>> RangeAll();
|
1966
|
|
1967
|
|
1968
|
//TODO: remove now that we assume that we can check the sorting order?
|
1969
|
/// <summary>
|
1970
|
/// Add all the items from another collection with an enumeration order that
|
1971
|
/// is increasing in the items.
|
1972
|
/// </summary>
|
1973
|
/// <exception cref="ArgumentException"> if the enumerated items turns out
|
1974
|
/// not to be in increasing order.</exception>
|
1975
|
/// <param name="items">The collection to add.</param>
|
1976
|
void AddSorted(SCG.IEnumerable<KeyValuePair<K, V>> items);
|
1977
|
|
1978
|
|
1979
|
/// <summary>
|
1980
|
/// Remove all items of this collection above or at a supplied threshold.
|
1981
|
/// </summary>
|
1982
|
/// <param name="low">The lower threshold (inclusive).</param>
|
1983
|
void RemoveRangeFrom(K low);
|
1984
|
|
1985
|
|
1986
|
/// <summary>
|
1987
|
/// Remove all items of this collection between two supplied thresholds.
|
1988
|
/// </summary>
|
1989
|
/// <param name="low">The lower threshold (inclusive).</param>
|
1990
|
/// <param name="hi">The upper threshold (exclusive).</param>
|
1991
|
void RemoveRangeFromTo(K low, K hi);
|
1992
|
|
1993
|
|
1994
|
/// <summary>
|
1995
|
/// Remove all items of this collection below a supplied threshold.
|
1996
|
/// </summary>
|
1997
|
/// <param name="hi">The upper threshold (exclusive).</param>
|
1998
|
void RemoveRangeTo(K hi);
|
1999
|
}
|
2000
|
|
2001
|
|
2002
|
|
2003
|
/*******************************************************************/
|
2004
|
/*/// <summary>
|
2005
|
/// The type of an item comparer
|
2006
|
/// <i>Implementations of this interface must asure that the method is self-consistent
|
2007
|
/// and defines a sorting order on items, or state precise conditions under which this is true.</i>
|
2008
|
/// <i>Implementations <b>must</b> assure that repeated calls of
|
2009
|
/// the method to the same (in reference or binary identity sense) arguments
|
2010
|
/// will return values with the same sign (-1, 0 or +1), or state precise conditions
|
2011
|
/// under which the user
|
2012
|
/// can be assured repeated calls will return the same sign.</i>
|
2013
|
/// <i>Implementations of this interface must always return values from the method
|
2014
|
/// and never throw exceptions.</i>
|
2015
|
/// <i>This interface is identical to System.Collections.Generic.IComparer<T></i>
|
2016
|
/// </summary>
|
2017
|
public interface IComparer<T>
|
2018
|
{
|
2019
|
/// <summary>
|
2020
|
/// Compare two items with respect to this item comparer
|
2021
|
/// </summary>
|
2022
|
/// <param name="item1">First item</param>
|
2023
|
/// <param name="item2">Second item</param>
|
2024
|
/// <returns>Positive if item1 is greater than item2, 0 if they are equal, negative if item1 is less than item2</returns>
|
2025
|
int Compare(T item1, T item2);
|
2026
|
}
|
2027
|
|
2028
|
/// <summary>
|
2029
|
/// The type of an item equalityComparer.
|
2030
|
/// <i>Implementations of this interface <b>must</b> assure that the methods are
|
2031
|
/// consistent, that is, that whenever two items i1 and i2 satisfies that Equals(i1,i2)
|
2032
|
/// returns true, then GetHashCode returns the same value for i1 and i2.</i>
|
2033
|
/// <i>Implementations of this interface <b>must</b> assure that repeated calls of
|
2034
|
/// the methods to the same (in reference or binary identity sense) arguments
|
2035
|
/// will return the same values, or state precise conditions under which the user
|
2036
|
/// can be assured repeated calls will return the same values.</i>
|
2037
|
/// <i>Implementations of this interface must always return values from the methods
|
2038
|
/// and never throw exceptions.</i>
|
2039
|
/// <i>This interface is similar in function to System.IKeyComparer<T></i>
|
2040
|
/// </summary>
|
2041
|
public interface SCG.IEqualityComparer<T>
|
2042
|
{
|
2043
|
/// <summary>
|
2044
|
/// Get the hash code with respect to this item equalityComparer
|
2045
|
/// </summary>
|
2046
|
/// <param name="item">The item</param>
|
2047
|
/// <returns>The hash code</returns>
|
2048
|
int GetHashCode(T item);
|
2049
|
|
2050
|
|
2051
|
/// <summary>
|
2052
|
/// Check if two items are equal with respect to this item equalityComparer
|
2053
|
/// </summary>
|
2054
|
/// <param name="item1">first item</param>
|
2055
|
/// <param name="item2">second item</param>
|
2056
|
/// <returns>True if equal</returns>
|
2057
|
bool Equals(T item1, T item2);
|
2058
|
}*/
|
2059
|
}
|