#if NET_2_0 /* Copyright (c) 2003-2004 Niels Kokholm and Peter Sestoft Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ using System; using MSG = System.Collections.Generic; namespace C5 { /*************************************************************************/ //TODO: use the MS defs fro m MSG if any? /// /// A generic delegate that when invoked performs some operation /// on it T argument. /// public delegate void Applier(T t); /// /// A generic delegate whose invocation constitutes a map from T to V. /// public delegate V Mapper(T item); /// /// A generic delegate that when invoked on a T item returns a boolean /// value -- i.e. a T predicate. /// public delegate bool Filter(T item); /************************************************************************ /// /// A generic collection that may be enumerated. This is the coarsest interface /// for main stream generic collection classes (as opposed to priority queues). /// It can also be the result of a query operation on another collection /// (where the result size is not easily computable, in which case the result /// could have been an ICollectionValue<T>). /// public interface noIEnumerable { /// /// Create an enumerator for the collection /// /// The enumerator(SIC) MSG.IEnumerator GetEnumerator(); } */ /// /// A generic collection, that can be enumerated backwards. /// public interface IDirectedEnumerable: MSG.IEnumerable { /// /// Create a collection containing the same items as this collection, but /// whose enumerator will enumerate the items backwards. The new collection /// will become invalid if the original is modified. Method typicaly used as in /// foreach (T x in coll.Backwards()) {...} /// /// The backwards collection. IDirectedEnumerable Backwards(); /// /// Forwards if same, else Backwards /// /// The enumeration direction relative to the original collection. EnumerationDirection Direction { get;} } /// /// A generic collection that may be enumerated and can answer /// efficiently how many items it contains. Like IEnumerable<T>, /// this interface does not prescribe any operations to initialize or update the /// collection. The main usage for this interface is to be the return type of /// query operations on generic collection. /// public interface ICollectionValue: MSG.IEnumerable { /// /// /// /// The number of items in this collection int Count { get;} /// /// The value is symbolic indicating the type of asymptotic complexity /// in terms of the size of this collection (worst-case or amortized as /// relevant). /// /// A characterization of the speed of the /// Count property in this collection. Speed CountSpeed { get;} /// /// Copy the items of this collection to a contiguous part of an array. /// /// The array to copy to /// The index at which to copy the first item void CopyTo(T[] a, int i); /// /// Create an array with the items of this collection (in the same order as an /// enumerator would output them). /// /// The array T[] ToArray(); /// /// Apply a delegate to all items of this collection. /// /// The delegate to apply void Apply(Applier a); /// /// Check if there exists an item that satisfies a /// specific predicate in this collection. /// /// A filter delegate /// () defining the predicate /// True is such an item exists bool Exists(Filter filter); /// /// Check if all items in this collection satisfies a specific predicate. /// /// A filter delegate /// () defining the predicate /// True if all items satisfies the predicate bool All(Filter filter); } /// /// A sized generic collection, that can be enumerated backwards. /// public interface IDirectedCollectionValue: ICollectionValue, IDirectedEnumerable { /// /// Create a collection containing the same items as this collection, but /// whose enumerator will enumerate the items backwards. The new collection /// will become invalid if the original is modified. Method typicaly used as in /// foreach (T x in coll.Backwards()) {...} /// /// The backwards collection. new IDirectedCollectionValue Backwards(); } /// /// A generic collection to which one may add items. This is just the intersection /// of the main stream generic collection interfaces and the priority queue interface, /// and . /// public interface IExtensible : ICollectionValue { /// /// /// /// False if this collection has set semantics, true if bag semantics. bool AllowsDuplicates { get;} /// /// /// /// An object to be used for locking to enable multi threaded code /// to acces this collection safely. object SyncRoot { get;} /// /// /// /// True if this collection is empty. bool IsEmpty { get;} /// /// Add an item to this collection if possible. If this collection has set /// semantics, the item will be added if not already in the collection. If /// bag semantics, the item will always be added. /// /// The item to add. /// True if item was added. bool Add(T item); /// /// Add the elements from another collection to this collection. If this /// collection has set semantics, only items not already in the collection /// will be added. /// /// The items to add. void AddAll(MSG.IEnumerable items); /// /// Add the elements from another collection with a more specialized item type /// to this collection. If this /// collection has set semantics, only items not already in the collection /// will be added. /// /// The type of items to add /// The items to add void AddAll(MSG.IEnumerable items) where U : T; //void Clear(); // for priority queue //int Count why not? /// /// Check the integrity of the internal data structures of this collection. ///

