Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Mirror #619

Merged
merged 6 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 67 additions & 77 deletions EpicOnlineTransport/BidirectionalDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,81 +50,71 @@
/// MIT License
/// </summary>

namespace EpicTransport;

public class BidirectionalDictionary<T1, T2> : IEnumerable
{
private Dictionary<T1, T2> t1ToT2Dict = new();
private Dictionary<T2, T1> t2ToT1Dict = new();

public IEnumerable<T1> FirstTypes => t1ToT2Dict.Keys;
public IEnumerable<T2> SecondTypes => t2ToT1Dict.Keys;

public IEnumerator GetEnumerator() => t1ToT2Dict.GetEnumerator();

public int Count => t1ToT2Dict.Count;

public void Add(T1 key, T2 value)
{
t1ToT2Dict[key] = value;
t2ToT1Dict[value] = key;
}

public void Add(T2 key, T1 value)
{
t2ToT1Dict[key] = value;
t1ToT2Dict[value] = key;
}

public T2 Get(T1 key) => t1ToT2Dict[key];

public T1 Get(T2 key) => t2ToT1Dict[key];

public bool TryGetValue(T1 key, out T2 value) => t1ToT2Dict.TryGetValue(key, out value);

public bool TryGetValue(T2 key, out T1 value) => t2ToT1Dict.TryGetValue(key, out value);

public bool Contains(T1 key) => t1ToT2Dict.ContainsKey(key);

public bool Contains(T2 key) => t2ToT1Dict.ContainsKey(key);

public void Remove(T1 key)
{
if (Contains(key))
{
var val = t1ToT2Dict[key];
t1ToT2Dict.Remove(key);
t2ToT1Dict.Remove(val);
}
}

public void Remove(T2 key)
{
if (Contains(key))
{
var val = t2ToT1Dict[key];
t1ToT2Dict.Remove(val);
t2ToT1Dict.Remove(key);
}
}

public T1 this[T2 key]
{
get => t2ToT1Dict[key];
set
{
t2ToT1Dict[key] = value;
t1ToT2Dict[value] = key;
}
}

public T2 this[T1 key]
{
get => t1ToT2Dict[key];
set
{
t1ToT2Dict[key] = value;
t2ToT1Dict[value] = key;
}
}
namespace EpicTransport {

public class BidirectionalDictionary<T1, T2> : IEnumerable {
private Dictionary<T1, T2> t1ToT2Dict = new Dictionary<T1, T2>();
private Dictionary<T2, T1> t2ToT1Dict = new Dictionary<T2, T1>();

public IEnumerable<T1> FirstTypes => t1ToT2Dict.Keys;
public IEnumerable<T2> SecondTypes => t2ToT1Dict.Keys;

public IEnumerator GetEnumerator() => t1ToT2Dict.GetEnumerator();

public int Count => t1ToT2Dict.Count;

public void Add(T1 key, T2 value) {
t1ToT2Dict[key] = value;
t2ToT1Dict[value] = key;
}

public void Add(T2 key, T1 value) {
t2ToT1Dict[key] = value;
t1ToT2Dict[value] = key;
}

public T2 Get(T1 key) => t1ToT2Dict[key];

public T1 Get(T2 key) => t2ToT1Dict[key];

public bool TryGetValue(T1 key, out T2 value) => t1ToT2Dict.TryGetValue(key, out value);

public bool TryGetValue(T2 key, out T1 value) => t2ToT1Dict.TryGetValue(key, out value);

public bool Contains(T1 key) => t1ToT2Dict.ContainsKey(key);

public bool Contains(T2 key) => t2ToT1Dict.ContainsKey(key);

public void Remove(T1 key) {
if (Contains(key)) {
T2 val = t1ToT2Dict[key];
t1ToT2Dict.Remove(key);
t2ToT1Dict.Remove(val);
}
}
public void Remove(T2 key) {
if (Contains(key)) {
T1 val = t2ToT1Dict[key];
t1ToT2Dict.Remove(val);
t2ToT1Dict.Remove(key);
}
}

public T1 this[T2 key] {
get => t2ToT1Dict[key];
set {
t2ToT1Dict[key] = value;
t1ToT2Dict[value] = key;
}
}

public T2 this[T1 key] {
get => t1ToT2Dict[key];
set {
t1ToT2Dict[key] = value;
t2ToT1Dict[value] = key;
}
}

}
}
Loading