Updated comments and removed redundant implementation
This commit is contained in:
parent
5d8e9bc0d6
commit
5f62651a8e
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@ -14,62 +15,107 @@ namespace UniversalEditor.Collections.Generic
|
||||
private Dictionary<T1, T2> mvarForwardDictionary = new Dictionary<T1, T2>();
|
||||
private Dictionary<T2, T1> mvarBackwardDictionary = new Dictionary<T2, T1>();
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified first and second value to the collection.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first value to add.</param>
|
||||
/// <param name="value2">The second value to add.</param>
|
||||
public void Add(T1 value1, T2 value2)
|
||||
{
|
||||
this.mvarForwardDictionary.Add(value1, value2);
|
||||
this.mvarBackwardDictionary.Add(value2, value1);
|
||||
mvarForwardDictionary.Add(value1, value2);
|
||||
mvarBackwardDictionary.Add(value2, value1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the first and second value associated with the specified first value.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first value of the first-second value pair to remove.</param>
|
||||
public void RemoveByValue1(T1 value1)
|
||||
{
|
||||
T2 value2 = this.mvarForwardDictionary[value1];
|
||||
this.mvarForwardDictionary.Remove(value1);
|
||||
this.mvarBackwardDictionary.Remove(value2);
|
||||
T2 value2 = mvarForwardDictionary[value1];
|
||||
mvarForwardDictionary.Remove(value1);
|
||||
mvarBackwardDictionary.Remove(value2);
|
||||
}
|
||||
/// <summary>
|
||||
/// Removes the first and second value associated with the specified second value.
|
||||
/// </summary>
|
||||
/// <param name="value1">The second value of the first-second value pair to remove.</param>
|
||||
public void RemoveByValue2(T2 value2)
|
||||
{
|
||||
T1 value3 = this.mvarBackwardDictionary[value2];
|
||||
this.mvarForwardDictionary.Remove(value3);
|
||||
this.mvarBackwardDictionary.Remove(value2);
|
||||
T1 value1 = mvarBackwardDictionary[value2];
|
||||
mvarForwardDictionary.Remove(value1);
|
||||
mvarBackwardDictionary.Remove(value2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the first value associated with the specified second value.
|
||||
/// </summary>
|
||||
/// <param name="value2">The second value of the first-second value pair to search for.</param>
|
||||
/// <returns>The first value associated with the specified second value.</returns>
|
||||
public T1 GetValue1(T2 value2)
|
||||
{
|
||||
return this.mvarBackwardDictionary[value2];
|
||||
return mvarBackwardDictionary[value2];
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the second value associated with the specified first value.
|
||||
/// </summary>
|
||||
/// <param name="value2">The first value of the first-second value pair to search for.</param>
|
||||
/// <returns>The second value associated with the specified first value.</returns>
|
||||
public T2 GetValue2(T1 value1)
|
||||
{
|
||||
return this.mvarForwardDictionary[value1];
|
||||
}
|
||||
public bool HasValue1(T2 value2)
|
||||
{
|
||||
return this.mvarBackwardDictionary.ContainsKey(value2);
|
||||
}
|
||||
public bool HasValue2(T1 value1)
|
||||
{
|
||||
return this.mvarForwardDictionary.ContainsKey(value1);
|
||||
}
|
||||
public IEnumerator<KeyValuePair<T1, T2>> GetEnumerator()
|
||||
{
|
||||
return this.mvarForwardDictionary.GetEnumerator();
|
||||
}
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return this.mvarForwardDictionary.GetEnumerator();
|
||||
return mvarForwardDictionary[value1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the specified first value is contained in this collection.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to search for.</param>
|
||||
/// <returns>True if the value exists in the first value dictionary; otherwise, false.</returns>
|
||||
public bool ContainsValue1(T1 value)
|
||||
{
|
||||
return this.mvarForwardDictionary.ContainsKey(value);
|
||||
return mvarForwardDictionary.ContainsKey(value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Determines if the specified second value is contained in this collection.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to search for.</param>
|
||||
/// <returns>True if the value exists in the second value dictionary; otherwise, false.</returns>
|
||||
public bool ContainsValue2(T2 value)
|
||||
{
|
||||
return this.mvarBackwardDictionary.ContainsKey(value);
|
||||
return mvarBackwardDictionary.ContainsKey(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="IEnumerator" /> that can be used to iterate over this collection.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="IEnumerator" /> that can be used to iterate over this collection.</returns>
|
||||
public IEnumerator<KeyValuePair<T1, T2>> GetEnumerator()
|
||||
{
|
||||
return mvarForwardDictionary.GetEnumerator();
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets a <see cref="IEnumerator" /> that can be used to iterate over this collection.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="IEnumerator" /> that can be used to iterate over this collection.</returns>
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return mvarForwardDictionary.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of items in this collection.
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mvarForwardDictionary.Count != mvarBackwardDictionary.Count) throw new InvalidOperationException("Count mismatch");
|
||||
if (mvarForwardDictionary.Count != mvarBackwardDictionary.Count)
|
||||
{
|
||||
// this should never happen
|
||||
throw new InvalidOperationException("Count mismatch");
|
||||
}
|
||||
|
||||
// they should be equal, so choose one at random to return and hardcode it ;)
|
||||
return mvarBackwardDictionary.Count;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user