Skip to content

Commit 83d0cf7

Browse files
committed
String search colors etc
1 parent 56baba0 commit 83d0cf7

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

src/algorithms/controllers/bruteForceStringSearch.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import { QSExp } from '../explanations';
66
import GraphTracerRect from '../../components/DataStructures/Graph/GraphTracerRect';
7+
// XXX need to fix up color selection for graphs then use this:
8+
import {colors} from '../../components/DataStructures/colors';
79

810
export default {
911
explanation: QSExp,
@@ -85,11 +87,11 @@ export default {
8587
} else if (shift_j === findString.length - 1) {
8688
// eslint-disable-next-line no-unused-vars
8789
chunker.add('5', (vis, i, j, n) => {
88-
const ResultStr = `Success: pattern found position ${i}`;
90+
const ResultStr = `Pattern found at position ${i}`;
8991
// method1
90-
vis.graph.addResult(ResultStr, i);
92+
vis.graph.addResult(ResultStr, 3);
9193
// method 2:
92-
// vis.array.addResult(ResultStr,i);
94+
// vis.array.addResult(ResultStr,i); // messed up display
9395
// method 3:
9496
// eslint-disable-next-line max-len
9597
// const array1 = ["The pattern string("+findString+") is placed at postion "+ i +" of Search String ("+searchString+")"];
@@ -106,7 +108,8 @@ export default {
106108
const i = findString.length;
107109
chunker.add('6', (vis, i, n) => {
108110
const ResultStr = 'Pattern not found';
109-
vis.graph.addResult(ResultStr, i);
111+
vis.graph.addResult(ResultStr, 3);
112+
// XXX best remove i,j display
110113
}, [i, nodes]);
111114
},
112115
};

src/algorithms/controllers/horspoolStringSearch.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default {
1313
order: 0,
1414
},
1515
graph: {
16-
instance: new GraphTracerRect('hsp', null, 'Horspool String Search'),
16+
instance: new GraphTracerRect('hsp', null, 'Pattern, String'),
1717
order: 1,
1818
},
1919

@@ -30,6 +30,9 @@ export default {
3030
// searchString and findString are stored in the same array
3131
// to get element in findString, add the length of searchString to the index
3232
chunker.add('1', (vis, n) => {
33+
// XXX adjust size+zoom
34+
vis.array.setSize(0.8);
35+
vis.graph.setZoom(1.5);
3336
vis.graph.addNode(0, searchString[0], 'box');
3437

3538
for (let i = 1; i < searchString.length; i++) {
@@ -46,13 +49,16 @@ export default {
4649
vis.graph.addEdge(j + i, j + i - 1);
4750
}
4851
vis.graph.shift(0, n);
52+
vis.array.set([shiftTable.slice(0, 13), new Array(13)],
53+
[shiftTable.slice(13, 27), new Array(14)],
54+
'horspools');
4955
}, [nodes]);
5056

5157
chunker.add('2', (vis, n) => {
5258
// initialize shift table
53-
vis.array.set([shiftTable.slice(0, 13), new Array(13)],
54-
[shiftTable.slice(13, 27), new Array(14)],
55-
'horspools');
59+
// vis.array.set([shiftTable.slice(0, 13), new Array(13)],
60+
// [shiftTable.slice(13, 27), new Array(14)],
61+
// 'horspools');
5662
}, [nodes]);
5763

5864
// incrementally fill inital shifttable
@@ -158,8 +164,10 @@ export default {
158164
} else if (shift_j === findString.length - 1) {
159165
// select - character matches
160166
chunker.add('10', (vis, i, j, n) => {
161-
const ResultStr = `Success: pattern found position ${i - j}`;
162-
vis.graph.addResult(ResultStr, i);
167+
const ResultStr = `Pattern found at position ${i - j}`;
168+
// vis.graph.addResult(ResultStr, i); // display mangled
169+
vis.graph.addResult(ResultStr, 3); // gnerally fine
170+
// XXX best remove i etc display as it can overlap with ResultStr
163171
}, [shift_i, shift_j, nodes]);
164172
return;
165173
} else {
@@ -199,7 +207,9 @@ export default {
199207
vis.graph.deselect(j, null);
200208
}
201209
const ResultStr = 'Pattern not found';
202-
vis.graph.addResult(ResultStr, i);
210+
// vis.graph.addResult(ResultStr, i); // i not passed in
211+
vis.graph.addResult(ResultStr, 3); // generally fine
212+
// XXX best remove i etc display as it can overlap with ResultStr
203213
}, [shift_pre - 1]);
204214
},
205215
};

src/components/DataStructures/Graph/GraphRendererRect/GraphRenderer.module.scss

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@
4141

4242
&.selected {
4343
.circle {
44-
fill: var(--sky);
45-
stroke: var(--sky);
44+
// fill: var(--sky);
45+
// stroke: var(--sky);
46+
// hacked so match in graph search is leaf, not sky
47+
// XXX should fix up properly
48+
fill: var(--leaf);
49+
stroke: var(--leaf);
4650
}
4751

4852
.rect {
@@ -130,4 +134,4 @@
130134
}
131135
}
132136

133-
}
137+
}