This is only relevant for developers of the library

///
/// True if check was passed. bool Check(); } /// /// The symbolic characterization of the speed of lookups for a collection. /// The values may refer to worst-case, amortized and/or expected asymtotic /// complexity wrt. the collection size. /// public enum Speed: short { /// /// Counting the collection with the Count property may not return /// (for a synthetic and potentially infinite collection). /// PotentiallyInfinite = 1, /// /// Lookup operations like Contains(T item) or the Count /// property may take time O(n), /// where n is the size of the collection. /// Linear = 2, /// /// Lookup operations like Contains(T item) or the Count /// property takes time O(log n), /// where n is the size of the collection. /// Log = 3, /// /// Lookup operations like Contains(T item) or the Count /// property takes time O(1), /// where n is the size of the collection. /// Constant = 4 } //TODO: add ItemHasher to interface by making it an IHasher? No, add Comparer property! /// /// The simplest interface of a main stream generic collection /// with lookup, insertion and removal operations. /// public interface ICollection: IExtensible { /// /// If true any call of an updating operation will throw an /// InvalidOperationException /// /// True if this collection is read only. bool IsReadOnly { get;} //This is somewhat similar to the RandomAccess marker itf in java /// /// The value is symbolic indicating the type of asymptotic complexity /// in terms of the size of this collection (worst-case or amortized as /// relevant). /// /// A characterization of the speed of lookup operations /// (Contains() etc.) of the implementation of this list. Speed ContainsSpeed { get;} /// /// The hashcode is defined as the sum of h(item) over the items /// of the collection, where the function h is??? /// /// The unordered hashcode of this collection. int GetHashCode(); /// /// Compare the contents of this collection to another one without regards to /// the sequence order. The comparison will use this collection's itemhasher /// to compare individual items. /// /// The collection to compare to. /// True if this collection and that contains the same items. bool Equals(ICollection that); /// /// Check if this collection contains (an item equivalent to according to the /// itemhasher) a particular value. /// /// The value to check for. /// True if the items is in this collection. bool Contains(T item); /// /// Count the number of items of the collection equal to a particular value. /// Returns 0 if and only if the value is not in the collection. /// /// The value to count. /// The number of copies found. int ContainsCount(T item); /// /// Check if this collection contains all the values in another collection. /// If this collection has bag semantics (NoDuplicates==false) /// the check is made with respect to multiplicities, else multiplicities /// are not taken into account. /// /// The /// True if all values in itemsis in this collection. bool ContainsAll(MSG.IEnumerable items); /// /// Check if this collection contains an item equivalent according to the /// itemhasher to a particular value. If so, return in the ref argument (a /// binary copy of) the actual value found. /// /// The value to look for. /// True if the items is in this collection. bool Find(ref T item); //This should probably just be bool Add(ref T item); !!! /// /// Check if this collection contains an item equivalent according to the /// itemhasher to a particular value. If so, return in the ref argument (a /// binary copy of) the actual value found. Else, add the item to the collection. /// /// The value to look for. /// True if the item was found (hence not added). bool FindOrAdd(ref T item); /// /// Check if this collection contains an item equivalent according to the /// itemhasher to a particular value. If so, update the item in the collection /// to with a binary copy of the supplied value. If the collection has bag semantics, /// it is implementation dependent if this updates all equivalent copies in /// the collection or just one. /// /// Value to update. /// True if the item was found and hence updated. bool Update(T item); //Better to call this AddOrUpdate since the return value fits that better //OTOH for a bag the update would be better be the default!!! /// /// Check if this collection contains an item equivalent according to the /// itemhasher to a particular value. If so, update the item in the collection /// to with a binary copy of the supplied value; else add the value to the collection. /// /// Value to add or update. /// True if the item was found and updated (hence not added). bool UpdateOrAdd(T item); /// /// Remove a particular item from this collection. If the collection has bag /// semantics only one copy equivalent to the supplied item is removed. /// /// The value to remove. /// True if the item was found (and removed). bool Remove(T item); //CLR will allow us to let this be bool Remove(ref T item); !!! /// /// Remove a particular item from this collection if found. If the collection /// has bag semantics only one copy equivalent to the supplied item is removed, /// which one is implementation dependent. /// If an item was removed, report a binary copy of the actual item removed in /// the argument. /// /// The value to remove on input. /// True if the item was found (and removed). bool RemoveWithReturn(ref T item); /// /// Remove all items equivalent to a given value. /// /// The value to remove. void RemoveAllCopies(T item); /// /// Remove all items in another collection from this one. If this collection /// has bag semantics, take multiplicities into account. /// /// The items to remove. void RemoveAll(MSG.IEnumerable items); /// /// Remove all items from this collection. /// void Clear(); /// /// Remove all items not in some other collection from this one. If this collection /// has bag semantics, take multiplicities into account. /// /// The items to retain. void RetainAll(MSG.IEnumerable items); //IDictionary UniqueItems() } /// /// An editable collection maintaining a definite sequence order of the items. /// ///

