예제 #1
0
        // ReSharper restore ReturnTypeCanBeEnumerable.Local
        // ReSharper disable ReturnTypeCanBeEnumerable.Local
        private List<HashSignature> GetSignatures(IEnumerable<bool[]> fingerprints, Track track, int hashTables, int hashKeys)
        {
            List<HashSignature> signatures = new List<HashSignature>();
            foreach (bool[] fingerprint in fingerprints)
            {
                int[] signature = hasher.ComputeMinHashSignature(fingerprint); /*Compute min-hash signature out of signature*/
                Dictionary<int, long> buckets = hasher.GroupMinHashToLSHBuckets(signature, hashTables, hashKeys); /*Group Min-Hash signature into LSH buckets*/
                int[] hashSignature = new int[buckets.Count];
                foreach (KeyValuePair<int, long> bucket in buckets)
                {
                    hashSignature[bucket.Key] = (int)bucket.Value;
                }

                HashSignature hash = new HashSignature(track, hashSignature); /*associate track to hash-signature*/
                signatures.Add(hash);
            }
            return signatures; /*Return the signatures*/
        }
예제 #2
0
 /// <summary>
 ///   Insert hash into the RAM Storage. Be careful, there should be a Track object already inserted into the Storage.
 /// </summary>
 /// <param name = "hash">Hash signature that corresponds to a specific track</param>
 /// <param name = "type">Type of the hash to be inserted</param>
 public void InsertHash(HashSignature hash, HashType type)
 {
     switch (type)
     {
         case HashType.Query:
             _fingerprints[hash.Track].Query.Add(hash);
             break;
         case HashType.Creational:
         {
             _fingerprints[hash.Track].Creational.Add(hash);
             int[] signature = hash.Signature;
             lock (_hashTables.SyncRoot) /*Lock insertion in the hash-tables as it keys are verified*/
             {
                 for (int i = 0; i < _numberOfHashTables; i++)
                 {
                     if (!_hashTables[i].ContainsKey(signature[i]))
                         _hashTables[i][signature[i]] = new HashSet<Track>();
                     _hashTables[i][signature[i]].Add(hash.Track);
                 }
             }
         }
             break;
     }
 }