KGySoft.Collections Namespace

The KGySoft.Collections namespace contains generic collections. Some of them are fully compatible with already existing collections in the .NET Framework but provide better performance in several cases (such as CircularListT, CircularSortedListTKey, TValue or ThreadSafeDictionaryTKey, TValue), while others provide new functionality, such as CacheTKey, TValue or ThreadSafeCacheFactory.
See also KGySoft.ComponentModel and KGySoft.Collections.ObjectModel namespaces for some further collections such as SortableBindingListT or FastLookupCollectionT.

Classes

CacheTKey, TValue Represents a generic cache. If an item loader is specified, then cache expansion is transparent: the user needs only to read the indexer to retrieve items. When a non-existing key is accessed, then the item is loaded automatically by the loader function that was passed to the constructor. If the cache is full (elements Count reaches the Capacity) and a new element has to be stored, then the oldest or least recent used element (depends on the value of Behavior) is removed from the cache.
CircularListT Implements an IListT where inserting/removing at the beginning/end position are O(1) operations. CircularListT is fully compatible with ListT but has a better performance in several cases.
CircularSortedListTKey, TValue Represents a dictionary of key/value pairs that are sorted by key based on the associated IComparerT implementation. The dictionary behaves as list as well, as it has a direct indexed access to the elements through Keys and Values properties or by the ElementAt method. CircularSortedListTKey, TValue is fully compatible with SortedListTKey, TValue, but is generally faster than that.
LockFreeCacheOptions Represents the options for creating a fast, lock-free, thread safe cache by the ThreadSafeCacheFactory.Create<TKey, TValue> methods.
To see when to use LockFreeCacheOptions or LockingCacheOptions see the Remarks section of the CreateTKey, TValue(FuncTKey, TValue, IEqualityComparerTKey, ThreadSafeCacheOptionsBase) method.
LockingCacheOptions Represents the options for creating a thread-safe accessor by the ThreadSafeCacheFactory.Create<TKey, TValue> methods.
To see when to use LockFreeCacheOptions or LockingCacheOptions see the Remarks section of the CreateTKey, TValue(FuncTKey, TValue, IEqualityComparerTKey, ThreadSafeCacheOptionsBase) method.
LockingCollectionT Provides a simple wrapper for an ICollectionT where all members are thread-safe. This only means that the inner state of the wrapped collection remains always consistent and not that all of the multi-threading concerns can be ignored.
LockingDictionaryTKey, TValue Provides a simple wrapper for an IDictionaryTKey, TValue where all members are thread-safe. This only means that the inner state of the wrapped dictionary remains always consistent and not that all of the multi-threading concerns can be ignored.
LockingListT Provides a simple wrapper for an IListT where all members are thread-safe. This only means that the inner state of the wrapped list remains always consistent and not that all of the multi-threading concerns can be ignored.
StringKeyedDictionaryTValue Represents a string keyed dictionary that can be queried also by StringSegment and ReadOnlySpanT (in .NET Core 2.1/.NET Standard 2.1 and above) instances.
ThreadSafeCacheFactory Provides factory methods to create thread-safe cache instances as IThreadSafeCacheAccessorTKey, TValue implementations.
See the Remarks section of the CreateTKey, TValue(FuncTKey, TValue, IEqualityComparerTKey, ThreadSafeCacheOptionsBase) method for details.
ThreadSafeCacheOptionsBase Represents the options for a thread safe cache instance to be created by the ThreadSafeCacheFactory.Create<TKey, TValue> methods. You can use the LockingCacheOptions and LockFreeCacheOptions types as built-in implementations.
See the Remarks section of the CreateTKey, TValue(FuncTKey, TValue, IEqualityComparerTKey, ThreadSafeCacheOptionsBase) method for details.
ThreadSafeDictionaryTKey, TValue Implements a thread-safe dictionary, which can be a good alternative for ConcurrentDictionaryTKey, TValue where it is not available (.NET Framework 3.5), or where ConcurrentDictionaryTKey, TValue has a poorer performance.
ThreadSafeHashSetT Implements a thread-safe hash set, which has similar characteristics to ThreadSafeDictionaryTKey, TValue. It can be a good alternative for HashSetT, LockingCollectionT, or when one would use a ConcurrentDictionaryTKey, TValue with ignored values.

Structures

Array2DT Represents a rectangular array, whose indexer access is faster than a regular 2D array. It supports accessing its rows or the whole content as a single dimensional ArraySectionT or ArraySegmentT. Depending on the used platform it supports ArrayPoolT allocation and casting to SpanT.
Array3DT Represents a cubic array, whose indexer access is faster than a regular 3D array. It supports accessing its planes as Array2DT instances, or the whole content as a single dimensional ArraySectionT or ArraySegmentT. Depending on the used platform it supports ArrayPoolT allocation and casting to SpanT.
ArraySectionT Represents a one dimensional array or a section of an array. This type is very similar to ArraySegmentT/Memory<T> types but can be used on every platform in the same way, allows span-like operations such as slicing, and it is faster than Memory<T> in most cases. Depending on the used platform it supports ArrayPoolT allocation.
ArraySectionEnumeratorT Enumerates the elements of an ArraySectionT, Array2DT or Array3DT instance.
CircularListTEnumerator Enumerates the elements of a CircularListT.
CircularSortedListTKey, TValueEnumerator Enumerates the elements of a CircularSortedListTKey, TValue.
StringKeyedDictionaryTValueEnumerator Enumerates the elements of a StringKeyedDictionaryTValue.

Interfaces

ICache Provides a non-generic access to the CacheTKey, TValue class.
ICacheStatistics Represents cache statistics retrieved by GetStatistics.
IStringKeyedDictionaryTValue Represents an IDictionaryTKey, TValue with string key that can be queried also by StringSegment and ReadOnlySpanT (in .NET Core 2.1/.NET Standard 2.1 and above) instances.
IStringKeyedReadOnlyDictionaryTValue Represents an IReadOnlyDictionaryTKey, TValue with string key that can be queried also by StringSegment and ReadOnlySpanT (in .NET Core 2.1/.NET Standard 2.1 and above) instances.
ISupportsRangeCollectionT Represents a collection that supports the AddRange method.
ISupportsRangeListT Represents a list that supports range operations.
IThreadSafeCacheAccessorTKey, TValue Represents a thread-safe accessor for a cache, which provides a read-only indexer to access values. An instance can be created by the Create methods of the ThreadSafeCacheFactory class, or if you have a CacheTKey, TValue instance, you can retrieve a thread-safe accessor for it by the GetThreadSafeAccessor method.

Enumerations

CacheBehavior Possible behaviors of CacheTKey, TValue when the cache store is full and an element has to be removed.
HashingStrategy Represents a hashing strategy for some hash-based dictionaries and caches.