9public static class ImmutableDictionary
84 return source.ToImmutableDictionary(
keySelector, (TSource v) => v, keyComparer,
null);
104 return source.ToImmutableDictionary(keyComparer,
null);
109 return source.ToImmutableDictionary(
null,
null);
135[DebuggerDisplay(
"Count = {Count}")]
137public sealed class ImmutableDictionary<TKey, TValue> :
IImmutableDictionary<TKey, TValue>,
IReadOnlyDictionary<TKey, TValue>,
IEnumerable<KeyValuePair<TKey, TValue>>,
IEnumerable,
IReadOnlyCollection<KeyValuePair<TKey, TValue>>,
IImmutableDictionaryInternal<TKey, TValue>,
IHashKeyCollection<TKey>,
IDictionary<TKey, TValue>,
ICollection<KeyValuePair<TKey, TValue>>,
IDictionary,
ICollection where TKey :
notnull
139 [DebuggerDisplay(
"Count = {Count}")]
141 public sealed class Builder :
IDictionary<TKey, TValue>,
ICollection<KeyValuePair<TKey, TValue>>,
IEnumerable<KeyValuePair<TKey, TValue>>,
IEnumerable,
IReadOnlyDictionary<TKey, TValue>,
IReadOnlyCollection<KeyValuePair<TKey, TValue>>,
IDictionary,
ICollection
226 bool IDictionary.IsFixedSize =>
false;
228 bool IDictionary.IsReadOnly =>
false;
235 object ICollection.SyncRoot
248 bool ICollection.IsSynchronized =>
false;
254 return this[(TKey)
key];
283 public TValue
this[TKey
key]
416 return Apply(result);
479 return result.CountAdjustment != 0;
501 Requires.NotNull(keyComparer,
"keyComparer");
533 Requires.NotNull(keyComparer,
"keyComparer");
839 value =
default(TValue);
851 value =
default(TValue);
1048 bool IDictionary.IsFixedSize =>
true;
1050 bool IDictionary.IsReadOnly =>
true;
1062 return this[(TKey)
key];
1071 object ICollection.SyncRoot =>
this;
1074 bool ICollection.IsSynchronized =>
true;
1187 if (keyComparer ==
null)
1412 value =
default(TValue);
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ContainsKey(TKey key)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
void AddRange(IEnumerable< KeyValuePair< TKey, TValue > > collection)
bool ICollection< KeyValuePair< TKey, TValue > >. IsReadOnly
Enumerator GetEnumerator()
void Add(TKey key, TValue value)
bool Contains(KeyValuePair< TKey, TValue > item)
IEqualityComparer< TValue > ValueComparer
Enumerator GetEnumerator()
Builder(ImmutableDictionary< TKey, TValue > map)
void Add(TKey key, TValue value)
SortedInt32KeyNode< HashBucket > Root
IDictionaryEnumerator IDictionary. GetEnumerator()
void RemoveRange(IEnumerable< TKey > keys)
ImmutableDictionary< TKey, TValue > _immutable
bool ContainsValue(TValue value)
bool ContainsKey(TKey key)
void AddRange(IEnumerable< KeyValuePair< TKey, TValue > > items)
SortedInt32KeyNode< HashBucket > _root
IEnumerable< TValue > Values
TValue GetValueOrDefault(TKey key, TValue defaultValue)
bool TryGetKey(TKey equalKey, out TKey actualKey)
bool IDictionary. Contains(object key)
bool Remove(KeyValuePair< TKey, TValue > item)
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
ImmutableDictionary< TKey, TValue > ToImmutable()
void IDictionary. Remove(object key)
void Add(KeyValuePair< TKey, TValue > item)
bool Apply(MutationResult result)
IEqualityComparer< TKey > KeyComparer
TValue? GetValueOrDefault(TKey key)
static readonly Comparers Default
IEqualityComparer< TKey > KeyComparer
Comparers WithValueComparer(IEqualityComparer< TValue > valueComparer)
Comparers(IEqualityComparer< TKey > keyComparer, IEqualityComparer< TValue > valueComparer)
readonly IEqualityComparer< TKey > _keyComparer
readonly IEqualityComparer< TValue > _valueComparer
static Comparers Get(IEqualityComparer< TKey > keyComparer, IEqualityComparer< TValue > valueComparer)
IEqualityComparer< HashBucket > HashBucketEqualityComparer
IEqualityComparer< TValue > ValueComparer
IEqualityComparer< KeyValuePair< TKey, TValue > > KeyOnlyComparer
int GetHashCode(HashBucket obj)
bool Equals(HashBucket x, HashBucket y)
ImmutableDictionary< TKey, TValue > WithComparers(IEqualityComparer< TKey >? keyComparer)
ImmutableDictionary< TKey, TValue > SetItem(TKey key, TValue value)
bool Contains(KeyValuePair< TKey, TValue > pair)
static bool TryGetValue(TKey key, MutationInput origin, [MaybeNullWhen(false)] out TValue value)
readonly SortedInt32KeyNode< HashBucket > _root
static ImmutableDictionary< TKey, TValue > Wrap(SortedInt32KeyNode< HashBucket > root, Comparers comparers, int count)
ImmutableDictionary< TKey, TValue > SetItems(IEnumerable< KeyValuePair< TKey, TValue > > items)
ImmutableDictionary< TKey, TValue > Add(TKey key, TValue value)
bool TryGetKey(TKey equalKey, out TKey actualKey)
ImmutableDictionary< TKey, TValue > WithComparers(IEqualityComparer< TKey >? keyComparer, IEqualityComparer< TValue >? valueComparer)
ImmutableDictionary< TKey, TValue > Remove(TKey key)
static bool Contains(KeyValuePair< TKey, TValue > keyValuePair, MutationInput origin)
static MutationResult Remove(TKey key, MutationInput origin)
bool ContainsKey(TKey key)
SortedInt32KeyNode< HashBucket > Root
static ImmutableDictionary< TKey, TValue > EmptyWithComparers(Comparers comparers)
IEqualityComparer< TValue > ValueComparer
static readonly Action< KeyValuePair< int, HashBucket > > s_FreezeBucketAction
static ? TValue GetValueOrDefault< TKey, TValue >(this IImmutableDictionary< TKey, TValue > dictionary, TKey key)
static ImmutableDictionary< TKey, TValue > ToImmutableDictionary< TSource, TKey, TValue >(this IEnumerable< TSource > source, Func< TSource, TKey > keySelector, Func< TSource, TValue > elementSelector, IEqualityComparer< TKey >? keyComparer, IEqualityComparer< TValue >? valueComparer)
static SortedInt32KeyNode< HashBucket > UpdateRoot(SortedInt32KeyNode< HashBucket > root, int hashCode, HashBucket newBucket, IEqualityComparer< HashBucket > hashBucketComparer)
ImmutableDictionary< TKey, TValue > RemoveRange(IEnumerable< TKey > keys)
static ImmutableDictionary< TKey, TSource > ToImmutableDictionary< TSource, TKey >(this IEnumerable< TSource > source, Func< TSource, TKey > keySelector)
readonly Comparers _comparers
ImmutableDictionary< TKey, TValue > Clear()
static bool ContainsKey(TKey key, MutationInput origin)
static MutationResult AddRange(IEnumerable< KeyValuePair< TKey, TValue > > items, MutationInput origin, KeyCollisionBehavior collisionBehavior=KeyCollisionBehavior.ThrowIfValueDifferent)
IEnumerable< TValue > Values
Enumerator GetEnumerator()
static MutationResult Add(TKey key, TValue value, KeyCollisionBehavior behavior, MutationInput origin)
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
static bool Contains< TKey, TValue >(this IImmutableDictionary< TKey, TValue > map, TKey key, TValue value)
static ImmutableDictionary< TKey, TValue > Create< TKey, TValue >()
ImmutableDictionary< TKey, TValue > AddRange(IEnumerable< KeyValuePair< TKey, TValue > > pairs, bool avoidToHashMap)
ImmutableDictionary< TKey, TValue > AddRange(IEnumerable< KeyValuePair< TKey, TValue > > pairs)
static ImmutableDictionary< TKey, TValue > CreateRange< TKey, TValue >(IEnumerable< KeyValuePair< TKey, TValue > > items)
ImmutableDictionary< TKey, TValue > Wrap(SortedInt32KeyNode< HashBucket > root, int adjustedCountIfDifferentRoot)
static ImmutableDictionary< TKey, TValue > ToImmutableDictionary< TKey, TValue >(this ImmutableDictionary< TKey, TValue >.Builder builder)
IEqualityComparer< TKey > KeyComparer
ImmutableDictionary(Comparers comparers=null)
static bool TryGetKey(TKey equalKey, MutationInput origin, out TKey actualKey)
bool ContainsValue(TValue value)
ImmutableDictionary(SortedInt32KeyNode< HashBucket > root, Comparers comparers, int count)
static readonly ImmutableDictionary< TKey, TValue > Empty
static bool TryCastToImmutableMap(IEnumerable< KeyValuePair< TKey, TValue > > sequence, [NotNullWhen(true)] out ImmutableDictionary< TKey, TValue > other)
static ImmutableDictionary< TKey, TValue >.Builder CreateBuilder< TKey, TValue >()
ImmutableList< T > Add(T value)
ImmutableList< T > RemoveAt(int index)
int IndexOf(T item, int index, int count, IEqualityComparer< T >? equalityComparer)
ref readonly T ItemRef(int index)
static void Range(bool condition, string? parameterName, string? message=null)
static string Format(string resourceFormat, object p1)
static string CollectionModifiedDuringEnumeration
static string DuplicateKey
static string Arg_KeyNotFoundWithKey
static int CompareExchange(ref int location1, int value, int comparand)
void CopyTo(Array array, int index)
new IDictionaryEnumerator GetEnumerator()
void Add(object key, object? value)
bool Contains(object key)
IEnumerator GetEnumerator()
new bool Equals(object? x, object? y)
int GetHashCode(object obj)
Enumerator(SortedInt32KeyNode< HashBucket > root, Builder? builder=null)
readonly Builder _builder
HashBucket.Enumerator _bucketEnumerator
int _enumeratingBuilderVersion
SortedInt32KeyNode< HashBucket >.Enumerator _mapEnumerator
object IEnumerator. Current
KeyValuePair< TKey, TValue > Current
object IEnumerator. Current
Position _currentPosition
Enumerator(HashBucket bucket)
readonly HashBucket _bucket
ImmutableList< KeyValuePair< TKey, TValue > >.Enumerator _additionalEnumerator
readonly ImmutableList< KeyValuePair< TKey, TValue > >.Node _additionalElements
HashBucket Remove(TKey key, IEqualityComparer< KeyValuePair< TKey, TValue > > keyOnlyComparer, out OperationResult result)
Enumerator GetEnumerator()
HashBucket(KeyValuePair< TKey, TValue > firstElement, ImmutableList< KeyValuePair< TKey, TValue > >.Node additionalElements=null)
bool TryGetValue(TKey key, Comparers comparers, [MaybeNullWhen(false)] out TValue value)
override int GetHashCode()
readonly KeyValuePair< TKey, TValue > _firstValue
bool TryGetKey(TKey equalKey, Comparers comparers, out TKey actualKey)
KeyValuePair< TKey, TValue > FirstValue
HashBucket Add(TKey key, TValue value, IEqualityComparer< KeyValuePair< TKey, TValue > > keyOnlyComparer, IEqualityComparer< TValue > valueComparer, KeyCollisionBehavior behavior, out OperationResult result)
ImmutableList< KeyValuePair< TKey, TValue > >.Node AdditionalElements
override bool Equals(object? obj)
MutationResult(MutationInput unchangedInput)
ImmutableDictionary< TKey, TValue > Finalize(ImmutableDictionary< TKey, TValue > priorMap)
readonly int _countAdjustment
SortedInt32KeyNode< HashBucket > Root
MutationResult(SortedInt32KeyNode< HashBucket > root, int countAdjustment)
readonly SortedInt32KeyNode< HashBucket > _root