Parallelized hash calculations
[pithos-ms-client] / trunk / Pithos.Network / TreeHash.cs
index 6d80476..e35b399 100644 (file)
@@ -43,18 +43,14 @@ namespace Pithos.Network
 
         public TreeHash(string algorithm)
         {
-            BlockHash = algorithm;
-            _topHash = new Lazy<byte[]>(() => Signature.CalculateTopHash(_hashes, BlockHash));
-
-            _topHash2 = new Lazy<string>(() =>
-                                             {
-                                                 var hashString = _hashes.Select(hash => hash.ToHashString())
-                                                     .Aggregate(new StringBuilder(),
-                                                                (builder, hash) => builder.Append(hash),
-                                                                builder => builder.ToString());
-
-                                                 return Signature.CalculateTopHash(hashString, BlockHash);
-                                             });
+            BlockHash = algorithm;            
+            _topHash = new Lazy<byte[]>(() =>
+            {
+                //
+                //Cast the hashes to an IList or create a new list out of the hashes
+                var hashMap = (_hashes as IList<byte[]>)??_hashes.ToList();
+                return Signature.CalculateTopHash(hashMap, BlockHash);
+            });
         }
 
         //Returns a Json representation of the hashes, as required by Pithos