PairSet
Represents a collection of key-value pairs that supports bidirectional lookup by key or value.
Наследует: KeyedCollection<T, T>
Конструкторы
public PairSet(IEqualityComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
pairSet = PairSet(keyComparer, valueComparer)
Initializes a new instance of the PairSet class with specified key and value comparers.
- keyComparer
- The equality comparer for keys, or null to use the default comparer.
- valueComparer
- The equality comparer for values, or null to use the default comparer.
public PairSet(IEqualityComparer<TKey> comparer)
pairSet = PairSet(comparer)
Initializes a new instance of the PairSet class with a specified key comparer.
- comparer
- The equality comparer for keys, or null to use the default comparer.
public PairSet()
pairSet = PairSet()
Initializes a new instance of the PairSet class with default comparers.
Свойства
public TKey Item { get; }
value = pairSet.Item
Gets the key associated with the specified value.
- value
- The value to look up.
Возвращает: The key associated with the specified value.
Методы
protected override bool CanAdd(TKey key, TValue value)
result = pairSet.CanAdd(key, value)
Determines whether a key-value pair can be added to the collection.
- key
- The key to check.
- value
- The value to check.
Возвращает: True if the value is not already associated with a key; otherwise, false.
public bool ContainsValue(TValue value)
result = pairSet.ContainsValue(value)
Determines whether the collection contains a specific value.
- value
- The value to check.
Возвращает: True if the value exists in the collection; otherwise, false.
public TKey GetKey(TValue value)
result = pairSet.GetKey(value)
Retrieves the key associated with the specified value.
- value
- The value to look up.
Возвращает: The key associated with the specified value.
public TValue GetValue(TKey key)
result = pairSet.GetValue(key)
Retrieves the value associated with the specified key.
- key
- The key to look up.
Возвращает: The value associated with the specified key.
protected override void OnAdding(TKey key, TValue value)
pairSet.OnAdding(key, value)
Called before adding a key-value pair to the collection, updating the value-to-key mapping.
- key
- The key being added.
- value
- The value being added.
protected override void OnClearing()
pairSet.OnClearing()
Called before clearing the collection, clearing the value-to-key mapping.
protected override void OnRemoving(TKey key, TValue value)
pairSet.OnRemoving(key, value)
Called before removing a key-value pair, updating the value-to-key mapping.
- key
- The key being removed.
- value
- The value being removed.
protected override void OnSetting(TKey key, TValue value)
pairSet.OnSetting(key, value)
Called before setting a new value for an existing key, updating the value-to-key mapping. Maintains bijective property by swapping values when a collision occurs.
- key
- The key being updated.
- value
- The new value to set.
public bool RemoveByValue(TValue value)
result = pairSet.RemoveByValue(value)
Removes a key-value pair from the collection based on the specified value.
- value
- The value to remove.
Возвращает: True if the value was found and removed; otherwise, false.
public void SetKey(TValue value, TKey key)
pairSet.SetKey(value, key)
Sets a new key for an existing value, replacing any previous association.
- value
- The value to associate with the new key.
- key
- The new key to associate with the value.
public void SetValue(TKey key, TValue value)
pairSet.SetValue(key, value)
Sets a new value for an existing key, updating the internal value-to-key mapping.
- key
- The key whose value is to be updated.
- value
- The new value to associate with the key.
public bool TryAdd(TKey key, TValue value)
result = pairSet.TryAdd(key, value)
Attempts to add a key-value pair to the collection if neither the key nor value already exists.
- key
- The key to add.
- value
- The value to add.
Возвращает: True if the pair was added; false if either the key or value already exists.
public bool TryGetKey(TValue value, TKey key)
result = pairSet.TryGetKey(value, key)
Attempts to retrieve the key associated with a specified value.
- value
- The value to look up.
- key
- When this method returns, contains the key if found; otherwise, the default value of .
Возвращает: True if the value was found; otherwise, false.