src/components/DataStructures/Graph/GraphRendererRect/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ class GraphRendererRect extends Renderer {
274274
{/* HFS */}
275275
{/* {(id === currentPatEnd.id && currentPatStart.x !== strStart.x && testing.length <=0 && algorithmName === "horspools"? <text style={{ fill: "#2986CC" }} y={lasthighlightj.y * 2} dy=".2em">j</text> : <></>)} */}
276276
{/* {(id === lasthighlightj.id && currentPatStart.x === strStart.x && !highlighting && testing.length >0 && algorithmName === "horspools"? <text style={{ fill: "#2986CC" }} y={lasthighlightj.y * 2} dy=".2em">j</text> : <></>)} */}
277-
{(id === lasthighlightj.id && currentPatStart.x !== strStart.x && testing.length > 0 && algorithmName === 'horspools' ? <text style={{ fill: '#2986CC', textAlign: 'centre' }} y={lasthighlightj.y * 2} dy=".2em">m-j</text> : <></>)}
278-
{(id === lasthighlightj.id && currentPatStart.x !== strStart.x && testing.length > 0 && algorithmName === 'horspools' ? <text style={{ fill: '#2986CC', textAlign: 'centre' }} y={-lasthighlightj.y * 6} dy=".2em">i-j</text> : <></>)}
279-
{(id === lasthighlightj.id && id === currentPatEnd.id && currentPatStart.x === strStart.x && testing.length > 0 && algorithmName === 'horspools' ? <text style={{ fill: '#2986CC', textAlign: 'centre' }} y={lasthighlightj.y * 2} dy=".2em">m-j</text> : <></>)}
280-
{(id === lasthighlightj.id && id === currentPatEnd.id && currentPatStart.x === strStart.x && testing.length > 0 && algorithmName === 'horspools' ? <text style={{ fill: '#2986CC', textAlign: 'centre' }} y={-lasthighlightj.y * 6} dy=".2em">i-j</text> : <></>)}
277+
{(id === lasthighlightj.id && currentPatStart.x !== strStart.x && testing.length > 0 && algorithmName === 'horspools' ? <text style={{ fill: '#2986CC', textAlign: 'centre' }} y={lasthighlightj.y * 2} dy=".2em" dx="-0.7em">m-j</text> : <></>)}
278+
{(id === lasthighlightj.id && currentPatStart.x !== strStart.x && testing.length > 0 && algorithmName === 'horspools' ? <text style={{ fill: '#2986CC', textAlign: 'centre' }} y={-lasthighlightj.y * 6} dy=".2em" dx="-0.2em">i-j</text> : <></>)}
279+
{(id === lasthighlightj.id && id === currentPatEnd.id && currentPatStart.x === strStart.x && testing.length > 0 && algorithmName === 'horspools' ? <text style={{ fill: '#2986CC', textAlign: 'centre' }} y={lasthighlightj.y * 2} dy=".2em" dx="-0.7em">m-j</text> : <></>)}
280+
{(id === lasthighlightj.id && id === currentPatEnd.id && currentPatStart.x === strStart.x && testing.length > 0 && algorithmName === 'horspools' ? <text style={{ fill: '#2986CC', textAlign: 'centre' }} y={-lasthighlightj.y * 6} dy=".2em" dx="-0.2em">i-j</text> : <></>)}
281281
{(id === currentPatEnd.id && currentPatStart.x !== strStart.x && algorithmName === 'horspools' ? <text style={{ fill: '#2986CC' }} y={-lasthighlightj.y * 4} dy=".2em">i</text> : <></>)}
282282
{(id === currentPatEnd.id && currentPatStart.x === strStart.x && highlighting && algorithmName === 'horspools' ? <text style={{ fill: '#2986CC' }} y={-lasthighlightj.y * 4} dy=".2em">i</text> : <></>)}
283283
{(id === currentPatEnd.id && (currentPatStart.x !== strStart.x || currentPatStart.x === strStart.x && highlighting) && algorithmName === 'horspools' ? <text style={{ fill: '#2986CC' }} x={strEnd.x} y={lasthighlightj.y * 8} dy=".2em">j={accumj}</text> : <></>)}

0 commit comments

Comments
 (0)