Exemple #1
0
            private const int FullList  = -1;                // Indicates entries should not be added to end of linked list

            /// <summary>
            /// Construct a new XHashtableState object with the specified capacity.
            /// </summary>
            public XHashtableState(ExtractKeyDelegate extractKey, int capacity)
            {
                Debug.Assert((capacity & (capacity - 1)) == 0, "capacity must be a power of 2");
                Debug.Assert(extractKey != null, "extractKey may not be null");

                // Initialize hash table data structures, with specified maximum capacity
                _buckets = new int[capacity];
                _entries = new Entry[capacity];

                // Save delegate
                _extractKey = extractKey;
            }
 static Dictionary<object, List<object>> MakeKeyDict(IEnumerable<object> list, ExtractKeyDelegate KeyExtractor)
 {
     var result = new Dictionary<object, List<object>>();
     foreach (var item in list)
     {
         var key = KeyExtractor(item);
         if (key == null)
             key = "";
         if (!result.ContainsKey(key))
             result.Add(key, new List<object>());
         result[key].Add(item);
     }
     return result;
 }
Exemple #3
0
 /// <summary>
 /// Construct a new XHashtable with the specified starting capacity.
 /// </summary>
 public XHashtable(ExtractKeyDelegate extractKey, int capacity)
 {
     _state = new XHashtableState(extractKey, capacity);
 }
 public XHashtable(ExtractKeyDelegate <TValue> extractKey, int capacity)
 {
     this.state = new XHashtableState <TValue>(extractKey, capacity);
 }
        /*
        public static List<KeyValuePair<List<object>, List<object>>> ClusteringByNearKey(Dictionary<object, List<object>> exifLocal)
        {
            //Clustering localExif by key
            var exifClusters = new List<KeyValuePair<List<object>, List<object>>>();
            foreach (var pair in exifLocal)
            {
                var newCluster = new KeyValuePair<List<object>, List<object>>(new List<object>(), new List<object>());
                newCluster.Key.Add(pair.Key);
                newCluster.Value.AddRange(pair.Value);

                var matchedCl = new List<KeyValuePair<List<object>, List<object>>>();

                foreach (var cluster in exifClusters)
                {
                    if (IsKeyMatched(pair.Key, cluster.Key))
                    {
                        //Has matching. All to this cluster
                        newCluster.Key.AddRange(cluster.Key);
                        newCluster.Value.AddRange(cluster.Value);
                        matchedCl.Add(cluster);
                    }
                }
                //delete matched
                foreach (var matched in matchedCl)
                    exifClusters.Remove(matched);
                exifClusters.Add(newCluster);
            }
            //End Clustering
            return exifClusters;
        }*/

        private static void MatchFilesWithTheSameNameByType(Dictionary<object, MatchedFiles> result, 
            HashSet<FileDesc> localFiles, HashSet<File> googleFiles, HashSet<PicasaEntry> picasaFiles,
            ExtractKeyDelegate localExtractor, ExtractKeyDelegate googleExtractor, ExtractKeyDelegate2 picasaExtractor)
        { 
            
            //Get different localfile keys
            var exifLocal = MakeKeyDict(localFiles, localExtractor);
            var exifGoogle = MakeKeyDict(googleFiles, googleExtractor);
            var exifPicasa = MakeKeyDict(picasaFiles, exifGoogle, picasaExtractor);
            
            /*
            if (1==1)
            {
                //Get different localfile keys
                var exifLocal1 = MakeKeyDict(localFiles, localExtractor);
                var exifGoogle1 = MakeKeyDict(googleFiles, googleExtractor);
                var exifPicasa1 = MakeKeyDict(picasaFiles, exifGoogle, picasaExtractor);
            }*/

            //Try matching by exif
            foreach (var pair in exifLocal)
            {
                if (pair.Key == null || pair.Key is string && String.IsNullOrWhiteSpace((string)pair.Key))
                    continue;

                //try local Matching
                bool manyLocalKeys;
                var localMatched = GetNearKeys(pair.Key, exifLocal, out manyLocalKeys);
                if (localMatched.Count > 1 || manyLocalKeys)
                    continue; //Bad matching - many file in this basked, or multikeys

                bool manyGoogleKeys;
                var googleMatched = GetNearKeys(pair.Key, exifGoogle, out manyGoogleKeys);
                bool manyPicasaKeys;
                var picasaMatched = GetNearKeys(pair.Key, exifPicasa, out manyPicasaKeys);

                if (googleMatched.Count == 0 && picasaMatched.Count == 0)
                    continue; //Nothing to match

                if (manyGoogleKeys || manyPicasaKeys)
                    continue; //Multimatching? Skip this
                
                if (!result.ContainsKey(pair.Key))
                    result.Add(pair.Key, new MatchedFiles());

                foreach (FileDesc fileDesc in pair.Value)
                    result[pair.Key].localFiles.Add(fileDesc);
                 
                if (googleMatched.Count > 0 && picasaMatched.Count > 0)
                {
                    //Delete if both matched
                    foreach (FileDesc fileDesc in pair.Value)
                        localFiles.Remove(fileDesc);
                }

                if (googleMatched.Count>0)
                {
                    foreach (File file in googleMatched)
                    {
                        result[pair.Key].googleFiles.Add(file);
                        googleFiles.Remove(file);
                    }
                }
                if (picasaMatched.Count>0)
                {
                    foreach (PicasaEntry file in picasaMatched)
                    {
                        result[pair.Key].picasaFiles.Add(file);
                        picasaFiles.Remove(file);
                    }
                }
            }
        }