PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue > Class Template Reference

Provides a Dictionary class which returns default values for unknown keys (like Python's defaultdict) More...

Inheritance diagram for PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >:

Public Member Functions

 DefaultDictionary (DefaultDictionaryFlags flags)
 Create the default dictionary with the default resolver (returning default(TValue)) and the provided flags.
 DefaultDictionary ()
 Constructs a DefaultDictionary where missing key lookups return the default value for TValue.
 DefaultDictionary (Func< TValue > defaultResolver)
 Constructs a DefaultDictionary where missing key lookups return the value provided by the default resolver.
 DefaultDictionary (Func< TValue > defaultResolver, DefaultDictionaryFlags flags)
 Creates the default dictionary with the provided default resolver, optionally storing resolved defaults for later re-use.
 DefaultDictionary (Func< TValue > defaultResolver, IEqualityComparer< TKey > keyComparer)
 Creates the default dictionary with the provided default resolver and key comparer.
 DefaultDictionary (Func< TValue > defaultResolver, IEqualityComparer< TKey > keyComparer, DefaultDictionaryFlags flags)
 Creates the default dictionary with the provided resolver and key comparer, choosing to store (and re-serve) resolved defaults when storeResolvedDefaults is true.
 DefaultDictionary (Func< TKey, TValue > smartResolver)
 Constructs a DefaultDictionary where missing key lookups return the value provided by the default resolver.
IEnumerator< KeyValuePair< TKey, TValue > > GetEnumerator ()
 Gets an enumerator for known items in the dictionary.
void Remove (object key)
void Add (KeyValuePair< TKey, TValue > item)
 Adds an item to the dictionary.
bool Contains (object key)
void Add (object key, object value)
void Clear ()
 Removes all known items from the dictionary -> NB: you'll still get default values!
bool Contains (KeyValuePair< TKey, TValue > item)
 Searches for an item in the dictionary.
void CopyTo (KeyValuePair< TKey, TValue >[] array, int arrayIndex)
 Copies known items to the target array.
bool Remove (KeyValuePair< TKey, TValue > item)
 Removes an item from the dictionary.
void CopyTo (Array array, int index)
bool ContainsKey (TKey key)
 Always returns true - if the key is "unknown" a default can still be provided.
void Add (TKey key, TValue value)
 Adds an item by key, value to the dictionary.
bool Remove (TKey key)
 Removes an item by key from the dictionary.
bool TryGetValue (TKey key, out TValue value)
 Tries to get a known value for the key, falling back on the default value.

Properties

IEqualityComparer< TKey > Comparer [get]
 Always report as case- and culture- insensitive.
object this[object key] [get, set]
int Count [get]
 Gives the count of known items in the dictionary.
object SyncRoot = new() [get]
bool IsSynchronized [get]
bool IsReadOnly [get]
 Always returns false - DefaultDictionaries are writable!
bool IsFixedSize [get]
TValue this[TKey key] [get, set]
 Index into the dictionary.
ICollection< TKey > Keys [get]
 Returns a collection of all known keys.
ICollection< TValue > Values [get]
 Returns a collection of all known values.

Detailed Description

Provides a Dictionary class which returns default values for unknown keys (like Python's defaultdict)

Template Parameters
TKey
TValue

Member Function Documentation

◆ Add() [1/2]

void PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.Add ( KeyValuePair< TKey, TValue > item)

Adds an item to the dictionary.

Parameters
itemKeyValuePair to add

◆ Add() [2/2]

void PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.Add ( TKey key,
TValue value )

Adds an item by key, value to the dictionary.

Parameters
keyKey to add
valueValue to add

◆ Contains()

bool PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.Contains ( KeyValuePair< TKey, TValue > item)

Searches for an item in the dictionary.

Parameters
itemItem to search for
Returns
True if found, False otherwise

◆ ContainsKey()

bool PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.ContainsKey ( TKey key)

Always returns true - if the key is "unknown" a default can still be provided.

Parameters
keyKey to search for
Returns
True

◆ CopyTo()

void PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.CopyTo ( KeyValuePair< TKey, TValue >[] array,
int arrayIndex )

Copies known items to the target array.

Parameters
arrayArray to copy to
arrayIndexposition to start copying at

◆ DefaultDictionary() [1/6]

PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.DefaultDictionary ( DefaultDictionaryFlags flags)

Create the default dictionary with the default resolver (returning default(TValue)) and the provided flags.

Parameters
flags

◆ DefaultDictionary() [2/6]

PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.DefaultDictionary ( Func< TKey, TValue > smartResolver)

Constructs a DefaultDictionary where missing key lookups return the value provided by the default resolver.

Parameters
smartResolver

◆ DefaultDictionary() [3/6]

PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.DefaultDictionary ( Func< TValue > defaultResolver)

Constructs a DefaultDictionary where missing key lookups return the value provided by the default resolver.

Parameters
defaultResolver

◆ DefaultDictionary() [4/6]

PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.DefaultDictionary ( Func< TValue > defaultResolver,
DefaultDictionaryFlags flags )

Creates the default dictionary with the provided default resolver, optionally storing resolved defaults for later re-use.

Parameters
defaultResolver
flags

◆ DefaultDictionary() [5/6]

PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.DefaultDictionary ( Func< TValue > defaultResolver,
IEqualityComparer< TKey > keyComparer )

Creates the default dictionary with the provided default resolver and key comparer.

Parameters
defaultResolver
keyComparer
Exceptions
ArgumentNullException

◆ DefaultDictionary() [6/6]

PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.DefaultDictionary ( Func< TValue > defaultResolver,
IEqualityComparer< TKey > keyComparer,
DefaultDictionaryFlags flags )

Creates the default dictionary with the provided resolver and key comparer, choosing to store (and re-serve) resolved defaults when storeResolvedDefaults is true.

Parameters
defaultResolver
keyComparer
flags
Exceptions
ArgumentNullException

◆ GetEnumerator()

IEnumerator< KeyValuePair< TKey, TValue > > PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.GetEnumerator ( )

Gets an enumerator for known items in the dictionary.

Returns
Enumerator of TKey/TValue

◆ Remove() [1/2]

bool PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.Remove ( KeyValuePair< TKey, TValue > item)

Removes an item from the dictionary.

Parameters
itemItem to remove
Returns
True if found and removed, False otherwise

◆ Remove() [2/2]

bool PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.Remove ( TKey key)

Removes an item by key from the dictionary.

Parameters
keyKey to remove
Returns
True if found and removed, False otherwise

◆ TryGetValue()

bool PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.TryGetValue ( TKey key,
out TValue value )

Tries to get a known value for the key, falling back on the default value.

Parameters
keyKey to look up
value(out) parameter containing looked up (or default) value
Returns
Always true

Property Documentation

◆ this[TKey key]

TValue PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.this[TKey key]
getset

Index into the dictionary.

Parameters
keyKey to look up

The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.Utils/Dictionaries/DefaultDictionary.cs