wasSharp – Blame information for rev 44
?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 | { |
||
44 | office | 16 | private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
39 | office | 17 | |
22 | office | 18 | public V this[K1 key1, K2 key2] |
19 | { |
||
20 | get |
||
21 | { |
||
44 | office | 22 | _lock.EnterReadLock(); |
23 | try |
||
39 | office | 24 | { |
44 | office | 25 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) |
26 | { |
||
27 | return default(V); |
||
28 | } |
||
29 | return base[key1][key2]; |
||
39 | office | 30 | } |
44 | office | 31 | finally |
32 | { |
||
33 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
34 | } |
||
22 | office | 35 | } |
36 | set |
||
37 | { |
||
44 | office | 38 | _lock.EnterWriteLock(); |
39 | try |
||
40 | { |
||
41 | if (!ContainsKey(key1)) |
||
42 | this[key1] = new Dictionary<K2, V>(); |
||
39 | office | 43 | |
44 | office | 44 | this[key1][key2] = value; |
45 | } |
||
46 | finally |
||
47 | { |
||
48 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
49 | } |
||
22 | office | 50 | } |
51 | } |
||
52 | |||
39 | office | 53 | public new IEnumerable<V> Values |
54 | { |
||
55 | get |
||
56 | { |
||
44 | office | 57 | _lock.EnterReadLock(); |
58 | try |
||
59 | { |
||
60 | return base.Values.SelectMany(baseDict => baseDict.Keys, (baseDict, baseKey) => baseDict[baseKey]); |
||
61 | } |
||
62 | finally |
||
63 | { |
||
64 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
65 | } |
||
39 | office | 66 | } |
67 | } |
||
22 | office | 68 | |
69 | public void Add(K1 key1, K2 key2, V value) |
||
70 | { |
||
44 | office | 71 | _lock.EnterWriteLock(); |
72 | try |
||
73 | { |
||
74 | if (!ContainsKey(key1)) |
||
75 | this[key1] = new Dictionary<K2, V>(); |
||
39 | office | 76 | |
44 | office | 77 | this[key1][key2] = value; |
78 | } |
||
79 | finally |
||
80 | { |
||
81 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
82 | } |
||
22 | office | 83 | } |
84 | |||
23 | office | 85 | public void Remove(K1 key1, K2 key2) |
86 | { |
||
44 | office | 87 | _lock.EnterWriteLock(); |
88 | try |
||
39 | office | 89 | { |
44 | office | 90 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) |
91 | { |
||
92 | return; |
||
93 | } |
||
94 | this[key1].Remove(key2); |
||
95 | Remove(key1); |
||
39 | office | 96 | } |
44 | office | 97 | finally |
98 | { |
||
99 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
100 | } |
||
23 | office | 101 | } |
102 | |||
22 | office | 103 | public bool ContainsKey(K1 key1, K2 key2) |
104 | { |
||
44 | office | 105 | _lock.EnterReadLock(); |
106 | try |
||
107 | { |
||
108 | return ContainsKey(key1) && this[key1].ContainsKey(key2); |
||
109 | } |
||
110 | finally |
||
111 | { |
||
112 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
113 | } |
||
22 | office | 114 | } |
23 | office | 115 | |
116 | public bool TryGetValue(K1 key1, K2 key2, out V value) |
||
117 | { |
||
44 | office | 118 | _lock.EnterReadLock(); |
119 | try |
||
23 | office | 120 | { |
44 | office | 121 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) |
122 | { |
||
123 | value = default(V); |
||
124 | return false; |
||
125 | } |
||
126 | value = base[key1][key2]; |
||
127 | return true; |
||
23 | office | 128 | } |
44 | office | 129 | finally |
130 | { |
||
131 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
132 | } |
||
23 | office | 133 | } |
22 | office | 134 | } |
135 | |||
136 | public class MultiKeyDictionary<K1, K2, K3, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, V>> |
||
137 | { |
||
44 | office | 138 | private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
39 | office | 139 | |
22 | office | 140 | public V this[K1 key1, K2 key2, K3 key3] |
141 | { |
||
39 | office | 142 | get |
143 | { |
||
44 | office | 144 | _lock.EnterReadLock(); |
145 | try |
||
146 | { |
||
147 | return ContainsKey(key1) ? this[key1][key2, key3] : default(V); |
||
148 | } |
||
149 | finally |
||
150 | { |
||
151 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
152 | } |
||
39 | office | 153 | } |
22 | office | 154 | set |
155 | { |
||
44 | office | 156 | _lock.EnterWriteLock(); |
157 | try |
||
158 | { |
||
159 | if (!ContainsKey(key1)) |
||
160 | this[key1] = new MultiKeyDictionary<K2, K3, V>(); |
||
161 | |||
162 | this[key1][key2, key3] = value; |
||
163 | } |
||
164 | finally |
||
165 | { |
||
166 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
167 | } |
||
22 | office | 168 | } |
169 | } |
||
170 | |||
171 | public bool ContainsKey(K1 key1, K2 key2, K3 key3) |
||
172 | { |
||
44 | office | 173 | _lock.EnterReadLock(); |
174 | try |
||
175 | { |
||
176 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3); |
||
177 | } |
||
178 | finally |
||
179 | { |
||
180 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
181 | } |
||
22 | office | 182 | } |
23 | office | 183 | |
184 | public void Add(K1 key1, K2 key2, K3 key3, V value) |
||
185 | { |
||
44 | office | 186 | _lock.EnterWriteLock(); |
187 | try |
||
188 | { |
||
189 | if (!ContainsKey(key1)) |
||
190 | this[key1] = new MultiKeyDictionary<K2, K3, V>(); |
||
191 | this[key1][key2, key3] = value; |
||
192 | } |
||
193 | finally |
||
194 | { |
||
195 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
196 | } |
||
23 | office | 197 | } |
198 | |||
199 | public void Remove(K1 key1, K2 key2, K3 key3) |
||
200 | { |
||
44 | office | 201 | _lock.EnterWriteLock(); |
202 | try |
||
39 | office | 203 | { |
44 | office | 204 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3)) |
205 | { |
||
206 | return; |
||
207 | } |
||
208 | this[key1][key2].Remove(key3); |
||
209 | this[key1].Remove(key2); |
||
210 | Remove(key1); |
||
39 | office | 211 | } |
44 | office | 212 | finally |
213 | { |
||
214 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
215 | } |
||
23 | office | 216 | } |
217 | |||
218 | public bool TryGetValue(K1 key1, K2 key2, K3 key3, out V value) |
||
219 | { |
||
44 | office | 220 | _lock.EnterReadLock(); |
221 | try |
||
23 | office | 222 | { |
44 | office | 223 | if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3)) |
224 | { |
||
225 | value = default(V); |
||
226 | return false; |
||
227 | } |
||
228 | value = base[key1][key2, key3]; |
||
229 | return true; |
||
23 | office | 230 | } |
44 | office | 231 | finally |
232 | { |
||
233 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
234 | } |
||
23 | office | 235 | } |
22 | office | 236 | } |
237 | |||
238 | public class MultiKeyDictionary<K1, K2, K3, K4, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, V>> |
||
239 | { |
||
44 | office | 240 | private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
39 | office | 241 | |
22 | office | 242 | public V this[K1 key1, K2 key2, K3 key3, K4 key4] |
243 | { |
||
39 | office | 244 | get |
245 | { |
||
44 | office | 246 | _lock.EnterReadLock(); |
247 | try |
||
248 | { |
||
249 | return ContainsKey(key1) ? this[key1][key2, key3, key4] : default(V); |
||
250 | } |
||
251 | finally |
||
252 | { |
||
253 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
254 | } |
||
39 | office | 255 | } |
22 | office | 256 | set |
257 | { |
||
44 | office | 258 | _lock.EnterWriteLock(); |
259 | try |
||
260 | { |
||
261 | if (!ContainsKey(key1)) |
||
262 | this[key1] = new MultiKeyDictionary<K2, K3, K4, V>(); |
||
263 | this[key1][key2, key3, key4] = value; |
||
264 | } |
||
265 | finally |
||
266 | { |
||
267 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
268 | } |
||
22 | office | 269 | } |
270 | } |
||
271 | |||
272 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4) |
||
273 | { |
||
44 | office | 274 | _lock.EnterReadLock(); |
275 | try |
||
276 | { |
||
277 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4); |
||
278 | } |
||
279 | finally |
||
280 | { |
||
281 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
282 | } |
||
22 | office | 283 | } |
284 | } |
||
285 | |||
286 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, V>> |
||
287 | { |
||
44 | office | 288 | private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
39 | office | 289 | |
22 | office | 290 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5] |
291 | { |
||
39 | office | 292 | get |
293 | { |
||
44 | office | 294 | _lock.EnterReadLock(); |
295 | try |
||
296 | { |
||
297 | return ContainsKey(key1) ? this[key1][key2, key3, key4, key5] : default(V); |
||
298 | } |
||
299 | finally |
||
300 | { |
||
301 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
302 | } |
||
39 | office | 303 | } |
22 | office | 304 | set |
305 | { |
||
44 | office | 306 | _lock.EnterWriteLock(); |
307 | try |
||
308 | { |
||
309 | if (!ContainsKey(key1)) |
||
310 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, V>(); |
||
311 | this[key1][key2, key3, key4, key5] = value; |
||
312 | } |
||
313 | finally |
||
314 | { |
||
315 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
316 | } |
||
22 | office | 317 | } |
318 | } |
||
319 | |||
320 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5) |
||
321 | { |
||
44 | office | 322 | _lock.EnterReadLock(); |
323 | try |
||
324 | { |
||
325 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5); |
||
326 | } |
||
327 | finally |
||
328 | { |
||
329 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
330 | } |
||
22 | office | 331 | } |
332 | } |
||
333 | |||
334 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, V> : |
||
335 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, V>> |
||
336 | { |
||
44 | office | 337 | private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
39 | office | 338 | |
22 | office | 339 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6] |
340 | { |
||
39 | office | 341 | get |
342 | { |
||
44 | office | 343 | _lock.EnterReadLock(); |
344 | try |
||
345 | { |
||
346 | return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6] : default(V); |
||
347 | } |
||
348 | finally |
||
349 | { |
||
350 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
351 | } |
||
39 | office | 352 | } |
22 | office | 353 | set |
354 | { |
||
44 | office | 355 | _lock.EnterWriteLock(); |
356 | try |
||
357 | { |
||
358 | if (!ContainsKey(key1)) |
||
359 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, V>(); |
||
360 | this[key1][key2, key3, key4, key5, key6] = value; |
||
361 | } |
||
362 | finally |
||
363 | { |
||
364 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
365 | } |
||
22 | office | 366 | } |
367 | } |
||
368 | |||
369 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6) |
||
370 | { |
||
44 | office | 371 | _lock.EnterReadLock(); |
372 | try |
||
373 | { |
||
374 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6); |
||
375 | } |
||
376 | finally |
||
377 | { |
||
378 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
379 | } |
||
22 | office | 380 | } |
381 | } |
||
382 | |||
383 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, V> : |
||
384 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>> |
||
385 | { |
||
44 | office | 386 | private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
39 | office | 387 | |
22 | office | 388 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7] |
389 | { |
||
39 | office | 390 | get |
391 | { |
||
44 | office | 392 | _lock.EnterReadLock(); |
393 | try |
||
394 | { |
||
395 | return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7] : default(V); |
||
396 | } |
||
397 | finally |
||
398 | { |
||
399 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
400 | } |
||
39 | office | 401 | } |
22 | office | 402 | set |
403 | { |
||
44 | office | 404 | _lock.EnterWriteLock(); |
405 | try |
||
406 | { |
||
407 | if (!ContainsKey(key1)) |
||
408 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>(); |
||
409 | this[key1][key2, key3, key4, key5, key6, key7] = value; |
||
410 | } |
||
411 | finally |
||
412 | { |
||
413 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
414 | } |
||
22 | office | 415 | } |
416 | } |
||
417 | |||
418 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7) |
||
419 | { |
||
44 | office | 420 | _lock.EnterReadLock(); |
421 | try |
||
422 | { |
||
423 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7); |
||
424 | } |
||
425 | finally |
||
426 | { |
||
427 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
428 | } |
||
22 | office | 429 | } |
430 | } |
||
431 | |||
432 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, V> : |
||
433 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>> |
||
434 | { |
||
44 | office | 435 | private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
39 | office | 436 | |
22 | office | 437 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8] |
438 | { |
||
39 | office | 439 | get |
440 | { |
||
44 | office | 441 | _lock.EnterReadLock(); |
442 | try |
||
443 | { |
||
444 | return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8] : default(V); |
||
445 | } |
||
446 | finally |
||
447 | { |
||
448 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
449 | } |
||
39 | office | 450 | } |
22 | office | 451 | set |
452 | { |
||
44 | office | 453 | _lock.EnterWriteLock(); |
454 | try |
||
455 | { |
||
456 | if (!ContainsKey(key1)) |
||
457 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>(); |
||
458 | this[key1][key2, key3, key4, key5, key6, key7, key8] = value; |
||
459 | } |
||
460 | finally |
||
461 | { |
||
462 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
463 | } |
||
22 | office | 464 | } |
465 | } |
||
466 | |||
467 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8) |
||
468 | { |
||
44 | office | 469 | _lock.EnterReadLock(); |
470 | try |
||
471 | { |
||
472 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8); |
||
473 | } |
||
474 | finally |
||
475 | { |
||
476 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
477 | } |
||
22 | office | 478 | } |
479 | } |
||
480 | |||
481 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, V> : |
||
482 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>> |
||
483 | { |
||
44 | office | 484 | private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
39 | office | 485 | |
22 | office | 486 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9] |
487 | { |
||
39 | office | 488 | get |
489 | { |
||
44 | office | 490 | _lock.EnterReadLock(); |
491 | try |
||
492 | { |
||
493 | return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9] : default(V); |
||
494 | } |
||
495 | finally |
||
496 | { |
||
497 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
498 | } |
||
39 | office | 499 | } |
22 | office | 500 | set |
501 | { |
||
44 | office | 502 | _lock.EnterWriteLock(); |
503 | try |
||
504 | { |
||
505 | if (!ContainsKey(key1)) |
||
506 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>(); |
||
507 | this[key1][key2, key3, key4, key5, key6, key7, key8, key9] = value; |
||
508 | } |
||
509 | finally |
||
510 | { |
||
511 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
512 | } |
||
22 | office | 513 | } |
514 | } |
||
515 | |||
516 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9) |
||
517 | { |
||
44 | office | 518 | _lock.EnterReadLock(); |
519 | try |
||
520 | { |
||
521 | return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9); |
||
522 | } |
||
523 | finally |
||
524 | { |
||
525 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
526 | } |
||
22 | office | 527 | } |
528 | } |
||
529 | |||
530 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, V> : |
||
531 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>> |
||
532 | { |
||
44 | office | 533 | private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
39 | office | 534 | |
22 | office | 535 | public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10] |
536 | { |
||
537 | get |
||
538 | { |
||
44 | office | 539 | _lock.EnterReadLock(); |
540 | try |
||
541 | { |
||
542 | return ContainsKey(key1) |
||
543 | ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10] |
||
544 | : default(V); |
||
545 | } |
||
546 | finally |
||
547 | { |
||
548 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
549 | } |
||
22 | office | 550 | } |
551 | set |
||
552 | { |
||
44 | office | 553 | _lock.EnterWriteLock(); |
554 | try |
||
555 | { |
||
556 | if (!ContainsKey(key1)) |
||
557 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>(); |
||
558 | this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10] = value; |
||
559 | } |
||
560 | finally |
||
561 | { |
||
562 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
563 | } |
||
22 | office | 564 | } |
565 | } |
||
566 | |||
567 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, |
||
568 | K10 key10) |
||
569 | { |
||
44 | office | 570 | _lock.EnterReadLock(); |
571 | try |
||
572 | { |
||
573 | return ContainsKey(key1) && |
||
574 | this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10); |
||
575 | } |
||
576 | finally |
||
577 | { |
||
578 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
579 | } |
||
22 | office | 580 | } |
581 | } |
||
582 | |||
583 | public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V> : |
||
584 | Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>> |
||
585 | { |
||
44 | office | 586 | private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
39 | office | 587 | |
22 | office | 588 | public V this[ |
589 | K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10, K11 key11] |
||
590 | { |
||
591 | get |
||
592 | { |
||
44 | office | 593 | _lock.EnterReadLock(); |
594 | try |
||
595 | { |
||
596 | return ContainsKey(key1) |
||
597 | ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11] |
||
598 | : default(V); |
||
599 | } |
||
600 | finally |
||
601 | { |
||
602 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
603 | } |
||
22 | office | 604 | } |
605 | set |
||
606 | { |
||
44 | office | 607 | _lock.EnterWriteLock(); |
608 | try |
||
609 | { |
||
610 | if (!ContainsKey(key1)) |
||
611 | this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>(); |
||
612 | this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11] = value; |
||
613 | } |
||
614 | finally |
||
615 | { |
||
616 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
617 | } |
||
22 | office | 618 | } |
619 | } |
||
620 | |||
621 | public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, |
||
622 | K10 key10, K11 key11) |
||
623 | { |
||
44 | office | 624 | _lock.EnterReadLock(); |
625 | try |
||
626 | { |
||
627 | return ContainsKey(key1) && |
||
628 | this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10, key11); |
||
629 | } |
||
630 | finally |
||
631 | { |
||
632 | if (_lock.IsReadLockHeld) _lock.ExitReadLock(); |
||
633 | } |
||
22 | office | 634 | } |
635 | } |
||
27 | office | 636 | } |