capacity
This commit is contained in:
parent
b0f2a500d6
commit
d7fac361bd
@ -3,6 +3,7 @@ using System;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace ObservableCollections
|
namespace ObservableCollections
|
||||||
{
|
{
|
||||||
@ -13,12 +14,27 @@ namespace ObservableCollections
|
|||||||
readonly Dictionary<TKey, TValue> dictionary;
|
readonly Dictionary<TKey, TValue> dictionary;
|
||||||
public object SyncRoot { get; } = new object();
|
public object SyncRoot { get; } = new object();
|
||||||
|
|
||||||
public ObservableDictionary(IEqualityComparer<TKey>? comparer = null)
|
public ObservableDictionary()
|
||||||
|
{
|
||||||
|
this.dictionary = new Dictionary<TKey, TValue>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableDictionary(IEqualityComparer<TKey>? comparer)
|
||||||
{
|
{
|
||||||
this.dictionary = new Dictionary<TKey, TValue>(comparer: comparer);
|
this.dictionary = new Dictionary<TKey, TValue>(comparer: comparer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableDictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey>? comparer = null)
|
public ObservableDictionary(int capacity, IEqualityComparer<TKey>? comparer)
|
||||||
|
{
|
||||||
|
this.dictionary = new Dictionary<TKey, TValue>(capacity, comparer: comparer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableDictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection)
|
||||||
|
: this(collection, null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableDictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey>? comparer)
|
||||||
{
|
{
|
||||||
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
|
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
|
||||||
this.dictionary = new Dictionary<TKey, TValue>(collection: collection, comparer: comparer);
|
this.dictionary = new Dictionary<TKey, TValue>(collection: collection, comparer: comparer);
|
||||||
|
@ -14,21 +14,36 @@ namespace ObservableCollections
|
|||||||
readonly HashSet<T> set;
|
readonly HashSet<T> set;
|
||||||
public object SyncRoot { get; } = new object();
|
public object SyncRoot { get; } = new object();
|
||||||
|
|
||||||
public ObservableHashSet(IEqualityComparer<T>? comparer = null)
|
public ObservableHashSet()
|
||||||
|
{
|
||||||
|
this.set = new HashSet<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableHashSet(IEqualityComparer<T>? comparer)
|
||||||
{
|
{
|
||||||
this.set = new HashSet<T>(comparer: comparer);
|
this.set = new HashSet<T>(comparer: comparer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
|
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
|
||||||
|
|
||||||
public ObservableHashSet(int capacity, IEqualityComparer<T>? comparer = null)
|
public ObservableHashSet(int capacity)
|
||||||
|
{
|
||||||
|
this.set = new HashSet<T>(capacity: capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableHashSet(int capacity, IEqualityComparer<T>? comparer)
|
||||||
{
|
{
|
||||||
this.set = new HashSet<T>(capacity: capacity, comparer: comparer);
|
this.set = new HashSet<T>(capacity: capacity, comparer: comparer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public ObservableHashSet(IEnumerable<T> collection, IEqualityComparer<T>? comparer = null)
|
public ObservableHashSet(IEnumerable<T> collection)
|
||||||
|
{
|
||||||
|
this.set = new HashSet<T>(collection: collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableHashSet(IEnumerable<T> collection, IEqualityComparer<T>? comparer)
|
||||||
{
|
{
|
||||||
this.set = new HashSet<T>(collection: collection, comparer: comparer);
|
this.set = new HashSet<T>(collection: collection, comparer: comparer);
|
||||||
}
|
}
|
||||||
@ -185,7 +200,7 @@ namespace ObservableCollections
|
|||||||
|
|
||||||
public bool TryGetValue(T equalValue, [MaybeNullWhen(false)] out T actualValue)
|
public bool TryGetValue(T equalValue, [MaybeNullWhen(false)] out T actualValue)
|
||||||
{
|
{
|
||||||
lock(SyncRoot)
|
lock (SyncRoot)
|
||||||
{
|
{
|
||||||
return set.TryGetValue(equalValue, out actualValue);
|
return set.TryGetValue(equalValue, out actualValue);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user