Skip to content

Commit

Permalink
Merge pull request RodrigoDLPontes#237 from ljones315/bm-fix
Browse files Browse the repository at this point in the history
fix galil toggle bug
  • Loading branch information
ljones315 authored Apr 12, 2023
2 parents 3e2e19e + c861fb9 commit 9849445
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/algo/BoyerMoore.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ const BM_CODE_Y = 205;

const GALIL_CODE_Y = 275;

let galilRuleEnabled = false;

export default class BoyerMoore extends Algorithm {
constructor(am, w, h) {
super(am, w, h);
Expand Down Expand Up @@ -126,6 +124,7 @@ export default class BoyerMoore extends Algorithm {
this.lastTableCharacterID = [];
this.lastTableValueID = [];
this.codeID = [];
this.galilRuleEnabled = false;
// this.failureTableLabelID = this.nextIndex++;
// this.failureTableCharacterID = [];
// this.failureTableValueID = [];
Expand Down Expand Up @@ -267,7 +266,7 @@ export default class BoyerMoore extends Algorithm {
}

toggleGalilRule() {
galilRuleEnabled = !galilRuleEnabled;
this.galilRuleEnabled = !this.galilRuleEnabled;
//this.implementAction(this.clear.bind(this));
}

Expand Down Expand Up @@ -342,7 +341,7 @@ export default class BoyerMoore extends Algorithm {

const lastTable = this.buildLastTable(text.length, pattern);
this.removeCode(this.codeID);
if (galilRuleEnabled) {
if (this.galilRuleEnabled) {
this.buildFailureTable(text.length, pattern);
this.codeID = this.addCodeToCanvasBase(
this.GalilCode,
Expand Down Expand Up @@ -380,10 +379,10 @@ export default class BoyerMoore extends Algorithm {
let j = pattern.length - 1;
let row = 0;
let l = 0;
let gr = galilRuleEnabled ? 1 : 0;
let gr = this.galilRuleEnabled ? 1 : 0;
this.highlight(gr + 4, 0);
while (i <= text.length - pattern.length) {
gr = galilRuleEnabled ? 1 : 0;
gr = this.galilRuleEnabled ? 1 : 0;
for (let k = i; k < i + pattern.length; k++) {
this.cmd(
act.setText,
Expand Down Expand Up @@ -426,7 +425,7 @@ export default class BoyerMoore extends Algorithm {
if (j < l) {
this.highlight(gr + 9, 0);
this.highlight(gr + 10, 0);
if (galilRuleEnabled) {
if (this.galilRuleEnabled) {
this.highlight(gr + 11, 0);
i += this.period;
l = pattern.length - this.period;
Expand All @@ -446,7 +445,7 @@ export default class BoyerMoore extends Algorithm {
if (l !== 0) {
l = 0;
}
gr = galilRuleEnabled ? 2 : 0;
gr = this.galilRuleEnabled ? 2 : 0;
this.highlight(11 + gr, 0);
this.cmd(act.setBackgroundColor, this.comparisonMatrixID[row][i + j], '#E74C3C');
let shift;
Expand Down Expand Up @@ -486,7 +485,7 @@ export default class BoyerMoore extends Algorithm {
this.cmd(act.move, jPointerID, xpos, ypos);
}
}
gr = galilRuleEnabled ? 1 : 0;
gr = this.galilRuleEnabled ? 1 : 0;
this.unhighlight(gr + 4, 0);
this.cmd(act.step);

Expand All @@ -496,7 +495,7 @@ export default class BoyerMoore extends Algorithm {
}

getMaxRows(text, pattern) {
if (galilRuleEnabled) {
if (this.galilRuleEnabled) {
const failureTable = [];
failureTable[0] = 0;
let i = 0;
Expand Down Expand Up @@ -530,7 +529,7 @@ export default class BoyerMoore extends Algorithm {
j--;
}
if (j < l) {
if (galilRuleEnabled) {
if (this.galilRuleEnabled) {
i += this.period;
l = pattern.length - this.period;
} else {
Expand Down

0 comments on commit 9849445

Please sign in to comment.