commit 89472316a52c0289eca9b84c0061bdc33e4828bb
Author: Panagiotis Kanavos <pkanavos@gmail.com>
Date:   Wed Feb 29 15:18:26 2012 +0200

    Simplified snapshot comparisons usind dictionaries

diff --git a/trunk/Pithos.Core/Agents/SnapshotDifferencer.cs b/trunk/Pithos.Core/Agents/SnapshotDifferencer.cs
index 7bd83b9..2725e72 100644
--- a/trunk/Pithos.Core/Agents/SnapshotDifferencer.cs
+++ b/trunk/Pithos.Core/Agents/SnapshotDifferencer.cs
@@ -43,7 +43,6 @@ using System.Collections.Concurrent;
 using System.Diagnostics.Contracts;
 using Pithos.Interfaces;
 using Pithos.Network;
-using System;
 using System.Collections.Generic;
 using System.Linq;
 
@@ -81,7 +80,7 @@ namespace Pithos.Core.Agents
             /// Common objects, lazily evalueated. 
             /// The common objects are used to calculate both the Changed and Unchanged objects
             /// </summary>
-            public readonly Lazy<IEnumerable<ObjectInfo>> Common;
+            public readonly IEnumerable<ObjectInfo> Common;
 
             private readonly static ObjectInfo[] Empty = new ObjectInfo[0];
 
@@ -104,11 +103,15 @@ namespace Pithos.Core.Agents
                 CurrentDict = Current.ToDictionary(info => info.UUID);
                 PreviousDict = Previous.ToDictionary(info => info.UUID);
 
-                Common=new Lazy<IEnumerable<ObjectInfo>>(() =>
-                    Current.Join(Previous,
-                                outKey => outKey.UUID,
-                                inKey => inKey.UUID,
-                                (outer, inner) =>outer.SetPrevious(inner)));            
+                //Attach the previous version to the current listings
+                foreach (var info in Current)
+                {
+                    ObjectInfo prev;
+                    if (PreviousDict.TryGetValue(info.UUID, out prev))
+                        info.SetPrevious(prev);
+                }
+
+                Common=Current.Where(c=>c.Previous !=null);
             }
         }
 
@@ -116,12 +119,6 @@ namespace Pithos.Core.Agents
         private State _state;
 
         /// <summary>
-        /// The comparer used to identify common objects.
-        /// Objects are considered common when they have the same Account, Container and Name
-        /// </summary>
-        private readonly ObjectInfoComparer _comparer = new ObjectInfoComparer();
-
-        /// <summary>
         /// Default constructor. Initializes the Current and Previous listings to empty lists
         /// </summary>
         public SnapshotDifferencer()
@@ -156,52 +153,61 @@ namespace Pithos.Core.Agents
         
         /// <summary>
         /// Deleted objects are those that existed in the Previous listing
-        /// but are not found in the Current listing, and their UUIDs do not
-        /// appear in the Current listing (ie they were not renamed/moved)
+        /// but are not found in the Current listing
         /// </summary>
         public IEnumerable<ObjectInfo> Deleted
         {
-            get { return _state.Previous.Except(_state.Current,_comparer)
+            get { return _state.Previous
                 .Where(info=>!_state.CurrentDict.ContainsKey(info.UUID)); }
         }
 
         /// <summary>
         /// Created objects are those that exist in the Current listing
-        /// but are not found in the Previous listing, and their UUIDs do not
-        /// appear in the Previous listing (ie they were not renamed/moved)
+        /// but are not found in the Previous listing 
         /// </summary>
         public IEnumerable<ObjectInfo> Created
         {
-            get { return _state.Current.Except(_state.Previous,_comparer)
+            get { return _state.Current
                 .Where(info=>!_state.PreviousDict.ContainsKey(info.UUID)); }
         }
                 
         public IEnumerable<ObjectInfo> Common
         {
-            get { return _state.Common.Value; }
+            get { return _state.Common; }
         }
 
         public IEnumerable<ObjectInfo> Changed
         {
             get
             {
-                return Common.Where(i => i.PreviousHash != i.Hash && (i.Previous == null ||  i.Uri == i.Previous.Uri));}
+                return Common.Where(info => 
+                    //The hash is different
+                    info.PreviousHash != info.Hash 
+                    //And the Uri is unchanged or there is no previous version
+                    && (info.Previous == null ||  info.Uri == info.Previous.Uri));
+            }
         }
+
+        /// <summary>
+        /// Unchanged objects have the same current and previous hash
+        /// </summary>
         public IEnumerable<ObjectInfo> Unchanged
         {
             get{ return Common.Where(i => i.PreviousHash == i.Hash);}
         }
 
+        /// <summary>
+        /// Moved objects have a previous version with a different name
+        /// </summary>
         public IEnumerable<ObjectInfo>  Moved
         {
             get
-            {
-                                
-                return _state.Current.Join(_state.Previous,
-                                    outer => outer.UUID,
-                                    inner => inner.UUID,
-                                    (outer, inner) => (outer.Name == inner.Name ? null : outer.SetPrevious(inner)))
-                    .Where(t => t != null);                
+            {                                
+                return Common.Where(info=>
+                    //A previous version exists
+                    info.Previous!= null 
+                    //and the Uri is different
+                    && info.Uri!=info.Previous.Uri);                    
             }
         }
     }
