wasSharp – Diff between revs 39 and 45

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 39 Rev 45
Line 5... Line 5...
5 /////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////
Line 6... Line 6...
6   6  
7 using System; 7 using System;
8 using System.Collections.Generic; 8 using System.Collections.Generic;
-   9 using System.Linq;
9 using System.Linq; 10 using System.Threading;
Line 10... Line 11...
10 using wasSharp.Collections.Specialized; 11 using wasSharp.Collections.Specialized;
11   12  
12 namespace wasSharp.Collections.Utilities 13 namespace wasSharp.Collections.Utilities
Line 31... Line 32...
31 .OrderBy(kvp => kvp.Key) 32 .OrderBy(kvp => kvp.Key)
32 .SequenceEqual((dictionary ?? new Dictionary<TKey, TValue>()) 33 .SequenceEqual((dictionary ?? new Dictionary<TKey, TValue>())
33 .OrderBy(kvp => kvp.Key)); 34 .OrderBy(kvp => kvp.Key));
34 } 35 }
Line 35... Line -...
35   -  
36 public static void UnionWith<TKey, TValue>(this IDictionary<TKey, TValue> target, -  
37 IDictionary<TKey, TValue> source) -  
38 { -  
39 var LockObject = new object(); -  
40 source.AsParallel().ForAll(o => -  
41 { -  
42 bool hasElement; -  
43 lock (LockObject) -  
44 { -  
45 hasElement = target.ContainsKey(o.Key); -  
46 } -  
47 switch (hasElement) -  
48 { -  
49 case true: -  
50 lock (LockObject) -  
51 { -  
52 target[o.Key] = o.Value; -  
53 } -  
54 break; -  
55   -  
56 default: -  
57 lock (LockObject) -  
58 { -  
59 target.Add(o.Key, o.Value); -  
60 } -  
61 break; -  
62 } -  
63 }); -  
64 } -  
65   36  
66 public static void AddOrReplace<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value) 37 public static void AddOrReplace<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
67 { 38 {
68 switch (dictionary.ContainsKey(key)) 39 switch (dictionary.ContainsKey(key))
69 { 40 {