Divooka Reference

Dictionary Routines

22 nodes

On this page 22

Add

Function

Adds a new entry, throwing System.ArgumentException if the dictionary already has the key, so an accidental duplicate is caught rather than silently overwriting.

Signature
Add
    dictionary: Dictionary of TKey to TValue
    key: TKey
    value: TValue
void Add(
    Dictionary<TKey, TValue> dictionary,
    TKey key,
    TValue value)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to change; must not be null.
keyTKey—The new key; a null key throws System.ArgumentNullException.
valueTValue—The value to store.
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Add Or Reject Duplicate

Function

Adds a new entry like DictionaryRoutines.TryAdd, and when the key already exists also gives you a message naming the duplicate key, ready to show or log; the existing entry is left untouched.

Signature
AddOrRejectDuplicate -> (result: Truth, error: Text)
    dictionary: Dictionary of TKey to TValue
    key: TKey
    value: TValue
bool AddOrRejectDuplicate(
    Dictionary<TKey, TValue> dictionary,
    TKey key,
    TValue value,
    out string error)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to change; must not be null.
keyTKey—The new key; a null key throws System.ArgumentNullException.
valueTValue—The value to store.

Returns

resultTruth
errorText
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Add Range

Function

Adds many key/value pairs at once, in the order given.

Signature
AddRange
    dictionary: Dictionary of TKey to TValue
    items: IEnumerable<KeyValuePair<TKey, TValue>>
    overwriteExisting: Truth
void AddRange(
    Dictionary<TKey, TValue> dictionary,
    IEnumerable<KeyValuePair<TKey, TValue>> items,
    bool overwriteExisting = false)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to change; must not be null.
itemsIEnumerable<KeyValuePair<TKey, TValue>>—The pairs to add; must not be null.
overwriteExistingTruthFalseWhen true, a key that already exists (or repeats within Items) takes the later value. When false, the first such key throws System.ArgumentException, and the pairs added before it stay in the dictionary.
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Capacity

Function

How many entries the dictionary can hold before it next has to grow its storage; always at least its count.

Signature
Capacity(dictionary: Dictionary of TKey to TValue) -> Integer
int Capacity(Dictionary<TKey, TValue> dictionary)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to inspect; must not be null.

Returns

resultInteger
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Clear

Function

Removes every entry; the dictionary keeps its current capacity, so refilling it does not have to grow it again.

Signature
Clear(dictionary: Dictionary of TKey to TValue)
void Clear(Dictionary<TKey, TValue> dictionary)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to empty; must not be null.
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Clone

Function

Makes a new dictionary holding the same entries as Source; adding or removing entries in one afterwards does not affect the other, but the values themselves are not copied, so a value of a reference type is shared by both.

Signature
Clone -> Dictionary of TKey to TValue
    source: Dictionary of TKey to TValue
    comparer: IEqualityComparer<TKey>
Dictionary<TKey, TValue> Clone(
    Dictionary<TKey, TValue> source,
    IEqualityComparer<TKey> comparer)

Parameters

nametypedefaultdescription
sourceDictionary of TKey to TValue—The dictionary to copy; must not be null.
comparerIEqualityComparer<TKey>—How the copy compares keys; null means the key type's default equality, not the comparer Source uses. If this comparer treats two of the source's keys as the same, System.ArgumentException is thrown.

Returns

resultDictionary of TKey to TValue
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Comparer

Function

The comparer the dictionary uses to decide whether two keys are the same, so you can make another dictionary that matches keys the same way.

Signature
Comparer(dictionary: Dictionary of TKey to TValue) -> IEqualityComparer<TKey>
IEqualityComparer<TKey> Comparer(Dictionary<TKey, TValue> dictionary)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to inspect; must not be null.

Returns

resultIEqualityComparer<TKey>
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Contains Key

Function

Whether the dictionary has an entry for Key, matched with the dictionary's key comparer.

Signature
ContainsKey -> Truth
    dictionary: Dictionary of TKey to TValue
    key: TKey
bool ContainsKey(Dictionary<TKey, TValue> dictionary, TKey key)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to search; must not be null.
keyTKey—The key to look for; a null key throws System.ArgumentNullException.

Returns

resultTruth
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Contains Value

Function

Whether any entry has Value as its value, compared with the value type's default equality.

Signature
ContainsValue -> Truth
    dictionary: Dictionary of TKey to TValue
    value: TValue
