-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTwoWayDictionary.cs
More file actions
39 lines (33 loc) · 878 Bytes
/
TwoWayDictionary.cs
File metadata and controls
39 lines (33 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Collections.Generic;
namespace VT0
{
public class TwoWayDictionary<T1, T2>
{
private readonly Dictionary<T1, T2> _a = new Dictionary<T1, T2>();
private readonly Dictionary<T2, T1> _b = new Dictionary<T2, T1>();
public void Add(T1 a, T2 b)
{
_a.Add(a, b);
_b.Add(b, a);
}
public bool Remove(T1 a)
{
T2 b;
if (_a.TryGetValue(a, out b))
{
_a.Remove(a);
_b.Remove(b);
return true;
}
return false;
}
public bool TryGetValue1(T1 key, out T2 value)
{
return _a.TryGetValue(key, out value);
}
public bool TryGetValue2(T2 key, out T1 value)
{
return _b.TryGetValue(key, out value);
}
}
}