Interface IMap<T, TKey>
A map between instances of two types. The polymorphism base for Map implementations in Towel.
Inherited Members
Namespace: Towel.DataStructures
Assembly: Towel.dll
Syntax
public interface IMap<T, TKey> : IDataStructure<T>, ISteppable<T>, System.Collections.Generic.IEnumerable<T>, DataStructure.ICountable, DataStructure.IClearable, DataStructure.IAuditable<TKey>, DataStructure.IRemovable<TKey>
Type Parameters
Name | Description |
---|---|
T | The generic type to be stored in this data structure. |
TKey | The type of keys used to look up items in this structure. |
Properties
| Improve this Doc View SourceItem[TKey]
Allows indexed look-up of the structure. (Set does not replace the Add() method)
Declaration
T this[TKey key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The "index" to access of the structure. |
Property Value
Type | Description |
---|---|
T | The value at the index of the requested key. |
Methods
| Improve this Doc View SourceGetKeys()
Gets an enumerator that will traverse the keys of the map.
Declaration
System.Collections.Generic.IEnumerable<TKey> GetKeys()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TKey> | An enumerator that will traverse the keys of the map. |
GetPairs()
Gets an enumerator that will traverse the pairs of the map.
Declaration
System.Collections.Generic.IEnumerable<(T Value, TKey Key)> GetPairs()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.ValueTuple<T, TKey>> | An enumerator that will traverse the pairs of the map. |
KeysBreak<TStep>(TStep)
Performs a function on every key in a map.
Declaration
StepStatus KeysBreak<TStep>(TStep step = default(TStep))
where TStep : struct, IFunc<TKey, StepStatus>
Parameters
Type | Name | Description |
---|---|---|
TStep | step | The step function to perform on every key. |
Returns
Type | Description |
---|---|
StepStatus | The status of traversal. |
Type Parameters
Name | Description |
---|---|
TStep | The type of the step function. |
KeysToArray()
Gets an array with all the keys in the map.
Declaration
TKey[] KeysToArray()
Returns
Type | Description |
---|---|
TKey[] | An array with all the keys in the map. |
PairsBreak<TStep>(TStep)
Performs a function on every pair in a map.
Declaration
StepStatus PairsBreak<TStep>(TStep step = default(TStep))
where TStep : struct, IFunc<(T Value, TKey Key), StepStatus>
Parameters
Type | Name | Description |
---|---|---|
TStep | step | The step function to perform on every pair. |
Returns
Type | Description |
---|---|
StepStatus | The status of traversal. |
Type Parameters
Name | Description |
---|---|
TStep | The type of the step function. |
PairsToArray()
Gets an array with all the pairs in the map.
Declaration
(T Value, TKey Key)[] PairsToArray()
Returns
Type | Description |
---|---|
System.ValueTuple<T, TKey>[] | An array with all the pairs in the map. |
TryAdd(TKey, T)
Tries to add a value to the map.
Declaration
(bool Success, Exception? Exception) TryAdd(TKey key, T value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the value. |
T | value | The value to be added. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>> |
|
TryAddOrUpdate<TUpdate>(TKey, T, TUpdate)
Adds or updates the value at the given key.
Declaration
(bool Success, Exception? Exception, bool? Existed, T OldValue) TryAddOrUpdate<TUpdate>(TKey key, T value, TUpdate update = default(TUpdate))
where TUpdate : struct, IFunc<T, T>
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the value to add or update. |
T | value | The value to add if not already present. |
TUpdate | update | The function to update the value if present. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>, System.Nullable<System.Boolean>, T> |
|
Type Parameters
Name | Description |
---|---|
TUpdate | The type of function to update the value if present. |
TryGet(TKey)
Tries to get a value by key.
Declaration
(bool Success, Exception? Exception, T Value) TryGet(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the value to get. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>, T> |
|
TryRemoveOrUpdate<TRemovePredicate, TUpdate>(TKey, TRemovePredicate, TUpdate)
Tries to update a value in the map the relative key exists.
Declaration
(bool Success, Exception? Exception, bool? Removed, T OldValue, T NewValue) TryRemoveOrUpdate<TRemovePredicate, TUpdate>(TKey key, TRemovePredicate removePredicate = default(TRemovePredicate), TUpdate update = default(TUpdate))
where TRemovePredicate : struct, IFunc<T, bool> where TUpdate : struct, IFunc<T, T>
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the value to update. |
TRemovePredicate | removePredicate | The predicate determining if the pair should be removed. |
TUpdate | update | The function to update the value relative to the key. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>, System.Nullable<System.Boolean>, T, T> |
|
Type Parameters
Name | Description |
---|---|
TRemovePredicate | The type of predicate determining if the pair should be removed. |
TUpdate | The type of function to update the value. |
TrySet(TKey, T)
Sets value in the map.
Declaration
(bool Success, Exception? Exception, bool? Existed, T OldValue) TrySet(TKey key, T value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the value. |
T | value | The value to be set. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>, System.Nullable<System.Boolean>, T> |
|
TryUpdate<TUpdate>(TKey, TUpdate)
Tries to update a value in the map the relative key exists.
Declaration
(bool Success, Exception? Exception, T OldValue, T NewValue) TryUpdate<TUpdate>(TKey key, TUpdate update = default(TUpdate))
where TUpdate : struct, IFunc<T, T>
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the value to update. |
TUpdate | update | The function to update the value relative to the key. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>, T, T> |
|
Type Parameters
Name | Description |
---|---|
TUpdate | The type of function to update the value. |