Skip to content

Commit

Permalink
Merge pull request RodrigoDLPontes#233 from skapoor68/thing
Browse files Browse the repository at this point in the history
Add indices to pattern matching tables
  • Loading branch information
ljones315 authored Apr 11, 2023
2 parents e9667f0 + ccdcde4 commit 0c7e13b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 10 deletions.
17 changes: 15 additions & 2 deletions src/algo/BoyerMoore.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Algorithm, {
import { act } from '../anim/AnimationMain';

const ARRAY_START_X = 100;
const ARRAY_START_Y = 30;
const ARRAY_START_Y = 60;

const MAX_LENGTH = 22;

Expand Down Expand Up @@ -294,8 +294,21 @@ export default class BoyerMoore extends Algorithm {

for (let i = 0; i < text.length; i++) {
const xpos = i * this.cellSize + ARRAY_START_X;
const ypos = ARRAY_START_Y;
const ypos = ARRAY_START_Y - 25;
this.textRowID[i] = this.nextIndex;
this.cmd(
act.createLabel,
this.nextIndex++,
i,
xpos,
ypos,
);
}

for (let i = 0; i < text.length; i++) {
const xpos = i * this.cellSize + ARRAY_START_X;
const ypos = ARRAY_START_Y;
this.textRowID[i + text.length] = this.nextIndex;
this.cmd(
act.createRectangle,
this.nextIndex,
Expand Down
17 changes: 15 additions & 2 deletions src/algo/BruteForce.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Algorithm, {
import { act } from '../anim/AnimationMain';

const ARRAY_START_X = 100;
const ARRAY_START_Y = 30;
const ARRAY_START_Y = 60;

const MAX_LENGTH = 22;

Expand Down Expand Up @@ -170,8 +170,21 @@ export default class BruteForce extends Algorithm {

for (let i = 0; i < text.length; i++) {
xpos = i * this.cellSize + ARRAY_START_X;
ypos = ARRAY_START_Y;
ypos = ARRAY_START_Y - 25;
this.textRowID[i] = this.nextIndex;
this.cmd(
act.createLabel,
this.nextIndex++,
i,
xpos,
ypos,
);
}

for (let i = 0; i < text.length; i++) {
xpos = i * this.cellSize + ARRAY_START_X;
ypos = ARRAY_START_Y;
this.textRowID[i + text.length] = this.nextIndex;
this.cmd(
act.createRectangle,
this.nextIndex,
Expand Down
18 changes: 16 additions & 2 deletions src/algo/KMP.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Algorithm, {
import { act } from '../anim/AnimationMain';

const ARRAY_START_X = 100;
const ARRAY_START_Y = 30;
const ARRAY_START_Y = 60;

const MAX_LENGTH = 22;

Expand Down Expand Up @@ -215,10 +215,24 @@ export default class KMP extends Algorithm {
}

let xpos, ypos;

for (let i = 0; i < text.length; i++) {
xpos = i * this.cellSize + ARRAY_START_X;
ypos = ARRAY_START_Y;
ypos = ARRAY_START_Y - 25;
this.textRowID[i] = this.nextIndex;
this.cmd(
act.createLabel,
this.nextIndex++,
i,
xpos,
ypos,
);
}

for (let i = 0; i < text.length; i++) {
xpos = i * this.cellSize + ARRAY_START_X;
ypos = ARRAY_START_Y;
this.textRowID[i + text.length] = this.nextIndex;
this.cmd(
act.createRectangle,
this.nextIndex,
Expand Down
21 changes: 17 additions & 4 deletions src/algo/RabinKarp.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Algorithm, {
import { act } from '../anim/AnimationMain';

const ARRAY_START_X = 100;
const ARRAY_START_Y = 30;
const ARRAY_START_Y = 60;

const MAX_LENGTH = 22;

Expand Down Expand Up @@ -223,8 +223,21 @@ export default class RabinKarp extends Algorithm {

for (let i = 0; i < text.length; i++) {
xpos = i * this.cellSize + ARRAY_START_X;
ypos = ARRAY_START_Y;
ypos = ARRAY_START_Y - 25;
this.textRowID[i] = this.nextIndex;
this.cmd(
act.createLabel,
this.nextIndex++,
i,
xpos,
ypos,
);
}

for (let i = 0; i < text.length; i++) {
xpos = i * this.cellSize + ARRAY_START_X;
ypos = ARRAY_START_Y;
this.textRowID[i + text.length] = this.nextIndex;
this.cmd(
act.createRectangle,
this.nextIndex,
Expand Down Expand Up @@ -356,9 +369,9 @@ export default class RabinKarp extends Algorithm {
this.unhighlight(6, 0);
this.highlight(7, 0);
xpos = i * this.cellSize + ARRAY_START_X;
this.cmd(act.createHighlightCircle, iPointerID, '#0000FF', xpos, ARRAY_START_Y);
this.cmd(act.createHighlightCircle, iPointerID, '#0000FF', xpos, ARRAY_START_Y, this.cellSize / 2);
ypos = (row + 1) * this.cellSize + ARRAY_START_Y;
this.cmd(act.createHighlightCircle, jPointerID, '#0000FF', xpos, ypos);
this.cmd(act.createHighlightCircle, jPointerID, '#0000FF', xpos, ypos, this.cellSize / 2);
this.cmd(act.step);
this.unhighlight(7, 0);
this.highlight(8, 0);
Expand Down

0 comments on commit 0c7e13b

Please sign in to comment.