Algorithms.ReverseInPlace(Algorithms.Range(list, 3, 6))
will reverse the 6 items beginning at index 3.Algorithms.ReverseInPlace(Algorithms.Range(array, 3, 6))
will reverse the 6 items beginning at index 3.
Dictionary<IEnumerable<string>, int> =
new Dictionary<IEnumerable<string>, int>(Algorithms.GetCollectionEqualityComparer<string>());
Dictionary<IEnumerable<string>, int> =
new Dictionary<IEnumerable<string>, int>(Algorithms.GetCollectionEqualityComparer<string>(StringComparer.CurrentCultureIgnoreCase));
Dictionary<IEnumerable<string>, int> =
new Dictionary<IEnumerable<string>, int>(Algorithms.GetSetEqualityComparer<string>(StringComparer.CurrentCultureIgnoreCase));
Dictionary<IEnumerable<string>, int> =
new Dictionary<IEnumerable<string>, int>(Algorithms.GetSetEqualityComparer<string>());
List<int> list1, list2;
if (EqualCollections(list1, list2, delegate(int x, int y) { return x <= y; }) {
// the check is true...
}
List<double> list = new List<double>(Algorithms.NCopiesOf(1000, 1.0));
The items are compared in one of two ways. If T implements IComparable<T> then the Equals method of that interface will be used to compare items, otherwise the Equals method from Object will be used. Alternatively, an instance of IComparer<T> can be passed to the constructor to use to compare items.
Bag is implemented as a hash table. Inserting, deleting, and looking up an an element all are done in approximately constant time, regardless of the number of items in the bag.
When multiple equal items are stored in the bag, they are stored as a representative item and a count. If equal items can be distinguished, this may be noticable. For example, if a case-insensitive comparer is used with a Bag<string>, and both "hello", and "HELLO" are added to the bag, then the bag will appear to contain two copies of "hello" (the representative item).
Typically, this method is not called directly. Instead the "foreach" statement is used to enumerate the items, which uses this method implicitly.
If an item is added to or deleted from the bag while it is being enumerated, then the enumeration will end with an InvalidOperationException.
Enumeration all the items in the bag takes time O(N), where N is the number of items in the bag.
This method is not abstract, although derived classes should always override it. It is not abstract because some derived classes may wish to reimplement Add with a different return type (typically bool). In C#, this can be accomplished with code like the following:
public class MyCollection<T>: CollectionBase<T>, ICollection<T>
{
public new bool Add(T item) {
/* Add the item */
}
void ICollection<T>.Add(T item) {
Add(item);
}
}
Insert(Count, item)
Algorithms.ReverseInPlace(deque.Range(3, 6))
will reverse the 6 items beginning at index 3.Insert(Count, item)
The items are compared in one of three ways. If T implements IComparable<TKey> or IComparable, then the CompareTo method of that interface will be used to compare items. Alternatively, a comparison function can be passed in either as a delegate, or as an instance of IComparer<TKey>.
OrderedBag is implemented as a balanced binary tree. Inserting, deleting, and looking up an an element all are done in log(N) + M time, where N is the number of keys in the tree, and M is the current number of copies of the element being handled.
Typically, this method is not called directly. Instead the "foreach" statement is used to enumerate the items, which uses this method implicitly.
If an item is added to or deleted from the bag while it is being enumerated, then the enumeration will end with an InvalidOperationException.
Enumeration all the items in the bag takes time O(N), where N is the number of items in the bag.
Typically, this method is used in conjunction with a foreach statement. For example:
foreach(T item in bag.Reversed()) {
// process item
}
If an item is added to or deleted from the bag while the View is being enumerated, then the enumeration will end with an InvalidOperationException.
Calling Reverse does not copy the data in the tree, and the operation takes constant time.
If
Typically, this method is used in conjunction with a foreach statement. For example:
foreach(T item in bag.Range(from, true, to, false)) {
// process item
}
If an item is added to or deleted from the bag while the View is being enumerated, then the enumeration will end with an InvalidOperationException.
Calling Range does not copy the data in the tree, and the operation takes constant time.
Typically, this method is used in conjunction with a foreach statement. For example:
foreach(T item in bag.RangeFrom(from, true)) {
// process item
}
If an item is added to or deleted from the bag while the View is being enumerated, then the enumeration will end with an InvalidOperationException.
Calling RangeFrom does not copy the data in the tree, and the operation takes constant time.
Typically, this method is used in conjunction with a foreach statement. For example:
foreach(T item in bag.RangeTo(to, false)) {
// process item
}
If an item is added to or deleted from the bag while the View is being enumerated, then the enumeration will end with an InvalidOperationException.
Calling RangeTo does not copy the data in the tree, and the operation takes constant time.
Views are dynamic. If the underlying bag changes, the view changes in sync. If a change is made to the view, the underlying bag changes accordingly.
Typically, this class is used in conjunction with a foreach statement to enumerate the items in a subset of the OrderedBag. For example:
foreach(T item in bag.Range(from, to)) {
// process item
}
bag.Range("A", "B").Clear();
Typically, this method is used in conjunction with a foreach statement. For example:
foreach(KeyValuePair<TKey, TValue> pair in dictionary.Reversed()) {
// process pair
}
If an entry is added to or deleted from the dictionary while the View is being enumerated, then the enumeration will end with an InvalidOperationException.
Calling Reverse does not copy the data in the dictionary, and the operation takes constant time.
If
The sorted order of the keys is determined by the comparison instance or delegate used to create the dictionary.
Typically, this property is used in conjunction with a foreach statement. For example:
foreach(KeyValuePair<TKey, TValue> pair in dictionary.Range(from, true, to, false)) {
// process pair
}
Calling Range does not copy the data in the dictionary, and the operation takes constant time.
The sorted order of the keys is determined by the comparison instance or delegate used to create the dictionary.
Typically, this property is used in conjunction with a foreach statement. For example:
foreach(KeyValuePair<TKey, TValue> pair in dictionary.RangeFrom(from, true)) {
// process pair
}
Calling RangeFrom does not copy of the data in the dictionary, and the operation takes constant time.
The sorted order of the keys is determined by the comparison instance or delegate used to create the dictionary.
Typically, this property is used in conjunction with a foreach statement. For example:
foreach(KeyValuePair<TKey, TValue> pair in dictionary.RangeFrom(from, false)) {
// process pair
}
Calling RangeTo does not copy the data in the dictionary, and the operation takes constant time.
Views are dynamic. If the underlying dictionary changes, the view changes in sync. If a change is made to the view, the underlying dictionary changes accordingly.
Typically, this class is used in conjunction with a foreach statement to enumerate the keys and values in a subset of the OrderedMultiDictionary. For example:
foreach(KeyValuePair<TKey, TValue> pair in dictionary.Range(from, to)) {
// process pair
}
dictionary.Range("A", "B").Clear();
The items are compared in one of three ways. If T implements IComparable<TKey> or IComparable, then the CompareTo method of that interface will be used to compare items. Alternatively, a comparison function can be passed in either as a delegate, or as an instance of IComparer<TKey>.
OrderedSet is implemented as a balanced binary tree. Inserting, deleting, and looking up an an element all are done in log(N) type, where N is the number of keys in the tree.
Typically, this method is not called directly. Instead the "foreach" statement is used to enumerate the items, which uses this method implicitly.
If an item is added to or deleted from the set while it is being enumerated, then the enumeration will end with an InvalidOperationException.
Enumeration all the items in the set takes time O(N log N), where N is the number of items in the set.
OrderedSet<string> set = new OrderedSet<string>(StringComparer.CurrentCultureIgnoreCase);
set.Add("HELLO");
string s;
bool b = set.TryGetItem("Hello", out s); // b receives true, s receives "HELLO".
Typically, this method is used in conjunction with a foreach statement. For example:
foreach(T item in set.Reversed()) {
// process item
}
If an item is added to or deleted from the set while the View is being enumerated, then the enumeration will end with an InvalidOperationException.
Calling Reverse does not copy the data in the tree, and the operation takes constant time.
If
Typically, this method is used in conjunction with a foreach statement. For example:
foreach(T item in set.Range(from, true, to, false)) {
// process item
}
If an item is added to or deleted from the set while the View is being enumerated, then the enumeration will end with an InvalidOperationException.
Calling Range does not copy the data in the tree, and the operation takes constant time.
Typically, this method is used in conjunction with a foreach statement. For example:
foreach(T item in set.RangeFrom(from, true)) {
// process item
}
If an item is added to or deleted from the set while the View is being enumerated, then the enumeration will end with an InvalidOperationException.
Calling RangeFrom does not copy the data in the tree, and the operation takes constant time.
Typically, this method is used in conjunction with a foreach statement. For example:
foreach(T item in set.RangeTo(to, false)) {
// process item
}
If an item is added to or deleted from the set while the View is being enumerated, then the enumeration will end with an InvalidOperationException.
Calling RangeTo does not copy the data in the tree, and the operation takes constant time.
Views are dynamic. If the underlying set changes, the view changes in sync. If a change is made to the view, the underlying set changes accordingly.
Typically, this class is used in conjunction with a foreach statement to enumerate the items in a subset of the OrderedSet. For example:
foreach(T item in set.Range(from, to)) {
// process item
}
set.Range("A", "B").Clear();
Algorithms.Reverse(deque.Range(3, 6))
will return the reverse opf the 6 items beginning at index 3.Algorithms.ReverseInPlace(list.Range(3, 6))
will reverse the 6 items beginning at index 3.The items are compared in one of two ways. If T implements IComparable<T> then the Equals method of that interface will be used to compare items, otherwise the Equals method from Object will be used. Alternatively, an instance of IComparer<T> can be passed to the constructor to use to compare items.
Set is implemented as a hash table. Inserting, deleting, and looking up an an element all are done in approximately constant time, regardless of the number of items in the Set.
Typically, this method is not called directly. Instead the "foreach" statement is used to enumerate the items, which uses this method implicitly.
If an item is added to or deleted from the set while it is being enumerated, then the enumeration will end with an InvalidOperationException.
Enumerating all the items in the set takes time O(N), where N is the number of items in the set.
Set<string> set = new Set<string>(StringComparer.CurrentCultureIgnoreCase);
set.Add("HELLO");
string s;
bool b = set.TryGetItem("Hello", out s); // b receives true, s receives "HELLO".
The keys are compared in one of three ways. If TKey implements IComparable<TKey> or IComparable, then the CompareTo method of that interface will be used to compare elements. Alternatively, a comparison function can be passed in either as a delegate, or as an instance of IComparer<TKey>.
OrderedDictionary is implemented as a balanced binary tree. Inserting, deleting, and looking up an an element all are done in log(N) type, where N is the number of keys in the tree.
Typically, this method is used in conjunction with a foreach statement. For example:
foreach(KeyValuePair<TKey, TValue> pair in dictionary.Reversed()) {
// process pair
}
If an entry is added to or deleted from the dictionary while the View is being enumerated, then the enumeration will end with an InvalidOperationException.
Calling Reverse does not copy the data in the dictionary, and the operation takes constant time.
If
The sorted order of the keys is determined by the comparison instance or delegate used to create the dictionary.
Typically, this property is used in conjunction with a foreach statement. For example:
foreach(KeyValuePair<TKey, TValue> pair in dictionary.Range(from, true, to, false)) {
// process pair
}
Calling Range does not copy the data in the dictionary, and the operation takes constant time.
The sorted order of the keys is determined by the comparison instance or delegate used to create the dictionary.
Typically, this property is used in conjunction with a foreach statement. For example:
foreach(KeyValuePair<TKey, TValue> pair in dictionary.RangeFrom(from, true)) {
// process pair
}
Calling RangeFrom does not copy of the data in the dictionary, and the operation takes constant time.
The sorted order of the keys is determined by the comparison instance or delegate used to create the dictionary.
Typically, this property is used in conjunction with a foreach statement. For example:
foreach(KeyValuePair<TKey, TValue> pair in dictionary.RangeFrom(from, false)) {
// process pair
}
Calling RangeTo does not copy the data in the dictionary, and the operation takes constant time.
Unlike adding or removing an element, changing the value associated with a key can be performed while an enumeration (foreach) on the the dictionary is in progress.
Equality between keys is determined by the comparison instance or delegate used to create the dictionary.
Replace takes time O(log N), where N is the number of entries in the dictionary.
Typically, this method is not called directly. Instead the "foreach" statement is used to enumerate the elements of the dictionary, which uses this method implicitly.
If an element is added to or deleted from the dictionary while it is being enumerated, then the enumeration will end with an InvalidOperationException.
Enumeration all the entries in the dictionary takes time O(N log N), where N is the number of entries in the dictionary.
Views are dynamic. If the underlying dictionary changes, the view changes in sync. If a change is made to the view, the underlying dictionary changes accordingly.
Typically, this class is used in conjunction with a foreach statement to enumerate the keys and values in a subset of the OrderedDictionary. For example:
foreach(KeyValuePair<TKey, TValue> pair in dictionary.Range(from, to)) {
// process pair
}
dictionary.Range("A", "B").Clear();