Interface ISorted<T>
A sorted collection, i.e. a collection where items are maintained and can be searched for in sorted order. Thus the sequence order is given as a sorting order.
The sorting order is defined by a comparer, an object of type IComparer<T> (C5.IComparer`1). Implementors of this interface will normally let the user define the comparer as an argument to a constructor. Usually there will also be constructors without a comparer argument, in which case the comparer should be the defalt comparer for the item type, C5.Comparer`1.Default.
The comparer of the sorted collection is available as the
System.Collections.Generic.Comparer
property
(C5.ISorted`1.Comparer).
The methods are grouped according to
Since this interface extends ISequenced<T>, sorted collections will also have an item equalityComparer (C5.IExtensible`1.EqualityComparer). This equalityComparer will not be used in connection with the inner workings of the sorted collection, but will be used if the sorted collection is used as an item in a collection of unsequenced or sequenced collections, (C5.ICollection`1 and C5.ISequenced`1)
Note that code may check if two sorted collections has the same sorting order by checking if the Comparer properties are equal. This is done a few places in this library for optimization purposes.
Inherited Members
Namespace: Lucene.Net.Support.C5
Assembly: Lucene.Net.dll
Syntax
public interface ISorted<T> : ISequenced<T>, ICollection<T>, IExtensible<T>, ICollection<T>, IDirectedCollectionValue<T>, ICollectionValue<T>, IShowable, IFormattable, IDirectedEnumerable<T>, IEnumerable<T>, IEnumerable
Type Parameters
Name | Description |
---|---|
T |
Properties
| Improve this Doc View SourceComparer
The comparer object supplied at creation time for this sorted collection.
Declaration
IComparer<T> Comparer { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IComparer<T> | The comparer |
Methods
| Improve this Doc View SourceAddSorted(IEnumerable<T>)
Add all the items from another collection with an enumeration order that is increasing in the items.
Declaration
void AddSorted(IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | items | The collection to add. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | if the enumerated items turns out not to be in increasing order. |
Cut(IComparable<T>, out T, out Boolean, out T, out Boolean)
Given a "cut" function from the items of the sorted collection to
int
whose only sign changes when going through items in increasing order
can be
The "cut" function is supplied as the
CompareTo
method
of an object c
implementing
IComparable<T>
.
A typical example is the case where
T
is comparable and
cutFunction
is itself of type T
.
This method performs a search in the sorted collection for the ranges in which the "cut" function is negative, zero respectively positive. If
T
is comparable
and c
is of type T
, this is a safe way (no exceptions thrown)
to find predecessor and successor of c
.
If the supplied cut function does not satisfy the sign-change condition, the result of this call is undefined.
Declaration
bool Cut(IComparable<T> cutFunction, out T low, out bool lowIsValid, out T high, out bool highIsValid)
Parameters
Type | Name | Description |
---|---|---|
System.IComparable<T> | cutFunction | The cut function to , given
by the method of an object implementing
. |
T | low | Returns the largest item in the collection, where the cut function is positive (if any). |
System.Boolean | lowIsValid | Returns true if the cut function is positive somewhere on this collection. |
T | high | Returns the least item in the collection, where the cut function is negative (if any). |
System.Boolean | highIsValid | Returns true if the cut function is negative somewhere on this collection. |
Returns
Type | Description |
---|---|
System.Boolean | True if the cut function is zero somewhere on this collection. |
DeleteMax()
Remove the largest item from this sorted collection.
Declaration
T DeleteMax()
Returns
Type | Description |
---|---|
T | The removed item. |
Exceptions
Type | Condition |
---|---|
NoSuchItemException | if the collection is empty. |
DeleteMin()
Remove the least item from this sorted collection.
Declaration
T DeleteMin()
Returns
Type | Description |
---|---|
T | The removed item. |
Exceptions
Type | Condition |
---|---|
NoSuchItemException | if the collection is empty. |
FindMax()
Find the current largest item of this sorted collection.
Declaration
T FindMax()
Returns
Type | Description |
---|---|
T | The largest item. |
Exceptions
Type | Condition |
---|---|
NoSuchItemException | if the collection is empty. |
FindMin()
Find the current least item of this sorted collection.
Declaration
T FindMin()
Returns
Type | Description |
---|---|
T | The least item. |
Exceptions
Type | Condition |
---|---|
NoSuchItemException | if the collection is empty. |
Predecessor(T)
Find the strict predecessor in the sorted collection of a particular value, that is, the largest item in the collection less than the supplied value.
Declaration
T Predecessor(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to find the predecessor for. |
Returns
Type | Description |
---|---|
T | The predecessor. |
Exceptions
Type | Condition |
---|---|
NoSuchItemException | if no such element exists (the supplied value is less than or equal to the minimum of this collection.) |
RangeAll()
Create a directed collection with the same items as this collection.
The returned collection is not a copy but a view into the collection.
The view is fragile in the sense that changes to the underlying collection will invalidate the view so that further operations on the view throws InvalidView exceptions.
Declaration
IDirectedCollectionValue<T> RangeAll()
Returns
Type | Description |
---|---|
IDirectedCollectionValue<T> | The result directed collection. |
RangeFrom(T)
Query this sorted collection for items greater than or equal to a supplied value.
The returned collection is not a copy but a view into the collection.
The view is fragile in the sense that changes to the underlying collection will invalidate the view so that further operations on the view throws InvalidView exceptions.
Declaration
IDirectedEnumerable<T> RangeFrom(T bot)
Parameters
Type | Name | Description |
---|---|---|
T | bot | The lower bound (inclusive). |
Returns
Type | Description |
---|---|
IDirectedEnumerable<T> | The result directed collection. |
RangeFromTo(T, T)
Query this sorted collection for items between two supplied values.
The returned collection is not a copy but a view into the collection.
The view is fragile in the sense that changes to the underlying collection will invalidate the view so that further operations on the view throws InvalidView exceptions.
Declaration
IDirectedEnumerable<T> RangeFromTo(T bot, T top)
Parameters
Type | Name | Description |
---|---|---|
T | bot | The lower bound (inclusive). |
T | top | The upper bound (exclusive). |
Returns
Type | Description |
---|---|
IDirectedEnumerable<T> | The result directed collection. |
RangeTo(T)
Query this sorted collection for items less than a supplied value.
The returned collection is not a copy but a view into the collection.
The view is fragile in the sense that changes to the underlying collection will invalidate the view so that further operations on the view throws InvalidView exceptions.
Declaration
IDirectedEnumerable<T> RangeTo(T top)
Parameters
Type | Name | Description |
---|---|---|
T | top | The upper bound (exclusive). |
Returns
Type | Description |
---|---|
IDirectedEnumerable<T> | The result directed collection. |
RemoveRangeFrom(T)
Remove all items of this collection above or at a supplied threshold.
Declaration
void RemoveRangeFrom(T low)
Parameters
Type | Name | Description |
---|---|---|
T | low | The lower threshold (inclusive). |
RemoveRangeFromTo(T, T)
Remove all items of this collection between two supplied thresholds.
Declaration
void RemoveRangeFromTo(T low, T hi)
Parameters
Type | Name | Description |
---|---|---|
T | low | The lower threshold (inclusive). |
T | hi | The upper threshold (exclusive). |
RemoveRangeTo(T)
Remove all items of this collection below a supplied threshold.
Declaration
void RemoveRangeTo(T hi)
Parameters
Type | Name | Description |
---|---|---|
T | hi | The upper threshold (exclusive). |
Successor(T)
Find the strict successor in the sorted collection of a particular value, that is, the least item in the collection greater than the supplied value.
Declaration
T Successor(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to find the successor for. |
Returns
Type | Description |
---|---|
T | The successor. |
Exceptions
Type | Condition |
---|---|
NoSuchItemException | if no such element exists (the supplied value is greater than or equal to the maximum of this collection.) |
TryPredecessor(T, out T)
Find the strict predecessor of item in the sorted collection, that is, the greatest item in the collection smaller than the item.
Declaration
bool TryPredecessor(T item, out T res)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to find the predecessor for. |
T | res | The predecessor, if any; otherwise the default value for T. |
Returns
Type | Description |
---|---|
System.Boolean | True if item has a predecessor; otherwise false. |
TrySuccessor(T, out T)
Find the strict successor of item in the sorted collection, that is, the least item in the collection greater than the supplied value.
Declaration
bool TrySuccessor(T item, out T res)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to find the successor for. |
T | res | The successor, if any; otherwise the default value for T. |
Returns
Type | Description |
---|---|
System.Boolean | True if item has a successor; otherwise false. |
TryWeakPredecessor(T, out T)
Find the weak predecessor of item in the sorted collection, that is, the greatest item in the collection smaller than or equal to the item.
Declaration
bool TryWeakPredecessor(T item, out T res)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to find the weak predecessor for. |
T | res | The weak predecessor, if any; otherwise the default value for T. |
Returns
Type | Description |
---|---|
System.Boolean | True if item has a weak predecessor; otherwise false. |
TryWeakSuccessor(T, out T)
Find the weak successor of item in the sorted collection, that is, the least item in the collection greater than or equal to the supplied value.
Declaration
bool TryWeakSuccessor(T item, out T res)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to find the weak successor for. |
T | res | The weak successor, if any; otherwise the default value for T. |
Returns
Type | Description |
---|---|
System.Boolean | True if item has a weak successor; otherwise false. |
WeakPredecessor(T)
Find the weak predecessor in the sorted collection of a particular value, that is, the largest item in the collection less than or equal to the supplied value.
Declaration
T WeakPredecessor(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to find the weak predecessor for. |
Returns
Type | Description |
---|---|
T | The weak predecessor. |
Exceptions
Type | Condition |
---|---|
NoSuchItemException | if no such element exists (the supplied value is less than the minimum of this collection.) |
WeakSuccessor(T)
Find the weak successor in the sorted collection of a particular value, that is, the least item in the collection greater than or equal to the supplied value.
Declaration
T WeakSuccessor(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to find the weak successor for. |
Returns
Type | Description |
---|---|
T | The weak successor. |
Exceptions
Type | Condition |
---|---|
NoSuchItemException | if no such element exists (the supplied value is greater than the maximum of this collection.) |