-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBetterDictionary.cs
More file actions
243 lines (243 loc) · 6.3 KB
/
BetterDictionary.cs
File metadata and controls
243 lines (243 loc) · 6.3 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Linq;
//using UnityEngine;
//
//[Serializable]
// public class BetterDictionary<TKey, TValue> : IDictionary<TKey, TValue>
// {
// [SerializeField]
// protected List<TKey> keys;
//
// [SerializeField]
// protected List<TValue> values;
//
// public List<TKey> Keys { get { return keys; } }
//
// public List<TValue> Values { get { return values; } }
//
// public int Count { get { return keys.Count; } }
//
// public BetterDictionary() : this(new List<TKey>(), new List<TValue>())
// {}
//
// public BetterDictionary(List<TKey> keys, List<TValue> values) {
// this.keys = keys;
// this.values = values;
// }
//
// public TValue this[TKey key] {
// get {
// int index;
// if (!TryGetIndex(key, out index)) {
// throw new KeyNotFoundException(key.ToString());
// }
// return values[index];
// }
// set {
// int index;
// if (!TryGetIndex(key, out index))
// Add(key, value);
// else values[index] = value;
// }
// }
//
// public void SetKeyAt(int i, TKey value)
// {
// AssertIndexInBounds(i);
// if (value != null && !value.Equals(keys[i]))
// AssertUniqueKey(value);
// keys[i] = value;
// }
//
// public TKey GetKeyAt(int i)
// {
// AssertIndexInBounds(i);
// return keys[i];
// }
//
// public void SetValueAt(int i, TValue value)
// {
// AssertIndexInBounds(i);
// values[i] = value;
// }
//
// public TValue GetValueAt(int i)
// {
// AssertIndexInBounds(i);
// return values[i];
// }
//
// public KeyValuePair<TKey, TValue> GetPairAt(int i)
// {
// AssertIndexInBounds(i);
// return new KeyValuePair<TKey, TValue>(keys[i], values[i]);
// }
//
// private void AssertIndexInBounds(int i)
// {
// if (!keys.InBounds(i))
// throw new IndexOutOfRangeException("i");
// }
//
// public void Clear()
// {
// keys.Clear();
// values.Clear();
// }
//
// public void Insert(int i, TKey key, TValue value)
// {
// AssertUniqueKey(key);
// if (key == null)
// Debug.LogError(key + " - Dictionary key cannot be null");
// keys.Insert(i, key);
// values.Insert(i, value);
// }
//
// private void AssertUniqueKey(TKey key)
// {
// if (ContainsKey(key))
// throw new ArgumentException(string.Format("There's already a key `{0}` defined in the dictionary", key.ToString()));
// }
//
// public void Insert(TKey key, TValue value)
// {
// Insert(0, key, value);
// }
//
// public void Add(TKey key, TValue value)
// {
// Insert(Count, key, value);
// }
//
// public bool Remove(TKey key)
// {
// int index;
// if (TryGetIndex(key, out index)) {
// keys.RemoveAt(index);
// values.RemoveAt(index);
// return true;
// }
// return false;
// }
//
// public void RemoveAt(int i)
// {
// AssertIndexInBounds(i);
// keys.RemoveAt(i);
// values.RemoveAt(i);
// }
//
// public void RemoveLast()
// {
// RemoveAt(Count - 1);
// }
//
// public void RemoveFirst()
// {
// RemoveAt(0);
// }
//
// public bool TryGetValue(TKey key, out TValue result)
// {
// int index;
// if (!TryGetIndex(key, out index)) {
// result = default(TValue);
// return false;
// }
// result = values[index];
// return true;
// }
//
// public bool ContainsValue(TValue value)
// {
// return values.Contains(value);
// }
//
// public bool ContainsKey(TKey key)
// {
// return keys.Contains(key);
// }
//
// private bool TryGetIndex(TKey key, out int index)
// {
// return (index = keys.IndexOf(key)) != -1;
// }
//
// public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
// {
// for (int i = 0; i < Count; i++)
// yield return new KeyValuePair<TKey, TValue>(keys[i], values[i]);
// }
//
// IEnumerator IEnumerable.GetEnumerator()
// {
// return GetEnumerator();
// }
//
// ICollection<TKey> IDictionary<TKey, TValue>.Keys {
// get { return keys; }
// }
//
// bool IDictionary<TKey, TValue>.Remove(TKey key)
// {
// return Remove(key);
// }
//
// ICollection<TValue> IDictionary<TKey, TValue>.Values {
// get { return values; }
// }
//
// public void Add(KeyValuePair<TKey, TValue> item)
// {
// keys.Add(item.Key);
// values.Add(item.Value);
// }
//
// public bool Contains(KeyValuePair<TKey, TValue> item)
// {
// return ContainsKey(item.Key);
// }
//
// public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
// {
// for (int i = arrayIndex; i < array.Length; i++)
// array[i] = new KeyValuePair<TKey, TValue>(keys[i], values[i]);
// }
//
// public bool IsReadOnly {
// get { return false; }
// }
//
// public bool Remove(KeyValuePair<TKey, TValue> item)
// {
// return Remove(item.Key);
// }
// }
//
// public static class BetterDictionaryExtensions {
// public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this BetterDictionary<TKey, TValue> d)
// {
// return CreateDictionary(d.Keys, d.Values);
// }
//
// public static BetterDictionary<TKey, TValue> ToKVPList<TKey, TValue>(this IDictionary<TKey, TValue> d)
// {
// return new BetterDictionary<TKey, TValue>(d.Keys.ToList(), d.Values.ToList());
// }
//
// /// <summary> Creates a dictionary out of the passed keys and values </summary>
// public static Dictionary<T, U> CreateDictionary<T, U>(IEnumerable<T> keys, IList<U> values)
// {
// return keys.Select((k, i) => new { k, v = values[i] }).ToDictionary(x => x.k, x => x.v);
// }
//
// public static bool InBounds<T>(this IList<T> list, int i)
// {
// return i > -1 && i < list.Count;
// }
// }
//
//