irapilguy

Untitled

Dec 15th, 2021
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public async cloneDetector(files: File[]): Promise<Report> {
  2.     const tokenizedFiles = files.map(f => this.tokenizer.tokenizeFile(f));
  3.     const report = new Report(this.options);
  4.     for (const file of tokenizedFiles) {
  5.       let kgram = 0;
  6.       for await (
  7.         const { hash, start, stop  }
  8.         of hashFilter.fingerprints(file.Ast)
  9.       ) {
  10.  
  11.         // add kgram to file
  12.         file.kgrams.push(new Range(start, stop));
  13.  
  14.         const location = Region.merge(
  15.           file.mapping[start],
  16.           file.mapping[stop]
  17.         );
  18.  
  19.         const part: Occurrence = {
  20.           file,
  21.           side: { index: kgram, start, stop, data, location }
  22.         };
  23.  
  24.         // look if the index already contains the given hashing
  25.         const matches = this.index.get(hash);
  26.  
  27.         if (matches) {
  28.           report.addOccurrences(hash, part, ...matches);
  29.           matches.push(part);
  30.         } else {
  31.           this.index.set(hash, [part]);
  32.         }
  33.         kgram += 1;
  34.       }
  35.     }
  36.     report.finish();
  37.     return report;
  38.   }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment