Show / Hide Table of Contents

Interface IMap<T, TKey>

A map between instances of two types. The polymorphism base for Map implementations in Towel.

Inherited Members
IDataStructure<T>.ToArray()
ISteppable<T>.StepperBreak<TStep>(TStep)
DataStructure.ICountable.Count
DataStructure.IClearable.Clear()
DataStructure.IAuditable<TKey>.Contains(TKey)
DataStructure.IRemovable<TKey>.TryRemove(TKey)
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 Source

Item[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 Source

GetKeys()

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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>>
  • Success: true if the key+value was added or false if not
  • ? Exception: the exception that occured if the add failed
| Improve this Doc View Source

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>
  • Success: true if the value was added or updated or false if not.
  • ? Exception: the exception that occured if the add or update failed.
  • ? Existed: if the key existed prior to the add or update
  • T? OldValue: the old value if the key existed prior to the add or update
Type Parameters
Name Description
TUpdate

The type of function to update the value if present.

| Improve this Doc View Source

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>
  • Success: true if the key was found or false if not.
  • ? Exception: the exception that occured if the get failed.
  • T? Value: the value if the key was found or default if not.
| Improve this Doc View Source

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>
  • Success: true if the key was found or false if not
  • ? Exception: the exception that occured if the add failed
  • T? OldValue: the non-updated value if the key was found or default if not
  • T? NewValue: the updated value if the key was found or default if not
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.

| Improve this Doc View Source

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>
  • Success: true if the key+value was set or false if not.
  • ? Exception: the exception that occured if the set failed.
  • ? Existed: if the key existed prior to being set
  • T? OldValue: the previous value if the key existed prior to being set
| Improve this Doc View Source

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>
  • Success: true if the key was found or false if not
  • ? Exception: the exception that occured if the add failed
  • T? OldValue: the non-updated value if the key was found or default if not
  • T? NewValue: the updated value if the key was found or default if not
Type Parameters
Name Description
TUpdate

The type of function to update the value.

Extension Methods

Steppable.Stepper<T>(ISteppable<T>, Action<T>)
Steppable.Stepper<T, TStep>(ISteppable<T>, TStep)
Steppable.StepperBreak<T>(ISteppable<T>, Func<T, StepStatus>)
DataStructure.Remove<T>(DataStructure.IRemovable<T>, T)
Map.Update<T, TKey>(IMap<T, TKey>, TKey, Func<T, T>)
Map.AddOrUpdate<T, TKey>(IMap<T, TKey>, TKey, T, Func<T, T>)
Map.Update<T, TKey, TUpdate>(IMap<T, TKey>, TKey, TUpdate)
Map.AddOrUpdate<T, TKey, TUpdate>(IMap<T, TKey>, TKey, T, TUpdate)
Map.TryUpdate<T, TKey>(IMap<T, TKey>, TKey, Func<T, T>)
Map.TryAddOrUpdate<T, TKey>(IMap<T, TKey>, TKey, T, Func<T, T>)
Map.Add<T, TKey>(IMap<T, TKey>, TKey, T)
Map.Set<T, TKey>(IMap<T, TKey>, TKey, T)
Map.Get<T, TKey>(IMap<T, TKey>, TKey)
Map.Keys<T, TKey>(IMap<T, TKey>, Action<TKey>)
Map.Keys<T, TKey, TStep>(IMap<T, TKey>, TStep)
Map.KeysBreak<T, TKey>(IMap<T, TKey>, Func<TKey, StepStatus>)
Map.Pairs<T, TKey>(IMap<T, TKey>, Action<(T Value, TKey Key)>)
Map.Pairs<T, TKey, TStep>(IMap<T, TKey>, TStep)
Map.PairsBreak<T, TKey>(IMap<T, TKey>, Func<(T Value, TKey Key), StepStatus>)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX