Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep an in-browser index #1591

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/algorithm/fingerprintIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class FingerprintIndex {
// A set of ignored hashes (either manually added, or through the ignored files, NOT because of maxFileCount)
private readonly ignoredHashes: Set<number>;


/**
* Creates a Fingerprint Index which is able to compare files with each other
* based on their winnowed fingerprints (kgrams of tokens).
Expand Down
51 changes: 33 additions & 18 deletions core/src/algorithm/pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
public readonly rightCovered;
public readonly leftTotal;
public readonly rightTotal;
public readonly longest;
public readonly similarity;
public readonly leftIgnored;
public readonly rightIgnored;

private longestValue: number;

constructor(
public readonly leftEntry: FileEntry,
public readonly rightEntry: FileEntry,
Expand All @@ -50,12 +51,38 @@
large = leftEntry;
}

for (const fingeprint of small.shared) {
if (large.shared.has(fingeprint)) {
this.shared.push(fingeprint);
this.leftCovered = 0;
this.rightCovered = 0;
for (const fingerprint of small.shared) {
if (large.shared.has(fingerprint)) {
this.shared.push(fingerprint);
this.leftCovered += fingerprint.occurrencesOf(this.leftFile).length;
this.rightCovered += fingerprint.occurrencesOf(this.rightFile).length;
}
}

this.longestValue = -1;

this.leftIgnored = leftEntry.ignored.size;
this.rightIgnored = leftEntry.ignored.size;
this.leftTotal = leftEntry.kgrams.length;
this.rightTotal = rightEntry.kgrams.length;
const denominator = this.leftTotal + this.rightTotal - this.leftIgnored - this.rightIgnored;
if (denominator > 0) {
this.similarity = (this.leftCovered + this.rightCovered) / denominator;
} else {
this.similarity = 0;
}
}

get longest(): number {
if (this.longestValue < 0) {
this.calculateLongestFragment();
}
return this.longestValue;
}

public calculateLongestFragment() {

Check failure on line 85 in core/src/algorithm/pair.ts

View workflow job for this annotation

GitHub Actions / Core ❤️ - lint 📏 (22)

Missing return type on function
const left: Kgram[] = [];
const right: Kgram[] = [];
for (const fingerprint of this.shared) {
Expand All @@ -69,20 +96,8 @@
left.sort((a, b) => a.index - b.index);
right.sort((a, b) => a.index - b.index);

this.longest = this.longestCommonSubstring(left, right);

this.leftCovered = left.length;
this.rightCovered = right.length;
this.leftIgnored = leftEntry.ignored.size;
this.rightIgnored = leftEntry.ignored.size;
this.leftTotal = leftEntry.kgrams.length;
this.rightTotal = rightEntry.kgrams.length;
const denominator = this.leftTotal + this.rightTotal - this.leftIgnored - this.rightIgnored;
if (denominator > 0) {
this.similarity = (this.leftCovered + this.rightCovered) / denominator;
} else {
this.similarity = 0;
}
this.longestValue = this.longestCommonSubstring(left, right);
return this.longestValue;
}

private longestCommonSubstring(l: Kgram[], r: Kgram[]): number {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export * from "@dodona/dolos-core";

export * from "./lib/dolos.js";
export * from "./lib/language.js";
export * from "./lib/options.js";
export * from "../../core/src/options.js";
export * from "./lib/report.js";
export * from "./lib/reader.js";
export * from "./lib/tokenizer/charTokenizer.js";
Expand Down
2 changes: 1 addition & 1 deletion lib/src/lib/dolos.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Report } from "./report.js";
import { CustomOptions, Options } from "./options.js";
import { CustomOptions, Options } from "../../../core/src/options.js";
import { Tokenizer } from "./tokenizer/tokenizer.js";
import { Language, LanguagePicker } from "./language.js";
import { readFiles, readPath } from "./reader.js";
Expand Down
2 changes: 1 addition & 1 deletion lib/src/lib/report.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TokenizedFile, FingerprintIndex, Pair, SharedFingerprint, FileEntry } from "@dodona/dolos-core";
import { DolosOptions, Options } from "./options.js";
import { DolosOptions, Options } from "../../../core/src/options.js";
import { Language } from "./language.js";

export interface Metadata extends DolosOptions {
Expand Down
Loading