bool ContainsValue(
    Dictionary<TKey, TValue> dictionary,
    TValue value)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to search; must not be null.
valueTValue—The value to look for; may be null.

Returns

resultTruth

Remarks

Unlike a key lookup this checks every entry in turn, so it gets slower as the dictionary grows.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Count

Function

How many key/value pairs the dictionary holds.

Signature
Count(dictionary: Dictionary of TKey to TValue) -> Integer
int Count(Dictionary<TKey, TValue> dictionary)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to measure; must not be null.

Returns

resultInteger
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Create

Function

Overload 1 of 4

Signature
Create() -> Dictionary of TKey to TValue
Dictionary<TKey, TValue> Create()

Makes a new, empty dictionary whose keys are compared with the key type's default equality.

Returns

resultDictionary of TKey to TValue

Overload 2 of 4

Signature
Create(capacity: Integer) -> Dictionary of TKey to TValue
Dictionary<TKey, TValue> Create(int capacity)

Makes a new, empty dictionary with room reserved for at least Capacity entries, so it does not have to grow while you fill it; use it when you know roughly how many entries are coming.

Parameters

nametypedefaultdescription
capacityInteger—How many entries to reserve room for; a negative number throws System.ArgumentOutOfRangeException.

Returns

resultDictionary of TKey to TValue

Overload 3 of 4

Signature
Create(comparer: IEqualityComparer<TKey>) -> Dictionary of TKey to TValue
Dictionary<TKey, TValue> Create(IEqualityComparer<TKey> comparer)

Makes a new, empty dictionary that uses Comparer to decide whether two keys are the same, for example StringComparer.OrdinalIgnoreCase for case-insensitive text keys.

Parameters

nametypedefaultdescription
comparerIEqualityComparer<TKey>—How keys are compared; null means the key type's default equality.

Returns

resultDictionary of TKey to TValue

Overload 4 of 4

Signature
Create -> Dictionary of TKey to TValue
    capacity: Integer
    comparer: IEqualityComparer<TKey>
Dictionary<TKey, TValue> Create(
    int capacity,
    IEqualityComparer<TKey> comparer)

Makes a new, empty dictionary with room reserved for at least Capacity entries and keys compared by Comparer.

Parameters

nametypedefaultdescription
capacityInteger—How many entries to reserve room for; a negative number throws System.ArgumentOutOfRangeException.
comparerIEqualityComparer<TKey>—How keys are compared; null means the key type's default equality.

Returns

resultDictionary of TKey to TValue
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Ensure Capacity

Function

Grows the dictionary's storage, if needed, so it can hold at least Capacity entries without growing again; it never shrinks it.

Signature
EnsureCapacity -> Integer
    dictionary: Dictionary of TKey to TValue
    capacity: Integer
int EnsureCapacity(
    Dictionary<TKey, TValue> dictionary,
    int capacity)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to change; must not be null.
capacityInteger—The number of entries to make room for; a negative number throws System.ArgumentOutOfRangeException.

Returns

resultInteger
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Get

Function

The value stored under Key; use it when the key must be there, and DictionaryRoutines.GetOrDefault or DictionaryRoutines.TryGet when it may not be.

Signature
Get -> TValue
    dictionary: Dictionary of TKey to TValue
    key: TKey
TValue Get(Dictionary<TKey, TValue> dictionary, TKey key)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to read; must not be null.
keyTKey—The key to look up; a missing key throws Generic.KeyNotFoundException and a null key throws System.ArgumentNullException.

Returns

ResultTValue
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Get Or Default

Function

The value stored under Key, or Default Value when the dictionary has no such key.

Signature
GetOrDefault -> TValue
    dictionary: Dictionary of TKey to TValue
    key: TKey
    defaultValue: TValue
TValue GetOrDefault(
    Dictionary<TKey, TValue> dictionary,
    TKey key,
    TValue defaultValue)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to read; must not be null.
keyTKey—The key to look up; a null key throws System.ArgumentNullException.
defaultValueTValue—What to answer when the key is missing; when omitted, the value type's default (0, false or null).

Returns

ResultTValue
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Keys

Function

The dictionary's keys, in no guaranteed order.

Signature
Keys(dictionary: Dictionary of TKey to TValue) -> Dictionary<TKey, TValue>.KeyCollection
Dictionary<TKey, TValue>.KeyCollection Keys(Dictionary<TKey, TValue> dictionary)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to read; must not be null.

Returns

