wasSharp – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
22 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
||
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
||
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
||
5 | /////////////////////////////////////////////////////////////////////////// |
||
27 | office | 6 | // Based on the work of Herman Schoenfeld |
22 | office | 7 | |
8 | using System; |
||
9 | using System.Collections.Generic; |
||
10 | using System.Linq; |
||
11 | |||
12 | namespace wasSharp.Collections.Specialized |
||
13 | { |
||
14 | public class MultiKeyDictionary<K1, K2, V> : Dictionary<K1, Dictionary<K2, V>> |
||
15 | { |
||
16 | public V this[K1 key1, K2 key2] |
||
17 | { |
||
18 | get |
||
19 | { |
||
20 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) |
||
21 | throw new ArgumentOutOfRangeException(); |
||
22 | return base[key1][key2]; |
||
23 | } |
||
24 | set |
||
25 | { |
||
26 | if (!ContainsKey(key1)) |
||
27 | this[key1] = new Dictionary<K2, V>(); |
||
28 | this[key1][key2] = value; |
||
29 | } |
||
30 | } |
||
31 | |||
23 | office | 32 | public new IEnumerable<V> Values => |
33 | base.Values.SelectMany(baseDict => baseDict.Keys, (baseDict, baseKey) => baseDict[baseKey]); |
||
22 | office | 34 | |
35 | public void Add(K1 key1, K2 key2, V value) |
||
36 | { |
||
37 | if (!ContainsKey(key1)) |
||
38 | this[key1] = new Dictionary<K2, V>(); |
||
39 | this[key1][key2] = value; |
||
40 | } |
||
41 | |||
23 | office | 42 | public void Remove(K1 key1, K2 key2) |
43 | { |
||
44 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) |
||
45 | return; |
||
46 | this[key1].Remove(key2); |
||
47 | Remove(key1); |
||
48 | } |
||
49 | |||
22 | office | 50 | public bool ContainsKey(K1 key1, K2 key2) |
51 | { |
||
23 | office | 52 | return ContainsKey(key1) && this[key1].ContainsKey(key2); |
22 | office | 53 | } |
23 | office | 54 | |
55 | public bool TryGetValue(K1 key1, K2 key2, out V value) |
||
56 | { |
||
57 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) |
||
58 | { |
||
59 | value = default(V); |
||
60 | return false; |
||
61 | } |
||
62 | value = base[key1][key2]; |
||
63 | return true; |
||
64 | } |
||
22 | office | 65 | } |
66 | |||
67 | public class MultiKeyDictionary<K1, K2, K3, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, V>> |
||
68 | { |
||
69 | public V this[K1 key1, K2 key2, K3 key3] |
||
70 | { |
||
71 | get { return ContainsKey(key1) ? this[key1][key2, key3] : default(V); } |
||
72 | set |
||
73 | { |
||
74 | if (!ContainsKey(key1)) |
||
75 | this[key1] = new MultiKeyDictionary<K2, K3, V>(); |
||
76 | this[key1][key2, key3] = value; |
||
77 | } |
||
78 | } |
||
79 | |||
80 | public bool ContainsKey(K1 key1, K2 key2, K3 key3) |
||
81 | { |
||
23 | office | 82 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3); |
22 | office | 83 | } |
23 | office | 84 | |
85 | public void Add(K1 key1, K2 key2, K3 key3, V value) |
||
86 | { |
||
87 | if (!ContainsKey(key1)) |
||
88 | this[key1] = new MultiKeyDictionary<K2, K3, V>(); |
||
89 | this[key1][key2, key3] = value; |
||
90 | } |
||
91 | |||
92 | public void Remove(K1 key1, K2 key2, K3 key3) |
||
93 | { |
||
94 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3)) |
||
95 | return; |
||
96 | this[key1][key2].Remove(key3); |
||
97 | this[key1].Remove(key2); |
||
98 | Remove(key1); |
||
99 | } |
||
100 | |||
101 | public bool TryGetValue(K1 key1, K2 key2, K3 key3, out V value) |
||
102 | { |
||
103 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3)) |
||
104 | { |
||
105 | value = default(V); |
||
106 | return false; |
||
107 | } |
||
108 | value = base[key1][key2, key3]; |
||
109 | return true; |
||
110 | } |
||
22 | office | 111 | } |
112 | |||
113 | public class MultiKeyDictionary<K1, K2, K3, K4, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, V>> |
||
114 | { |
||
115 | public V this[K1 key1, K2 key2, K3 key3, K4 key4] |
||
116 | { |
||
117 | get { return ContainsKey(key1) ? this[key1][key2, key3, key4] : default(V); } |
||
118 | set |
||
119 | { |
||
120 | if (!ContainsKey(key1)) |
||
121 | this[key1] = new MultiKeyDictionary<K2, K3, K4, V>(); |
||
122 | this[key1][key2, key3, key4] = value; |
||
123 | } |
||
124 | } |
||
125 | |||
126 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4) |
||
127 | { |
||
23 | office | 128 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4); |
22 | office | 129 | } |
130 | } |
||
131 | |||
132 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, V>> |
||
133 | { |
||
134 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5] |
||
135 | { |
||
136 | get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5] : default(V); } |
||
137 | set |
||
138 | { |
||
139 | if (!ContainsKey(key1)) |
||
140 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, V>(); |
||
141 | this[key1][key2, key3, key4, key5] = value; |
||
142 | } |
||
143 | } |
||
144 | |||
145 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5) |
||
146 | { |
||
23 | office | 147 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5); |
22 | office | 148 | } |
149 | } |
||
150 | |||
151 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, V> : |
||
152 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, V>> |
||
153 | { |
||
154 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6] |
||
155 | { |
||
156 | get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6] : default(V); } |
||
157 | set |
||
158 | { |
||
159 | if (!ContainsKey(key1)) |
||
160 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, V>(); |
||
161 | this[key1][key2, key3, key4, key5, key6] = value; |
||
162 | } |
||
163 | } |
||
164 | |||
165 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6) |
||
166 | { |
||
23 | office | 167 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6); |
22 | office | 168 | } |
169 | } |
||
170 | |||
171 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, V> : |
||
172 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>> |
||
173 | { |
||
174 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7] |
||
175 | { |
||
176 | get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7] : default(V); } |
||
177 | set |
||
178 | { |
||
179 | if (!ContainsKey(key1)) |
||
180 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>(); |
||
181 | this[key1][key2, key3, key4, key5, key6, key7] = value; |
||
182 | } |
||
183 | } |
||
184 | |||
185 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7) |
||
186 | { |
||
23 | office | 187 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7); |
22 | office | 188 | } |
189 | } |
||
190 | |||
191 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, V> : |
||
192 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>> |
||
193 | { |
||
194 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8] |
||
195 | { |
||
196 | get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8] : default(V); } |
||
197 | set |
||
198 | { |
||
199 | if (!ContainsKey(key1)) |
||
200 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>(); |
||
201 | this[key1][key2, key3, key4, key5, key6, key7, key8] = value; |
||
202 | } |
||
203 | } |
||
204 | |||
205 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8) |
||
206 | { |
||
23 | office | 207 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8); |
22 | office | 208 | } |
209 | } |
||
210 | |||
211 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, V> : |
||
212 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>> |
||
213 | { |
||
214 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9] |
||
215 | { |
||
216 | get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9] : default(V); } |
||
217 | set |
||
218 | { |
||
219 | if (!ContainsKey(key1)) |
||
220 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>(); |
||
221 | this[key1][key2, key3, key4, key5, key6, key7, key8, key9] = value; |
||
222 | } |
||
223 | } |
||
224 | |||
225 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9) |
||
226 | { |
||
23 | office | 227 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9); |
22 | office | 228 | } |
229 | } |
||
230 | |||
231 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, V> : |
||
232 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>> |
||
233 | { |
||
234 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10] |
||
235 | { |
||
236 | get |
||
237 | { |
||
238 | return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10] : default(V); |
||
239 | } |
||
240 | set |
||
241 | { |
||
242 | if (!ContainsKey(key1)) |
||
243 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>(); |
||
244 | this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10] = value; |
||
245 | } |
||
246 | } |
||
247 | |||
248 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, |
||
249 | K10 key10) |
||
250 | { |
||
23 | office | 251 | return ContainsKey(key1) && |
22 | office | 252 | this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10); |
253 | } |
||
254 | } |
||
255 | |||
256 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V> : |
||
257 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>> |
||
258 | { |
||
259 | public V this[ |
||
260 | K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10, K11 key11] |
||
261 | { |
||
262 | get |
||
263 | { |
||
264 | return ContainsKey(key1) |
||
265 | ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11] |
||
266 | : default(V); |
||
267 | } |
||
268 | set |
||
269 | { |
||
270 | if (!ContainsKey(key1)) |
||
271 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>(); |
||
272 | this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11] = value; |
||
273 | } |
||
274 | } |
||
275 | |||
276 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, |
||
277 | K10 key10, K11 key11) |
||
278 | { |
||
23 | office | 279 | return ContainsKey(key1) && |
22 | office | 280 | this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10, key11); |
281 | } |
||
282 | } |
||
27 | office | 283 | } |