Implementations of this interface must compute the hash code and /// equality exactly as prescribed in the method definitions in order to /// be consistent with other collection classes implementing this interface.

///

This interface is usually implemented by explicit interface implementation, /// not as ordinary virtual methods.

///
public interface ISequenced: ICollection, IDirectedCollectionValue { /// /// The hashcode is defined as h(...h(h(x1),x2)...,xn) for /// h(a,b)=31*a+b and the x's the hash codes of /// /// The sequence order hashcode of this collection. new int GetHashCode(); /// /// Compare this sequenced collection to another one in sequence order. /// /// The sequenced collection to compare to. /// True if this collection and that contains equal (according to /// this collection's itemhasher) in the same sequence order. bool Equals(ISequenced that); } /// /// A sequenced collection, where indices of items in the order are maintained /// public interface IIndexed: ISequenced { /// /// if i is negative or /// >= the size of the collection. /// /// The i'th item of this list. /// the index to lookup T this[int i] { get;} /// /// . /// /// The directed collection of items in a specific index interval. /// The low index of the interval (inclusive). /// The size of the range. IDirectedCollectionValue this[int start, int count] { get;} /// /// Searches for an item in the list going forwrds from the start. /// /// Item to search for. /// Index of item from start. int IndexOf(T item); /// /// Searches for an item in the list going backwords from the end. /// /// Item to search for. /// Index of of item from the end. int LastIndexOf(T item); /// /// Remove the item at a specific position of the list. /// if i is negative or /// >= the size of the collection. /// /// The index of the item to remove. /// The removed item. T RemoveAt(int i); /// /// Remove all items in an index interval. /// ???. /// /// The index of the first item to remove. /// The number of items to remove. void RemoveInterval(int start, int count); } //TODO: decide if this should extend ICollection /// /// The interface describing the operations of a LIFO stack data structure. /// /// The item type public interface IStack { /// /// Push an item to the top of the stack. /// /// The item void Push(T item); /// /// Pop the item at the top of the stack from the stack. /// /// The popped item. T Pop(); } //TODO: decide if this should extend ICollection /// /// The interface describing the operations of a FIFO queue data structure. /// /// The item type public interface IQueue { /// /// Enqueue an item at the back of the queue. /// /// The item void EnQueue(T item); /// /// Dequeue an item from the front of the queue. /// /// The item T DeQueue(); } /// /// This is an indexed collection, where the item order is chosen by /// the user at insertion time. /// /// NBNBNB: we neeed a description of the view functionality here! /// public interface IList: IIndexed, IStack, IQueue { /// /// if this list is empty. /// /// The first item in this list. T First { get;} /// /// if this list is empty. /// /// The last item in this list. T Last { get;} /// /// Since Add(T item) always add at the end of the list, /// this describes if list has FIFO or LIFO semantics. /// /// True if the Remove() operation removes from the /// start of the list, false if it removes from the end. bool FIFO { get; set;} /// /// On this list, this indexer is read/write. /// if i is negative or /// >= the size of the collection. /// /// The i'th item of this list. /// The index of the item to fetch or store. new T this[int i] { get; set;} /// /// Insert an item at a specific index location in this list. /// if i is negative or /// > the size of the collection. /// if the list has /// NoDuplicates=true and the item is /// already in the list. /// The index at which to insert. /// The item to insert. void Insert(int i, T item); /// /// Insert an item at the front of this list. /// if the list has /// NoDuplicates=true and the item is /// already in the list. /// /// The item to insert. void InsertFirst(T item); /// /// Insert an item at the back of this list. /// if the list has /// NoDuplicates=true and the item is /// already in the list. /// /// The item to insert. void InsertLast(T item); /// /// Insert an item right before the first occurrence of some target item. /// if target is not found /// or if the list has NoDuplicates=true and the item is /// already in the list. /// /// The item to insert. /// The target before which to insert. void InsertBefore(T item, T target); /// /// Insert an item right after the last(???) occurrence of some target item. /// if target is not found /// or if the list has NoDuplicates=true and the item is /// already in the list. /// /// The item to insert. /// The target after which to insert. void InsertAfter(T item, T target); /// /// Insert into this list all items from an enumerable collection starting /// at a particular index. /// if i is negative or /// > the size of the collection. /// if the list has /// NoDuplicates=true and one of the items to insert is /// already in the list. /// /// Index to start inserting at /// Items to insert void InsertAll(int i, MSG.IEnumerable items); /// /// Create a new list consisting of the items of this list satisfying a /// certain predicate. /// /// The filter delegate defining the predicate. /// The new list. IList FindAll(Filter filter); /// /// Create a new list consisting of the results of mapping all items of this /// list. The new list will use the default hasher for the item type V. /// /// The type of items of the new list /// The delegate defining the map. /// The new list. IList Map(Mapper mapper); /// /// Create a new list consisting of the results of mapping all items of this /// list. The new list will use a specified hasher for the item type. /// /// The type of items of the new list /// The delegate defining the map. /// The hasher to use for the new list /// The new list. IList Map(Mapper mapper, IHasher hasher); /// /// Remove one item from the list: from the front if FIFO /// is true, else from the back. /// if this list is empty. /// /// The removed item. T Remove(); /// /// Remove one item from the fromnt of the list. /// if this list is empty. /// /// The removed item. T RemoveFirst(); /// /// Remove one item from the back of the list. /// if this list is empty. /// /// The removed item. T RemoveLast(); /// /// Create a list view on this list. /// if the view would not fit into /// this list. /// /// The index in this list of the start of the view. /// The size of the view. /// The new list view. IList View(int start, int count); /// /// Null if this list is not a view. /// /// Underlying list for view. IList Underlying { get;} /// /// /// Offset for this list view or 0 for an underlying list. int Offset { get;} /// /// Slide this list view along the underlying list. /// if this list is not a view. /// if the operation /// would bring either end of the view outside the underlying list. /// /// The signed amount to slide: positive to slide /// towards the end. void Slide(int offset); /// /// Slide this list view along the underlying list, changing its size. /// if this list is not a view. /// if the operation /// would bring either end of the view outside the underlying list. /// /// The signed amount to slide: positive to slide /// towards the end. /// The new size of the view. void Slide(int offset, int size); /// /// Reverse the list so the items are in the opposite sequence order. /// void Reverse(); /// /// Reverst part of the list so the items are in the opposite sequence order. /// if the count is negative. /// if the part does not fit /// into the list. /// /// The index of the start of the part to reverse. /// The size of the part to reverse. void Reverse(int start, int count); //NaturalSort for comparable items? /// /// Check if this list is sorted according to a specific sorting order. /// /// The comparer defining the sorting order. /// True if the list is sorted, else false. bool IsSorted(IComparer c); /// /// Sort the items of the list according to a specific sorting order. /// /// The comparer defining the sorting order. void Sort(IComparer c); /// /// Randonmly shuffle the items of this list. /// void Shuffle(); /// /// Shuffle the items of this list according to a specific random source. /// /// The random source. void Shuffle(Random rnd); } /// /// A generic collection of items prioritized by a comparison (order) relation. /// Supports adding items and reporting or removing extremal elements. /// The priority queue itself exports the used /// order relation through its implementation of IComparer<T> /// public interface IPriorityQueue: IExtensible { /// /// Find the current least item of this priority queue. /// /// The least item. T FindMin(); /// /// Remove the least item from this priority queue. /// /// The removed item. T DeleteMin(); /// /// Find the current largest item of this priority queue. /// /// The largest item. T FindMax(); /// /// Remove the largest item from this priority queue. /// /// The removed item. T DeleteMax(); /// /// The comparer object supplied at creation time for this collection /// /// The comparer IComparer Comparer { get;} } /// /// A collection where items are maintained in sorted order. /// public interface ISorted: ISequenced, IPriorityQueue { /// /// Find the strict predecessor in the sorted collection of a particular value, /// i.e. the largest item in the collection less than the supplied value. /// if no such element exists (the /// supplied value is less than or equal to the minimum of this collection.) /// /// The item to find the predecessor for. /// The predecessor. T Predecessor(T item); /// /// Find the strict successor in the sorted collection of a particular value, /// i.e. the least item in the collection greater than the supplied value. /// if no such element exists (the /// supplied value is greater than or equal to the maximum of this collection.) /// /// The item to find the successor for. /// The successor. T Successor(T item); /// /// Find the weak predecessor in the sorted collection of a particular value, /// i.e. the largest item in the collection less than or equal to the supplied value. /// if no such element exists (the /// supplied value is less than the minimum of this collection.) /// /// The item to find the weak predecessor for. /// The weak predecessor. T WeakPredecessor(T item); /// /// Find the weak successor in the sorted collection of a particular value, /// i.e. the least item in the collection greater than or equal to the supplied value. /// if no such element exists (the /// supplied value is greater than the maximum of this collection.) /// /// The item to find the weak successor for. /// The weak successor. T WeakSuccessor(T item); /// /// Perform a search in the sorted collection for the ranges in which a /// non-decreasing function from the item type to int is /// negative, zero respectively positive. If the supplied cut function is /// not non-decreasing, the result of this call is undefined. /// /// The cut function T to int, given /// as an IComparable<T> object, where the cut function is /// the c.CompareTo(T that) method. /// Returns the largest item in the collection, where the /// cut function is negative (if any). /// True if the cut function is negative somewhere /// on this collection. /// Returns the least item in the collection, where the /// cut function is positive (if any). /// True if the cut function is positive somewhere /// on this collection. /// bool Cut(IComparable c, out T low, out bool lowIsValid, out T high, out bool highIsValid); /// /// Query this sorted collection for items greater than or equal to a supplied value. /// /// The lower bound (inclusive). /// The result directed collection. IDirectedEnumerable RangeFrom(T bot); /// /// Query this sorted collection for items between two supplied values. /// /// The lower bound (inclusive). /// The upper bound (exclusive). /// The result directed collection. IDirectedEnumerable RangeFromTo(T bot, T top); /// /// Query this sorted collection for items less than a supplied value. /// /// The upper bound (exclusive). /// The result directed collection. IDirectedEnumerable RangeTo(T top); /// /// Create a directed collection with the same items as this collection. /// /// The result directed collection. IDirectedCollectionValue RangeAll(); /// /// Add all the items from another collection with an enumeration order that /// is increasing in the items. /// if the enumerated items turns out /// not to be in increasing order. /// /// The collection to add. void AddSorted(MSG.IEnumerable items); /// /// Remove all items of this collection above or at a supplied threshold. /// /// The lower threshold (inclusive). void RemoveRangeFrom(T low); /// /// Remove all items of this collection between two supplied thresholds. /// /// The lower threshold (inclusive). /// The upper threshold (exclusive). void RemoveRangeFromTo(T low, T hi); /// /// Remove all items of this collection below a supplied threshold. /// /// The upper threshold (exclusive). void RemoveRangeTo(T hi); } /// /// A collection where items are maintained in sorted order together /// with their indexes in that order. /// public interface IIndexedSorted: ISorted, IIndexed { /// /// Determine the number of items at or above a supplied threshold. /// /// The lower bound (inclusive) /// The number of matcing items. int CountFrom(T bot); /// /// Determine the number of items between two supplied thresholds. /// /// The lower bound (inclusive) /// The upper bound (exclusive) /// The number of matcing items. int CountFromTo(T bot, T top); /// /// Determine the number of items below a supplied threshold. /// /// The upper bound (exclusive) /// The number of matcing items. int CountTo(T top); /// /// Query this sorted collection for items greater than or equal to a supplied value. /// /// The lower bound (inclusive). /// The result directed collection. new IDirectedCollectionValue RangeFrom(T bot); /// /// Query this sorted collection for items between two supplied values. /// /// The lower bound (inclusive). /// The upper bound (exclusive). /// The result directed collection. new IDirectedCollectionValue RangeFromTo(T bot, T top); /// /// Query this sorted collection for items less than a supplied value. /// /// The upper bound (exclusive). /// The result directed collection. new IDirectedCollectionValue RangeTo(T top); /// /// Create a new indexed sorted collection consisting of the items of this /// indexed sorted collection satisfying a certain predicate. /// /// The filter delegate defining the predicate. /// The new indexed sorted collection. IIndexedSorted FindAll(Filter f); /// /// Create a new indexed sorted collection consisting of the results of /// mapping all items of this list. /// if the map is not increasing over /// the items of this collection (with respect to the two given comparison /// relations). /// /// The delegate definging the map. /// The comparion relation to use for the result. /// The new sorted collection. IIndexedSorted Map(Mapper m, IComparer c); } /// /// The type of a sorted collection with persistence /// public interface IPersistentSorted: ISorted, IDisposable { /// /// Make a (read-only) snap shot of this collection. /// /// The snap shot. ISorted Snapshot(); } /*************************************************************************/ /// /// A dictionary with keys of type K and values of type V. Equivalent to a /// finite partial map from K to V. /// public interface IDictionary: MSG.IEnumerable> { /// /// Indexer for dictionary. /// if no entry is found. /// /// The value corresponding to the key V this[K key] { get; set;} /// /// /// /// The number of entrues in the dictionary int Count { get; } /// /// /// /// True if dictionary is read only bool IsReadOnly { get;} /// /// /// /// The distinguished object to use for locking to synchronize multithreaded access object SyncRoot { get;} /// /// /// /// A collection containg the all the keys of the dictionary ICollectionValue Keys { get;} /// /// /// /// A collection containing all the values of the dictionary ICollectionValue Values { get;} /// /// Add a new (key, value) pair (a mapping) to the dictionary. /// if there already is an entry with the same key. /// /// Key to add /// Value to add void Add(K key, V val); /// /// Remove an entry with a given key from the dictionary /// /// The key of the entry to remove /// True if an entry was found (and removed) bool Remove(K key); /// /// Remove an entry with a given key from the dictionary and report its value. /// /// The key of the entry to remove /// On exit, the value of the removed entry /// True if an entry was found (and removed) bool Remove(K key, out V val); /// /// Remove all entries from the dictionary /// void Clear(); /// /// Check if there is an entry with a specified key /// /// The key to look for /// True if key was found bool Contains(K key); /// /// Check if there is an entry with a specified key and report the corresponding /// value if found. This can be seen as a safe form of "val = this[key]". /// /// The key to look for /// On exit, the value of the entry /// True if key was found bool Find(K key, out V val); /// /// Look for a specific key in the dictionary and if found replace the value with a new one. /// This can be seen as a non-adding version of "this[key] = val". /// /// The key to look for /// The new value /// True if key was found bool Update(K key, V val); //no-adding /// /// Look for a specific key in the dictionary. If found, report the corresponding value, /// else add an entry with the key and the supplied value. /// /// The key to look for /// On entry the value to add if the key is not found. /// On exit the value found if any. /// True if key was found bool FindOrAdd(K key, ref V val); //mixture /// /// Update value in dictionary corresponding to key if found, else add new entry. /// More general than "this[key] = val;" by reporting if key was found. /// /// The key to look for /// The value to add or replace with. /// True if key was found and value updated. bool UpdateOrAdd(K key, V val); /// /// Check the integrity of the internal data structures of this dictionary. /// Only avaliable in DEBUG builds??? /// /// True if check does not fail. bool Check(); } /// /// A dictionary with sorted keys. /// public interface ISortedDictionary: IDictionary { /// /// Find the entry with the largest key less than a given key. /// if there is no such entry. /// /// The key to compare to /// The entry KeyValuePair Predecessor(K key); /// /// Find the entry with the least key greater than a given key. /// if there is no such entry. /// /// The key to compare to /// The entry KeyValuePair Successor(K key); /// /// Find the entry with the largest key less than or equal to a given key. /// if there is no such entry. /// /// The key to compare to /// The entry KeyValuePair WeakPredecessor(K key); /// /// Find the entry with the least key greater than or equal to a given key. /// if there is no such entry. /// /// The key to compare to /// The entry KeyValuePair WeakSuccessor(K key); } /*******************************************************************/ /// /// The type of an item comparer ///

Implementations of this interface must asure that the method is self-consistent /// and defines a sorting order on items, or state precise conditions under which this is true.

///

Implementations must assure that repeated calls of /// the method to the same (in reference or binary identity sense) arguments /// will return values with the same sign (-1, 0 or +1), or state precise conditions /// under which the user /// can be assured repeated calls will return the same sign.

///

Implementations of this interface must always return values from the method /// and never throw exceptions.

///

This interface is identical to System.Collections.Generic.IComparer<T>

///
public interface IComparer { /// /// Compare two items with respect to this item comparer /// /// First item /// Second item /// Positive if a is greater than b, 0 if they are equal, negative if a is less than b int Compare(T a, T b); } /* /// /// The interface for an item that is generic comparable. ///

Implementations of this interface must assure that repeated calls of /// the method to the same (in reference or binary identity sense) object and argument /// will return values with the same sign (-1, 0 or +1), or state precise conditions /// under which the user /// can be assured repeated calls will return the same sign.

///

Implementations of this interface must always return values from the method /// and never throw exceptions.

///

This interface is identical to System.Collections.Generic.IComparable<T>

///
public interface unIComparable //: System.IComparable { /// /// Compare this item to another one /// /// The other item /// Positive if this is greater than , 0 if equal to, negative if less than that int CompareTo(T that); } */ /// /// The type of an item hasher. ///

Implementations of this interface must assure that the methods are /// consistent, i.e. that whenever two items i1 and i2 satisfies that Equals(i1,i2) /// returns true, then GetHashCode returns the same values for i1 and i2.

///

Implementations of this interface must assure that repeated calls of /// the methods to the same (in reference or binary identity sense) arguments /// will return the same values, or state precise conditions under which the user /// can be assured repeated calls will return the same values.

///

Implementations of this interface must always return values from the methods /// and never throw exceptions.

///

This interface is similar in function to System.IKeyComparer<T>

///
public interface IHasher { /// /// Get the hash code with respect to this item hasher /// /// The item /// The hash code int GetHashCode(T item); /// /// Check if two items are equal with respect to this item hasher /// /// first item /// second item /// True if equal bool Equals(T i1, T i2); } } #endif