resultDictionary<TKey, TValue>.KeyCollection

Remarks

This is a live view rather than a copy: it reflects later additions and removals, and enumerating it while the dictionary is changed throws System.InvalidOperationException. Use DictionaryRoutines.ToArray for a snapshot.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Remove

Function

Overload 1 of 2

Signature
Remove -> Truth
    dictionary: Dictionary of TKey to TValue
    key: TKey
bool Remove(Dictionary<TKey, TValue> dictionary, TKey key)

Removes the entry for Key, if there is one.

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to change; must not be null.
keyTKey—The key to remove; a null key throws System.ArgumentNullException.

Returns

resultTruth

Overload 2 of 2

Signature
Remove -> (result: Truth, value: TValue)
    dictionary: Dictionary of TKey to TValue
    key: TKey
bool Remove(
    Dictionary<TKey, TValue> dictionary,
    TKey key,
    out TValue value)

Removes the entry for Key and hands back the value it held, so you can take an item out and use it in one step.

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to change; must not be null.
keyTKey—The key to remove; a null key throws System.ArgumentNullException.

Returns

resultTruth
valueTValue
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Set

Function

Stores Value under Key, adding a new entry or replacing the value already there; use DictionaryRoutines.Add instead when a duplicate key should be an error.

Signature
Set
    dictionary: Dictionary of TKey to TValue
    key: TKey
    value: TValue
void Set(
    Dictionary<TKey, TValue> dictionary,
    TKey key,
    TValue value)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to change; must not be null.
keyTKey—The key to store under; a null key throws System.ArgumentNullException.
valueTValue—The value to store.
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

To Array

Function

Copies every key/value pair into a new array, a snapshot that later changes to the dictionary do not affect.

Signature
ToArray(dictionary: Dictionary of TKey to TValue) -> KeyValuePair<TKey, TValue> Array
KeyValuePair<TKey, TValue>[] ToArray(Dictionary<TKey, TValue> dictionary)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to copy; must not be null.

Returns

resultKeyValuePair<TKey, TValue> Array
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Trim Excess

Function

Overload 1 of 2

Signature
TrimExcess(dictionary: Dictionary of TKey to TValue)
void TrimExcess(Dictionary<TKey, TValue> dictionary)

Shrinks the dictionary's storage to fit the entries it holds now, giving back memory after many removals.

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to change; must not be null.

Overload 2 of 2

Signature
TrimExcess
    dictionary: Dictionary of TKey to TValue
    capacity: Integer
void TrimExcess(
    Dictionary<TKey, TValue> dictionary,
    int capacity)

Shrinks the dictionary's storage to fit Capacity entries, leaving room to grow to that size without reallocating.

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to change; must not be null.
capacityInteger—The number of entries to keep room for; less than the current count throws System.ArgumentOutOfRangeException.
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Try Add

Function

Adds a new entry only if the key is not already there; an existing entry is left untouched.

Signature
TryAdd -> Truth
    dictionary: Dictionary of TKey to TValue
    key: TKey
    value: TValue
bool TryAdd(
    Dictionary<TKey, TValue> dictionary,
    TKey key,
    TValue value)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to change; must not be null.
keyTKey—The new key; a null key throws System.ArgumentNullException.
valueTValue—The value to store.

Returns

resultTruth
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Try Get

Function

Looks up Key without failing when it is missing, telling you both whether it was found and what it holds.

Signature
TryGet -> (result: Truth, value: TValue)
    dictionary: Dictionary of TKey to TValue
    key: TKey
bool TryGet(
    Dictionary<TKey, TValue> dictionary,
    TKey key,
    out TValue value)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to read; must not be null.
keyTKey—The key to look up; a null key throws System.ArgumentNullException.

Returns

resultTruth
valueTValue
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library

Values

Function

The dictionary's values, in the same order as DictionaryRoutines.Keys.

Signature
Values(dictionary: Dictionary of TKey to TValue) -> Dictionary<TKey, TValue>.ValueCollection
Dictionary<TKey, TValue>.ValueCollection Values(Dictionary<TKey, TValue> dictionary)

Parameters

nametypedefaultdescription
dictionaryDictionary of TKey to TValue—The dictionary to read; must not be null.

Returns

resultDictionary<TKey, TValue>.ValueCollection

Remarks

This is a live view rather than a copy: it reflects later changes, and enumerating it while the dictionary is changed throws System.InvalidOperationException.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Dictionary Routines
Package
Standard Library