Ejemplo n.º 1
0
        // Get hash representing pair of files
        private string GetHash(string fileName1, string fileName2, CloneSearchParameters searchParameters)
        {
            byte[] hash1;
            byte[] hash2;
            byte[] hash;

            using (MD5 md5 = MD5.Create())
            {
                // Get hash of file 1 contents
                using (FileStream fs = File.OpenRead(fileName1))
                {
                    hash1 = md5.ComputeHash(fs);
                }
                // Get hash of file 2 contents
                using (FileStream fs = File.OpenRead(fileName2))
                {
                    hash2 = md5.ComputeHash(fs);
                }
                // Combine hashes and min clone length data into single hash
                byte[] comb = hash1.Concat(hash2)
                              .Concat(BitConverter.GetBytes(searchParameters.MinLines))
                              .Concat(BitConverter.GetBytes(searchParameters.MinTokens))
                              .Concat(BitConverter.GetBytes(searchParameters.MinPercentMatch))
                              .ToArray();
                hash = md5.ComputeHash(comb);
            }

            // Convert hash to hex
            return(string.Concat(hash.Select(b => b.ToString("X2"))));
        }
Ejemplo n.º 2
0
        public CloneFinder(TokenList tokenList1, TokenList tokenList2, CloneSearchParameters searchParameters)
        {
            this.FileName1  = tokenList1.FileName;
            this.TokenList1 = tokenList1.Tokens;

            this.FileName2  = tokenList2.FileName;
            this.TokenList2 = tokenList2.Tokens;

            this.MinLines       = searchParameters.MinLines;
            this.MinTokens      = searchParameters.MinTokens;
            this.MatchThreshold = searchParameters.MinPercentMatch / 100;
        }
Ejemplo n.º 3
0
        // Check table for entry matching given filenames
        public List <Clone> TryGet(string fileName1, string fileName2, CloneSearchParameters searchParameters)
        {
            string key = GetHash(fileName1, fileName2, searchParameters);

            if (table.ContainsKey(key))
            {
                return(table[key]);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
 // Add entry to table
 public void AddEntry(string fileName1, string fileName2, CloneSearchParameters searchParameters, List <Clone> clones)
 {
     table.Add(GetHash(fileName1, fileName2, searchParameters), clones);
 }