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.Collections.Generic; |
||
9 | using System.Linq; |
||
39 | office | 10 | using System.Threading; |
22 | office | 11 | |
12 | namespace wasSharp.Collections.Specialized |
||
13 | { |
||
14 | public class MultiKeyDictionary<K1, K2, V> : Dictionary<K1, Dictionary<K2, V>> |
||
15 | { |
||
39 | office | 16 | private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
17 | |||
22 | office | 18 | public V this[K1 key1, K2 key2] |
19 | { |
||
20 | get |
||
21 | { |
||
39 | office | 22 | SyncRoot.EnterReadLock(); |
22 | office | 23 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) |
39 | office | 24 | { |
25 | SyncRoot.ExitReadLock(); |
||
26 | return default(V); |
||
27 | } |
||
28 | var v = base[key1][key2]; |
||
29 | SyncRoot.ExitReadLock(); |
||
30 | return v; |
||
22 | office | 31 | } |
32 | set |
||
33 | { |
||
39 | office | 34 | SyncRoot.EnterWriteLock(); |
22 | office | 35 | if (!ContainsKey(key1)) |
36 | this[key1] = new Dictionary<K2, V>(); |
||
39 | office | 37 | |
22 | office | 38 | this[key1][key2] = value; |
39 | office | 39 | SyncRoot.ExitWriteLock(); |
22 | office | 40 | } |
41 | } |
||
42 | |||
39 | office | 43 | public new IEnumerable<V> Values |
44 | { |
||
45 | get |
||
46 | { |
||
47 | SyncRoot.EnterReadLock(); |
||
48 | var v = base.Values.SelectMany(baseDict => baseDict.Keys, (baseDict, baseKey) => baseDict[baseKey]); |
||
49 | SyncRoot.ExitReadLock(); |
||
50 | return v; |
||
51 | } |
||
52 | } |
||
22 | office | 53 | |
54 | public void Add(K1 key1, K2 key2, V value) |
||
55 | { |
||
39 | office | 56 | SyncRoot.EnterWriteLock(); |
22 | office | 57 | if (!ContainsKey(key1)) |
58 | this[key1] = new Dictionary<K2, V>(); |
||
39 | office | 59 | |
22 | office | 60 | this[key1][key2] = value; |
39 | office | 61 | SyncRoot.ExitWriteLock(); |
22 | office | 62 | } |
63 | |||
23 | office | 64 | public void Remove(K1 key1, K2 key2) |
65 | { |
||
39 | office | 66 | SyncRoot.EnterWriteLock(); |
23 | office | 67 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) |
39 | office | 68 | { |
69 | SyncRoot.ExitWriteLock(); |
||
23 | office | 70 | return; |
39 | office | 71 | } |
23 | office | 72 | this[key1].Remove(key2); |
73 | Remove(key1); |
||
39 | office | 74 | SyncRoot.ExitWriteLock(); |
23 | office | 75 | } |
76 | |||
22 | office | 77 | public bool ContainsKey(K1 key1, K2 key2) |
78 | { |
||
39 | office | 79 | SyncRoot.EnterReadLock(); |
80 | var c = ContainsKey(key1) && this[key1].ContainsKey(key2); |
||
81 | SyncRoot.ExitReadLock(); |
||
82 | return c; |
||
22 | office | 83 | } |
23 | office | 84 | |
85 | public bool TryGetValue(K1 key1, K2 key2, out V value) |
||
86 | { |
||
39 | office | 87 | SyncRoot.EnterReadLock(); |
23 | office | 88 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) |
89 | { |
||
39 | office | 90 | SyncRoot.ExitReadLock(); |
23 | office | 91 | value = default(V); |
92 | return false; |
||
93 | } |
||
94 | value = base[key1][key2]; |
||
39 | office | 95 | SyncRoot.ExitReadLock(); |
23 | office | 96 | return true; |
97 | } |
||
22 | office | 98 | } |
99 | |||
100 | public class MultiKeyDictionary<K1, K2, K3, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, V>> |
||
101 | { |
||
39 | office | 102 | private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
103 | |||
22 | office | 104 | public V this[K1 key1, K2 key2, K3 key3] |
105 | { |
||
39 | office | 106 | get |
107 | { |
||
108 | SyncRoot.EnterReadLock(); |
||
109 | var v = ContainsKey(key1) ? this[key1][key2, key3] : default(V); |
||
110 | SyncRoot.ExitReadLock(); |
||
111 | return v; |
||
112 | } |
||
22 | office | 113 | set |
114 | { |
||
39 | office | 115 | SyncRoot.EnterWriteLock(); |
22 | office | 116 | if (!ContainsKey(key1)) |
117 | this[key1] = new MultiKeyDictionary<K2, K3, V>(); |
||
118 | this[key1][key2, key3] = value; |
||
39 | office | 119 | SyncRoot.ExitWriteLock(); |
22 | office | 120 | } |
121 | } |
||
122 | |||
123 | public bool ContainsKey(K1 key1, K2 key2, K3 key3) |
||
124 | { |
||
39 | office | 125 | SyncRoot.EnterReadLock(); |
126 | var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3); |
||
127 | SyncRoot.ExitReadLock(); |
||
128 | return c; |
||
22 | office | 129 | } |
23 | office | 130 | |
131 | public void Add(K1 key1, K2 key2, K3 key3, V value) |
||
132 | { |
||
39 | office | 133 | SyncRoot.EnterWriteLock(); |
23 | office | 134 | if (!ContainsKey(key1)) |
135 | this[key1] = new MultiKeyDictionary<K2, K3, V>(); |
||
136 | this[key1][key2, key3] = value; |
||
39 | office | 137 | SyncRoot.ExitWriteLock(); |
23 | office | 138 | } |
139 | |||
140 | public void Remove(K1 key1, K2 key2, K3 key3) |
||
141 | { |
||
39 | office | 142 | SyncRoot.EnterWriteLock(); |
23 | office | 143 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3)) |
39 | office | 144 | { |
145 | SyncRoot.ExitWriteLock(); |
||
23 | office | 146 | return; |
39 | office | 147 | } |
23 | office | 148 | this[key1][key2].Remove(key3); |
149 | this[key1].Remove(key2); |
||
150 | Remove(key1); |
||
39 | office | 151 | SyncRoot.ExitWriteLock(); |
23 | office | 152 | } |
153 | |||
154 | public bool TryGetValue(K1 key1, K2 key2, K3 key3, out V value) |
||
155 | { |
||
39 | office | 156 | SyncRoot.EnterReadLock(); |
23 | office | 157 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3)) |
158 | { |
||
39 | office | 159 | SyncRoot.ExitReadLock(); |
23 | office | 160 | value = default(V); |
161 | return false; |
||
162 | } |
||
163 | value = base[key1][key2, key3]; |
||
39 | office | 164 | SyncRoot.ExitReadLock(); |
23 | office | 165 | return true; |
166 | } |
||
22 | office | 167 | } |
168 | |||
169 | public class MultiKeyDictionary<K1, K2, K3, K4, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, V>> |
||
170 | { |
||
39 | office | 171 | private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
172 | |||
22 | office | 173 | public V this[K1 key1, K2 key2, K3 key3, K4 key4] |
174 | { |
||
39 | office | 175 | get |
176 | { |
||
177 | SyncRoot.EnterReadLock(); |
||
178 | var v = ContainsKey(key1) ? this[key1][key2, key3, key4] : default(V); |
||
179 | SyncRoot.ExitReadLock(); |
||
180 | return v; |
||
181 | } |
||
22 | office | 182 | set |
183 | { |
||
39 | office | 184 | SyncRoot.EnterWriteLock(); |
22 | office | 185 | if (!ContainsKey(key1)) |
186 | this[key1] = new MultiKeyDictionary<K2, K3, K4, V>(); |
||
187 | this[key1][key2, key3, key4] = value; |
||
39 | office | 188 | SyncRoot.ExitWriteLock(); |
22 | office | 189 | } |
190 | } |
||
191 | |||
192 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4) |
||
193 | { |
||
39 | office | 194 | SyncRoot.EnterReadLock(); |
195 | var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4); |
||
196 | SyncRoot.ExitReadLock(); |
||
197 | return c; |
||
22 | office | 198 | } |
199 | } |
||
200 | |||
201 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, V>> |
||
202 | { |
||
39 | office | 203 | private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
204 | |||
22 | office | 205 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5] |
206 | { |
||
39 | office | 207 | get |
208 | { |
||
209 | SyncRoot.EnterReadLock(); |
||
210 | var v = ContainsKey(key1) ? this[key1][key2, key3, key4, key5] : default(V); |
||
211 | SyncRoot.ExitReadLock(); |
||
212 | return v; |
||
213 | } |
||
22 | office | 214 | set |
215 | { |
||
39 | office | 216 | SyncRoot.EnterWriteLock(); |
22 | office | 217 | if (!ContainsKey(key1)) |
218 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, V>(); |
||
219 | this[key1][key2, key3, key4, key5] = value; |
||
39 | office | 220 | SyncRoot.ExitWriteLock(); |
22 | office | 221 | } |
222 | } |
||
223 | |||
224 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5) |
||
225 | { |
||
39 | office | 226 | SyncRoot.EnterReadLock(); |
227 | var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5); |
||
228 | SyncRoot.ExitReadLock(); |
||
229 | return c; |
||
22 | office | 230 | } |
231 | } |
||
232 | |||
233 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, V> : |
||
234 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, V>> |
||
235 | { |
||
39 | office | 236 | private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
237 | |||
22 | office | 238 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6] |
239 | { |
||
39 | office | 240 | get |
241 | { |
||
242 | SyncRoot.EnterReadLock(); |
||
243 | var v = ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6] : default(V); |
||
244 | SyncRoot.ExitReadLock(); |
||
245 | return v; |
||
246 | } |
||
22 | office | 247 | set |
248 | { |
||
39 | office | 249 | SyncRoot.EnterWriteLock(); |
22 | office | 250 | if (!ContainsKey(key1)) |
251 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, V>(); |
||
252 | this[key1][key2, key3, key4, key5, key6] = value; |
||
39 | office | 253 | SyncRoot.ExitWriteLock(); |
22 | office | 254 | } |
255 | } |
||
256 | |||
257 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6) |
||
258 | { |
||
39 | office | 259 | SyncRoot.EnterReadLock(); |
260 | var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6); |
||
261 | SyncRoot.ExitReadLock(); |
||
262 | return c; |
||
22 | office | 263 | } |
264 | } |
||
265 | |||
266 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, V> : |
||
267 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>> |
||
268 | { |
||
39 | office | 269 | private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
270 | |||
22 | office | 271 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7] |
272 | { |
||
39 | office | 273 | get |
274 | { |
||
275 | SyncRoot.EnterReadLock(); |
||
276 | var v = ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7] : default(V); |
||
277 | SyncRoot.ExitReadLock(); |
||
278 | return v; |
||
279 | } |
||
22 | office | 280 | set |
281 | { |
||
39 | office | 282 | SyncRoot.EnterWriteLock(); |
22 | office | 283 | if (!ContainsKey(key1)) |
284 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>(); |
||
285 | this[key1][key2, key3, key4, key5, key6, key7] = value; |
||
39 | office | 286 | SyncRoot.ExitWriteLock(); |
22 | office | 287 | } |
288 | } |
||
289 | |||
290 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7) |
||
291 | { |
||
39 | office | 292 | SyncRoot.EnterReadLock(); |
293 | var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7); |
||
294 | SyncRoot.ExitReadLock(); |
||
295 | return c; |
||
22 | office | 296 | } |
297 | } |
||
298 | |||
299 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, V> : |
||
300 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>> |
||
301 | { |
||
39 | office | 302 | private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
303 | |||
22 | office | 304 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8] |
305 | { |
||
39 | office | 306 | get |
307 | { |
||
308 | SyncRoot.EnterReadLock(); |
||
309 | var v = ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8] : default(V); |
||
310 | SyncRoot.ExitReadLock(); |
||
311 | return v; |
||
312 | } |
||
22 | office | 313 | set |
314 | { |
||
39 | office | 315 | SyncRoot.EnterWriteLock(); |
22 | office | 316 | if (!ContainsKey(key1)) |
317 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>(); |
||
318 | this[key1][key2, key3, key4, key5, key6, key7, key8] = value; |
||
39 | office | 319 | SyncRoot.ExitWriteLock(); |
22 | office | 320 | } |
321 | } |
||
322 | |||
323 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8) |
||
324 | { |
||
39 | office | 325 | SyncRoot.EnterReadLock(); |
326 | var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8); |
||
327 | SyncRoot.ExitReadLock(); |
||
328 | return c; |
||
22 | office | 329 | } |
330 | } |
||
331 | |||
332 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, V> : |
||
333 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>> |
||
334 | { |
||
39 | office | 335 | private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
336 | |||
22 | office | 337 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9] |
338 | { |
||
39 | office | 339 | get |
340 | { |
||
341 | SyncRoot.EnterReadLock(); |
||
342 | var v = ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9] : default(V); |
||
343 | SyncRoot.ExitReadLock(); |
||
344 | return v; |
||
345 | } |
||
22 | office | 346 | set |
347 | { |
||
39 | office | 348 | SyncRoot.EnterWriteLock(); |
22 | office | 349 | if (!ContainsKey(key1)) |
350 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>(); |
||
351 | this[key1][key2, key3, key4, key5, key6, key7, key8, key9] = value; |
||
39 | office | 352 | SyncRoot.ExitWriteLock(); |
22 | office | 353 | } |
354 | } |
||
355 | |||
356 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9) |
||
357 | { |
||
39 | office | 358 | SyncRoot.EnterReadLock(); |
359 | var c = ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9); |
||
360 | SyncRoot.ExitReadLock(); |
||
361 | return c; |
||
22 | office | 362 | } |
363 | } |
||
364 | |||
365 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, V> : |
||
366 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>> |
||
367 | { |
||
39 | office | 368 | private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
369 | |||
22 | office | 370 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10] |
371 | { |
||
372 | get |
||
373 | { |
||
39 | office | 374 | SyncRoot.EnterReadLock(); |
375 | var v = ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10] : default(V); |
||
376 | SyncRoot.ExitReadLock(); |
||
377 | return v; |
||
22 | office | 378 | } |
379 | set |
||
380 | { |
||
39 | office | 381 | SyncRoot.EnterWriteLock(); |
22 | office | 382 | if (!ContainsKey(key1)) |
383 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>(); |
||
384 | this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10] = value; |
||
39 | office | 385 | SyncRoot.ExitWriteLock(); |
22 | office | 386 | } |
387 | } |
||
388 | |||
389 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, |
||
390 | K10 key10) |
||
391 | { |
||
39 | office | 392 | SyncRoot.EnterReadLock(); |
393 | var c = ContainsKey(key1) && |
||
22 | office | 394 | this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10); |
39 | office | 395 | SyncRoot.ExitReadLock(); |
396 | return c; |
||
22 | office | 397 | } |
398 | } |
||
399 | |||
400 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V> : |
||
401 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>> |
||
402 | { |
||
39 | office | 403 | private readonly ReaderWriterLockSlim SyncRoot = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
404 | |||
22 | office | 405 | public V this[ |
406 | K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10, K11 key11] |
||
407 | { |
||
408 | get |
||
409 | { |
||
39 | office | 410 | SyncRoot.EnterReadLock(); |
411 | var v = ContainsKey(key1) |
||
22 | office | 412 | ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11] |
413 | : default(V); |
||
39 | office | 414 | SyncRoot.ExitReadLock(); |
415 | return v; |
||
22 | office | 416 | } |
417 | set |
||
418 | { |
||
39 | office | 419 | SyncRoot.EnterWriteLock(); |
22 | office | 420 | if (!ContainsKey(key1)) |
421 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>(); |
||
422 | this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11] = value; |
||
39 | office | 423 | SyncRoot.ExitWriteLock(); |
22 | office | 424 | } |
425 | } |
||
426 | |||
427 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, |
||
428 | K10 key10, K11 key11) |
||
429 | { |
||
39 | office | 430 | SyncRoot.EnterReadLock(); |
431 | var c = ContainsKey(key1) && |
||
22 | office | 432 | this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10, key11); |
39 | office | 433 | SyncRoot.ExitReadLock(); |
434 | return c; |
||
22 | office | 435 | } |
436 | } |
||
27 | office | 437 | } |