Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public async cloneDetector(files: File[]): Promise<Report> {
- const tokenizedFiles = files.map(f => this.tokenizer.tokenizeFile(f));
- const report = new Report(this.options);
- for (const file of tokenizedFiles) {
- let kgram = 0;
- for await (
- const { hash, start, stop }
- of hashFilter.fingerprints(file.Ast)
- ) {
- // add kgram to file
- file.kgrams.push(new Range(start, stop));
- const location = Region.merge(
- file.mapping[start],
- file.mapping[stop]
- );
- const part: Occurrence = {
- file,
- side: { index: kgram, start, stop, data, location }
- };
- // look if the index already contains the given hashing
- const matches = this.index.get(hash);
- if (matches) {
- report.addOccurrences(hash, part, ...matches);
- matches.push(part);
- } else {
- this.index.set(hash, [part]);
- }
- kgram += 1;
- }
- }
- report.finish();
- return report;
- }
Advertisement
Add Comment
Please, Sign In to add comment