Summary
Implements a list whose items are always stored in a sorted order. Multiple equal items are allowed, and will
always be added to the end of a run of equal items. Insertion, and removal are O(N); lookups are O(log N); access
by index is supported.
Generic type parameters
T | This type parameter is not documented. |
Constructors
| Creates an empty ListSorted<T> using a default comparer for the item type. |
|
Creates an empty ListSorted<T> of the specified capacity and using a default comparer for
the item type. |
| Creates an empty ListSorted<T> using the specified item comparer. |
|
Creates an empty ListSorted<T> of the specified capacity and using the specified item
comparer. |
Instance methods
void | |
Adds the specified item to the list. The item is added at the appropriate location to keep the list sorted. If
multiple equal items are stored, this method is guaranteed to add an item at the end of the equal items run.
This method is O(N). |
void | |
Adds all of the specified items into the list. The resulting list will contain all the items in the same order
as a stable sort would have produced. NOTE: the current implementation is O(N log N) if the collection is
empty, or O(N*M) otherwise, where N = items currently in the collection and M = items to be added. The latter
can be improved. |
void | | Removes all items from the list. |
bool | | Returns true if the list contains the specified item. This operation is O(logN). |
void | CopyTo(T[] array, int arrayIndex) |
Copies all items of this collection into the specified array, starting at the specified index, in the sorted
order. |
IEnumerator<T> | | Gets an enumerator which enumerates all items of this collection in sorted order. |
int | |
Returns the index of the FIRST item equal to the specified item, or -1 if the item is not found. The operation
is O(log N). |
int | |
Returns the index of the LAST item equal to the specified item, or -1 if the item is not found. The operation
is O(log N). |
bool | |
Removes the FIRST occurrence of the specified item from the list. Returns true if the item was removed, or
false if it wasn't found. |
void | | Removes the item at the specified index. |
bool | |
Removes the LAST occurrence of the specified item from the list. Returns true if the item was removed, or
false if it wasn't found. |
Instance properties
int | | Gets the number of items stored in this collection. |
bool | | Returns false. |
T | | Gets an item at the specified index. Setting an item is not supported and will always throw an exception. |