Enhanced C#
Language of your choice: library documentation
Namespaces | Classes | Enumerations | Functions
Loyc.Collections Namespace Reference

Contains general-purpose interfaces (Loyc.Collections.IListSource<T>, ranges, etc.), collection implementations (Loyc.Collections.DList<T>, Loyc.Collections.WeakValueDictionary<K,V>, etc.), extension methods (Loyc.Collections.LCExt, Loyc.Collections.EnumerableExt, etc.), helper classes (Loyc.Collections.EmptyList<T>, (Loyc.Collections.Repeated<T>, etc.), and adapter classes (Loyc.Collections.ListSlice<T>, Loyc.Collections.BufferedSequence<T>, etc.). More...

Namespaces

namespace  Impl
 Contains helper classes and base classes for implementing collections (Loyc.Collections.Impl.InternalList<T>, Loyc.Collections.Impl.ListExBase<T>, Loyc.Collections.Impl.ListSourceBase<T>, etc.) Also contains the AList and CPTrie node classes, which perhaps should not be public...
 

Classes

class  AList
 An all-purpose list structure with the following additional features beyond what's offered by List<T>: fast insertion and deletion (O(log N)), batch insertion and deletion, observability, fast cloning, freezability, and fast splitting and joining of large collections. More...
 
class  AListBase
 Common base class of AList<T> and SparseAList<T>. Most of the functionality of the two types is identical, so this class is used to share code between them. More...
 
struct  AListReverseView
 A reverse view of an AList. More...
 
class  ArrayOf4
 
struct  ArraySlice
 Adapter: Provides access to a section of an array. More...
 
class  BDictionary
 An sorted dictionary that is efficient for all operations and offers indexed access to its list of key-value pairs. More...
 
class  Bijection
 A bijection is a one-to-one function and its inverse. It is implemented with a pair of dictionaries, one that maps K1 to K2 and another that maps K2 to K1. More...
 
class  BList
 An sorted in-memory list that is efficient for all operations and offers indexed access to its list. More...
 
class  BMultiMap
 An sorted dictionary that allows multiple values to be associated with a single key. Note: both keys and values must be comparable. More...
 
class  BufferedSequence
 Adapter: This class wraps an IEnumerator<T> or IEnumerable<T> into an IListSource<T>, lazily reading the sequence as TryGet is called. More...
 
class  CG
 Contains global functions of Loyc.Collections that don't belong in any specific class. More...
 
class  CollectionAsReadOnly
 Adapter: a read-only wrapper that implements ICollection(T) and IReadOnlyCollection(T), returned from LCExt.AsReadOnly<T>. More...
 
class  CollectionDebugView
 This helper class gives a nice view of a custom collection within the debugger. More...
 
class  CPStringTrie
 A compact patricia trie that uses strings as keys. More...
 
class  CPTrie
 Compact patricia tree class that stores keys as byte arrays. This class is intended to be use as a base class; a derived class can give meaning to the byte arrays, e.g. CPStringTrie encodes strings into byte arrays so they can be placed in the trie. More...
 
class  CPTrieBenchmark
 
class  CPTrieTests
 Test suite for CPStringTrie, CPByteTrie and CPIntTrie
 
class  CPValueCollection
 Provides read-only access to the values of a CPTrie. More...
 
class  DictionaryDebugView
 Workaround for a limitation of the debugger: it doesn't support CollectionDebugView<T> when T is KeyValuePair<K,V>. This class is identical, except that T is replaced with KeyValuePair{K,V}. More...
 
class  DictionaryExt
 Extension methods for Dictionary<K,V> and IDictionary<K,V>. More...
 
class  DList
 A compact auto-enlarging list that efficiently supports supports insertions at the beginning or end of the list. More...
 
class  EmptyArray
 EmptyArray<T>.Value lets you avoid allocating an empty array on the heap. More...
 
class  EmptyEnumerator
 Helper class: an empty enumerator. More...
 
class  EmptyList
 Helper class: EmptyList<T>.Value is a read-only empty list. More...
 
class  EmptySequenceException
 An exception thrown by methods or properties that require a non-empty sequence but were provided with an empty sequence. More...
 
class  EnumerableExt
 Additional extension methods for IEnumerable<T>, beyond what LINQ provides. More...
 
class  EnumerationException
 An exception thrown by an enumerator when it detects that the collection was modified after enumeration started but before it finished. More...
 
class  EnumeratorBase
 Base class to help you implement the standard IEnumerator{T} interface. All you have to do is override MoveNext() and, when successful, set the Current property. More...
 
struct  FVList
 A reference to a FVList, a so-called persistent list data structure. More...
 
class  FVListTests
 
class  FWList
 FWList is the mutable variant of the FVList data structure. More...
 
class  FWListTests
 
interface  IAdd
 An interface for depositing items. Includes only an Add(T) method. More...
 
interface  IAddRange
 An interface typically implemented alongside ICollection<T>, for collection types that can add multiple items in one method call. More...
 
interface  IArray
 This interface models the capabilities of an array: getting and setting elements by index, but not adding or removing elements. More...
 
interface  IAutoCreatePool
 Represents a pool of objects in which an object is automatically created when requested by its key. More...
 
interface  IAutoSizeArray
 An auto-sizing array is a list structure that allows you to modify the element at any index, including indices that don't yet exist; the collection automatically adds missing indices. More...
 
interface  IBinumerable
 Interface for a collection that can return IBinumerator<T>s pointing to the beginning and end of the collection. More...
 
interface  IBinumerator
 Extends the "enumerator" concept to allow backward enumeration. More...
 
interface  IBRange
 A bidirectional range. Allows you to read or remove the first or last element in a range. More...
 
interface  IBRangeEx
 A bidirectional range that can perform operations such as intersection and overlap tests on pairs of ranges of the same type. More...
 
interface  ICharSource
 A read-only list of characters plus a Slice(int,int) method. More...
 
interface  ICollectionAndReadOnly
 This interface combines the original ICollection<T> with IReadOnlyCollection<T>. It exists for the same reason as IListAndListSource<T>, to fix ambiguity errors. More...
 
interface  ICollectionEx
 This interface combines the original ICollection(T) interface with IReadOnlyCollection(T), ISinkCollection(T), and IAddRange(T), a convenient way to implement all three. More...
 
interface  ICount
 Holds the Count property found in nearly all collection interfaces. More...
 
interface  IDeque
 Represents a double-ended queue that allows items to be added or removed at the beginning or end. More...
 
interface  IFRange
 A forward range. Allows you to read the first element from the range or skip it. The forward range lays the foundation for IBRange<T> and IRange<T>. More...
 
interface  IIsEmpty
 Holds the IsEmpty property that tells you if a collection is empty. More...
 
interface  IListAndListSource
 This interface combines the original IList<T> interface with its "source" (read-only) component interfaces, including IReadOnlyList<T>, plus IListSource<T>. More...
 
interface  IListEx
 This interface combines the original IList(T) interface with several IListSource(T), ISinkList(T), IArray(T) and several additional methods (e.g. RemoveAll, InsertRange). More...
 
interface  IListRangeMethods
 An interface typically implemented alongside IList<T> for collection types that can add or remove multiple items in one method call. More...
 
interface  IListSource
 A read-only list indexed by an integer. More...
 
interface  IMBinumerator
 A mutable bidirectional enumerator interface. Please note that the "Remove" method always moves to the next item, even though the Binumerator is capable of moving backward. More...
 
interface  IMBRange
 A mutable bidirectional range. More...
 
interface  IMEnumerator
 A mutable enumerator interface. Provides a "Remove" method like Java iterators have, and allows you to modify the current item. More...
 
interface  IMFRange
 A mutable forward range. More...
 
interface  IMRange
 A mutable random-access range. More...
 
class  IndexedAList
 A simple wrapper around AList that includes an AListIndexer<K,T> that can be used to find items relatively quickly in a large list. When an index is built and the list is large, it accelerates IndexOf(item), Contains(item) and Remove(item). More...
 
interface  INegArray
 This interface models the capabilities of an array: getting and setting elements by index, but not adding or removing elements. This interface is the counterpart to IListSource<T> for lists whose minimum index is not (necessarily) zero. More...
 
interface  INegAutoSizeArray
 An auto-sizing array is a list structure that allows you to modify the element at any index, including indexes that don't yet exist; the collection automatically adds missing indexes. More...
 
interface  INegDeque
 Represents a Deque that supports negative indexes. In this kind of Deque, pushing and popping elements does not affect the indexes of the other elements in the collection. More...
 
interface  INegListSource
 This interface is the counterpart to IListSource<T> for lists whose minimum index is not (necessarily) zero. More...
 
interface  INotifyListChanging
 Encapsulates the ListChanging event that notifies listeners of dynamic changes to an indexed list, such as when items get added and removed or the whole list is refreshed. More...
 
class  InvertibleSet
 An immutable set that can be inverted. For example, an InvertibleSet<int> could contain "everything except 4 and 10", or it could contain a positive set such as "1, 2, and 3". More...
 
class  InvertibleSetTests
 
interface  IPop
 Represents a collection that produces a sequence of items, and can return the next item without popping it (the Peek operation). More...
 
interface  IPush
 Represents a collection that accepts a sequence of items. More...
 
interface  IQueue
 Represents a FIFO (first-in-first-out) queue. More...
 
interface  IRange
 A random-access range, also known as a "slice". Allows you to narrow down the range like IBRange<T> does, and also provides random access via IListSource<T>. More...
 
interface  IRangeEx
 A random-access range that can perform operations such as intersection and overlap tests on pairs of ranges of the same type. More...
 
interface  ISetImm
 An immutable set of type SetT with elements of type T. More...
 
interface  ISetOperations
 Set-combining operations: With, Without, Union, Intersect, Except, Xor. More...
 
interface  ISetTests
 Set testing operations.
 
interface  ISinkArray
 Represents a write-only array. More...
 
interface  ISinkCollection
 Represents a write-only collection: you can modify it, but you cannot learn what it contains. More...
 
interface  ISinkList
 Represents a write-only indexable list class. More...
 
interface  ISparseList
 Represents a sparse list that allows insertion and removal of items and empty spaces. In a sparse list, some spaces can be "clear" meaning that they have no value. More...
 
interface  ISparseListEx
 A sparse list that supports additional methods including InsertRange(int, ISparseListSource<T>). More...
 
interface  ISparseListSource
 Represents a read-only indexed list in which parts of the index space may be unused or "clear". More...
 
interface  IStack
 Represents a LIFO (last-in-first-out) stack. More...
 
class  KeyAlreadyExistsException
 An exception thrown by dictionary objects when they are asked to "add" a key-value pair that already exists. More...
 
class  KeyCollection
 Adapter: this is a read-only collection of Keys read from a generic IDictionary. It is a modified version of Dictionary{TKey, TValue}.KeyCollection from the Mono project, changed to use IDictionary instead of Dictionary. More...
 
class  LCExt
 Extension methods for Loyc Collection interfaces (such as IListSource<T>) and for Loyc Collection adapters (such as AsReadOnly<T>, which returns a CollectionAsReadOnly<T> adapter.) More...
 
class  LCInterfaces
 This class contains extension methods that are provided as part of various Loyc.Collections interfaces. For example, it provides methods such as IndexOf(), Contains() and CopyTo(), that the traditional ICollection<T> and IList<T> interfaces require the author to write himself. More...
 
class  LinqToCollections
 This class enhances LINQ-to-Objects with extension methods that preserve the interface (e.g. Take(List<int>) returns IList<int>) and/or have higher performance than the ones in System.Linq.Enumerable. More...
 
class  ListAsListSource
 Helper type returned from LCExt.AsListSource<T>. More...
 
struct  ListChangeInfo
 Contains information about how a collection is about to change. More...
 
class  ListExt
 Extension methods and helper methods for List<T>, IList<T>, IReadOnlyList<T>, arrays, IListSource<T>, and for related mutable interfaces such as IArray<T>. More...
 
struct  ListSlice
 Adapter: a wrapper of a list that provides a view of a range of elements. Objects of this type are returned from ListExt.Slice<T> More...
 
class  ListSourceAsList
 Adapter: a read-only wrapper that implements IList(T) and IListSource(T), returned from LCExt.AsList<T>. More...
 
class  ListSourceAsSparse
 Adapter from IListSource<T> to ISparseListSource<T>. More...
 
class  ListSourceDebugView
 This helper class gives a nice view of a custom collection within the debugger. More...
 
class  Map
 An immutable dictionary. More...
 
class  MapOrMMap
 Common base class that contains code shared between Map<K,V> and MMap<K,V>. More...
 
class  MMap
 A dictionary class built on top of InternalSet<KeyValuePair<K,V>>. More...
 
class  MSet
 A mutable set. More...
 
struct  NegList
 Adapter: provides a view of an IList<T> in which the Count is the same, but the minimum index is not necessarily zero. Returned from LCExt.NegView<T>(IList<T>,int). More...
 
struct  NegListSlice
 Adapter: a random-access range for a slice of an INegListSource<T>. More...
 
struct  NegListSource
 Adapter: provides a view of an IListSource<T> in which the Count is the same, but the minimum index is not necessarily zero. Returned from LCExt.NegView<T>(IListSource<T>,int). More...
 
struct  NestedEnumerable
 Helper type. You pass a cloneable Frame object to the constructor, and then a copy of this Frame is used to construct a new NestedEnumerator<Frame,T> each time the user calls GetEnumerator. More...
 
struct  NestedEnumerator
 Helper class. An enumerator that helps enumerate tree data structures. It maintains a virtual call stack that avoids the performance hit of using nested "yield return" statements in C#. More...
 
struct  NumRange
 Represents a range of integers of a specified data type. More...
 
struct  RangeEnumerator
 Helper struct: enumerates through a forward range (IFRange<T>). More...
 
class  RangeExt
 Extension/helper methods for ranges. More...
 
class  ReadOnlyAsCollection
 A read-only wrapper that implements ICollection(T) and ISource(T), returned from LCExt.AsCollection<T> More...
 
struct  Repeated
 Helper struct. A sequence that stores one value, but acts like a list in which that value is repeated a specified number of times. Returned from Range.Repeat<T>. More...
 
struct  ReverseBinumerator
 Adapter: a IBinumerator<T> that swaps the MoveNext() and MovePrev() methods. More...
 
struct  ReversedList
 Adapter: a reversed of an IList<T>. TODO: unit tests. More...
 
class  ReversedListSource
 Adapter: reversed view of IListSource<T> returned from LCExt.Reverse<T>. More...
 
class  SelectList
 Helper class: provides a modified view of an IList by transforming each element on-demand. Objects of this type are returned from LinqToCollections.Select<T,TResult>(IList<T>,Func<T,TResult>) More...
 
class  SelectListSource
 Helper class: provides a modified view of an IListSource by transforming each element on-demand. Objects of this type are returned from LinqToCollections.Select<T,TResult>(IListSource<T>,Func<T,TResult>) More...
 
struct  Set
 An immutable set. More...
 
class  SimpleCache
 A cache designed to save memory by sharing instances of identical strings and other immutable objects. More...
 
class  SimpleCacheTests
 
struct  Slice_
 Adapter: a random-access range for a slice of an IListSource<T>. More...
 
class  SparseAList
 A sparse A-List that implements ISparseList<T>. More...
 
struct  StringSlice
 A random-access slice of System.String. More...
 
class  UpCastListSource
 Helper class for treating a collection of a derived type as a collection of a base type or interface. More...
 
class  UpCastSource
 Helper class for treating a collection of a derived type as a collection of a base type or interface. More...
 
class  ValueCollection
 Adapter: this is a read-only collection of Values read from a generic IDictionary. It is a modified version of Dictionary{TKey, TValue}.ValueCollection from the Mono project, changed to use IDictionary instead of Dictionary. More...
 
struct  VList
 VList represents a reference to a reverse-order FVList. More...
 
class  VListBlock
 VListBlock implements the core functionality of FVList, VList, FWList and WList. It is not intended to be used directly. More...
 
class  VListBlockArray
 Implementation of VListBlock(of T) that contains an array. It is always initialized with at least one item, and items cannot be removed unless the list is mutable. More...
 
class  VListBlockOfTwo
 The tail of a VList contains only one or two items. To improve efficiency slightly, these two-item lists are represented by a VListBlockOfTwo, which is more compact than VListBlockArray. More...
 
class  VListTests
 
class  WeakKeyComparer
 Compares objects of the given type or WeakKeyReferences to them for equality based on the given comparer. Note that we can only implement IEqualityComparer<T> for T = object as there is no other common base between T and WeakKeyReference<T>. We need a single comparer to handle both types because we don't want to allocate a new weak reference for every lookup. More...
 
class  WeakKeyDictionary
 A dictionary with weak keys. More...
 
class  WeakKeyReference
 Provides a weak reference to an object of the given type to be used in a WeakDictionary along with the given comparer. More...
 
class  WeakValueDictionary
 A dictionary in which the values are weak. When a value has been garbage- collected, the dictionary acts as if the key is not present (except the Remove() method, which saves time by not checking whether the value is dead.) More...
 
class  WList
 WList is the mutable variant of the VList data structure. More...
 
class  WListBase
 Shared base class of FWList and WList. More...
 
class  WListProtected
 WList implementation in which the WList operations are only accessible to a derived class. More...
 
class  WListTests
 

Enumerations

enum  AListOperation {
  AListOperation.Retrieve = 0, AListOperation.ReplaceIfPresent = 1, AListOperation.Remove = 2,
  AListOperation.Add = 3, AListOperation.AddOrReplace = 4, AListOperation.AddIfNotPresent = 5,
  AListOperation.AddOrThrow = 6
}
 Indicates the way an add operation (such as BList<T>.Do should behave when an item being added to a set or list is a duplicate of an item that is already present, or when the key of a key-value pair being added to a dictionary is a duplicate of a key that is already present in the dictionary. More...
 
enum  XfAction {
  XfAction.Drop, XfAction.Keep, XfAction.Change,
  XfAction.Repeat
}
 Values that can be returned by the VListTransformer function that the user passes to the Transform method in FVList, VList, FWList or WList. More...
 

Functions

delegate void ListChangingHandler< T > (IListSource< T > sender, ListChangeInfo< T > args)
 Represents the method that handles the INotifyListChanging<T>.ListChanging event. More...
 
delegate XfAction VListTransformer< T > (int i, ref T item)
 User-supplied list transformer function. More...
 

Detailed Description

Contains general-purpose interfaces (Loyc.Collections.IListSource<T>, ranges, etc.), collection implementations (Loyc.Collections.DList<T>, Loyc.Collections.WeakValueDictionary<K,V>, etc.), extension methods (Loyc.Collections.LCExt, Loyc.Collections.EnumerableExt, etc.), helper classes (Loyc.Collections.EmptyList<T>, (Loyc.Collections.Repeated<T>, etc.), and adapter classes (Loyc.Collections.ListSlice<T>, Loyc.Collections.BufferedSequence<T>, etc.).

Enumeration Type Documentation

Indicates the way an add operation (such as BList<T>.Do should behave when an item being added to a set or list is a duplicate of an item that is already present, or when the key of a key-value pair being added to a dictionary is a duplicate of a key that is already present in the dictionary.

All the "add" operations are deliberately listed last, so that AListBase<K,T>.DoSingleOperation can use a greater-than operator to figure out whether an item may be added or not.

Enumerator
Retrieve 

Default operation. The item with the specified key will be retrieved. The tree will not be modified.

ReplaceIfPresent 

Replace an existing item/key if present, or do nothing if there is no matching item/key.

Remove 

Remove the item with the specified key if present.

Add 

A new item will be added unconditionally, without affecting existing elements, in no particular order with respect to existing items that have the same key.

AddOrReplace 

A new item will replace an item that has the same key. If the collection already contains multiple instances of the item/key, the instance to be replaced is undefined.

AddIfNotPresent 

A new item will be added if its key doesn't match an existing element. If the item already exists, it is not replaced.

AddOrThrow 

The item will be added if its key is not already present, but KeyAlreadyExistsException or InvalidOperationException will be thrown if the new item is equal to an existing element. If this exception occurs during an AddRange() operation, some of the items may have already been added successfully, and the changes will not be rolled back unless otherwise specified in the documentation of the method that performs the add operation.

Values that can be returned by the VListTransformer function that the user passes to the Transform method in FVList, VList, FWList or WList.

Enumerator
Drop 

Do not include the item in the output list

Keep 

Include the original item in the output list

Change 

Include the modified item in the output list

Repeat 

Include the modified item in the output, and transform it again

Function Documentation

delegate void Loyc.Collections.ListChangingHandler< T > ( IListSource< T >  sender,
ListChangeInfo< T >  args 
)

Represents the method that handles the INotifyListChanging<T>.ListChanging event.

Parameters
senderThe collection that changed.
argsInformation about the change.
delegate XfAction Loyc.Collections.VListTransformer< T > ( int  i,
ref T  item 
)

User-supplied list transformer function.

Parameters
itemAn item from the FVList or VList
iIndex of the item
Returns
See the documentation of FVList.Transform() for instructions and possible return values.