[]
Indexes a collection by an expression (typically, by a field), providing fast access to items having particular values (or range of values) of that expression.
public abstract class Index<T, TKey> : Index<T>, IIndexScanner<T, TKey>, IIndexScanner<T>
Name | Description |
---|---|
T | The type of the elements of the collection to index. |
TKey | The type of the index key. |
Indexes can be created and added to a collection explicitly in code by calling IndexCollection.Add, or their creation can be enforced in LINQ queries by using the Indexed hint.
In LINQ queries, indexes are used for optimizing query performance if that is specified with an Indexed hint. Usually, hints are not required, because LiveLinq can automatically determine that an index can be used to speedup a query, but using hints helps to ensure this optimization.
Indexes can also be used programmatically in code, without LINQ syntax, by using the methods of the IIndexScanner<T, TKey> interface that is implemented by the Index<T, TKey> class. For example, you can call such methods as Find directly for an Index<T, TKey> object.
It must be kept in mind that every index you create introduces a trade-off: it can dramatically speed up searches, but it consumes memory and adds some (usually, small) overhead every time the indexed collection (or any of the items, its elements) is modified. This is why indexes should generally be kept only while you need them for queries. To delete an index, use IndexCollection.Remove.
An index can have subindexes, see Subindex<T, TKey>. Subindexes are optional, not required for any indexing tasks, but can provide additional optimization and help minimize memory requirements when a collection is indexed by multiple keys. In presence of subindexes, an index is the root level of a tree of subindexes.
Name | Description |
---|---|
KeySelector | Gets the expression used to obtain key value from an element of the indexed collection. |
Name | Description |
---|---|
All(Order) | Gets all items in the indexed collection. |
ContainsKey(TKey) | Returns a value that indicates whether the collection contains an item with the given key value. |
Find(TKey) | Finds items with the specified key value. |
FindBetween(TKey, bool, TKey, bool, Func<TKey, bool>, Order) | Finds items with key values in the interval between the specified values. |
FindGreater(TKey, bool, Func<TKey, bool>, Order) | Finds items with keys greater than the specified value. |
FindKeys(IEnumerable<TKey>, Order) | Finds items containing any of the specified key values. |
FindLess(TKey, bool, Func<TKey, bool>, Order) | Finds items with keys less than the specified value. |
FindSingle(TKey) | Finds the only item with the specified key value and throws an exception if there is not exactly one item with that key value. |
GroupJoin<T2, TResult>(IIndexScanner<T2, TKey>, Func<T, IEnumerable<T2>, TResult>) | Correlates the items of this indexed collection with the items of another indexed collection and groups the results by the item of this collection. Implements IIndexScanner(T,TKey).GroupJoin |
GroupJoin<T2, TResult>(IEnumerable<T2>, Func<T2, TKey>, Func<IEnumerable<T>, T2, TResult>) | Correlates the items of this indexed collection with the items of another sequence and groups the results by the item of the second sequence. Implements IIndexScanner(T,TKey).GroupJoin |
GroupJoin<T2, TResult>(IEnumerable<T2>, Func<T2, TKey>, Func<T, IEnumerable<T2>, TResult>) | Correlates the items of this indexed collection with the items of another sequence and groups the results by the item of this collection. Implements IIndexScanner(T,TKey).GroupJoin |
Join<T2, TResult>(IIndexScanner<T2, TKey>, Func<T, T2, TResult>, JoinOperator) | Correlates the items of this indexed collection with the items of another indexed collection and returns the combined items with matching keys. Implements IIndexScanner(T,TKey).Join |
Join<T2, TResult>(IEnumerable<T2>, Func<T2, TKey>, Func<T, T2, TResult>, JoinOperator) | Correlates the items of this indexed collection with the items of another sequence and returns the combined items with matching keys. Implements IIndexScanner(T,TKey).Join |
Keys(Order) | Gets distinct key values in all items of the indexed collection. |