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

Faster search #53

Merged
merged 6 commits into from
Dec 1, 2023
Merged
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ build/
dist/
docs/.vuepress/.cache
docs/.vuepress/.temp
scripts/api-key.js
scripts/api-key.mjs
3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "client",
"version": "0.1.0",
"scripts": {
"dev": "vite",
"dev": "vite -c vite.config.ts",
"build": "vite build",
"pretest": "rm -rf reports/ && vite build --mode testing",
"update:snapshot": "UPDATE_SNAPSHOTS=true vitest run --mode testing Grid-view",
Expand Down Expand Up @@ -56,6 +56,7 @@
"rimraf": "^4.4.1",
"typescript": "~4.5.5",
"vite": "^4.1.4",
"vite-plugin-glslify": "^2.0.2",
"vitest": "^0.29.5",
"vue-tsc": "^1.2.0"
},
Expand Down
43 changes: 17 additions & 26 deletions client/src/components/Suggestion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
</n-icon>
</template>
</n-button>
<n-button
icon-placement="right"
@click="emit('dir', dir === 'horizontal' ? 'vertical' : 'horizontal')"
>
<n-button icon-placement="right" @click="emit('dir', dir === 'horizontal' ? 'vertical' : 'horizontal')">
<template #icon>
<n-icon>
<ArrowForward v-if="dir === 'horizontal'" />
Expand All @@ -25,24 +22,15 @@
</n-button>
</span>

<n-data-table
v-if="!loading"
:bordered="false"
:single-line="false"
:columns="[
{
title: `${totalResults} ${$t('suggestions.results')}`,
key: 'word',
},
]"
:data="results"
:pagination="{
pageSize: 13,
simple: true,
}"
@mousemove="onMouseEvt($event, false)"
@click="onMouseEvt($event, true)"
/>
<n-data-table v-if="!loading" :bordered="false" :single-line="false" :columns="[
{
title: `${totalResults} ${$t('suggestions.results')}`,
key: 'word',
},
]" :data="results" :pagination="{
pageSize: 13,
simple: true,
}" @mousemove="onMouseEvt($event, false)" @click="onMouseEvt($event, true)" />
<n-button class="loading" v-else :loading="true"></n-button>
</div>
</template>
Expand All @@ -63,7 +51,7 @@ import { Method, Ordering } from "../types";
/**
* Component to display words suggestions
*/
const results = ref<{word:string}[]>([]);
const results = ref<{ word: string; }[]>([]);
const totalResults = ref(0);
const suggestion = ref(null);
const version = ref(0);
Expand Down Expand Up @@ -143,7 +131,7 @@ function getSuggestions(
words.sort(() => Math.random() - 0.5);
}
totalResults.value = words.length;
results.value = words.map((word) => ({word}));
results.value = words.map((word) => ({ word }));
}

function orderingText() {
Expand Down Expand Up @@ -174,19 +162,22 @@ function onMouseEvt(evt: MouseEvent, click = false) {
</script>

<style>
.n-data-table-tr > td {
.n-data-table-tr>td {
cursor: pointer;
}

.suggestion {
display: flex;
flex-direction: column;
height: 100%;
width: 100%;
}
.suggestion > .loading {

.suggestion>.loading {
flex: 1;
padding: 150px 0;
}

.buttons {
display: flex;
flex-direction: row;
Expand Down
8 changes: 8 additions & 0 deletions client/src/search-worker/dico.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { StringBS } from "./string-bs";

export const ACode = "A".charCodeAt(0);
export const ZCode = "Z".charCodeAt(0);


/**
* Dico is a sigleton class that contains the dictionnary
Expand Down Expand Up @@ -62,6 +64,12 @@ export class Dico {
this.stringBS = new StringBS(this.words, this.sorted);
}

findLengthInterval(length: number) {
const start = this.stringBS.byLengthStart(length, 0, this.words.length - 1);
const end = this.stringBS.byLengthEnd(length, start, this.words.length - 1);
return [start, end];
}

findInterval(query: string) {
const startL = this.stringBS.byLengthStart(
query.length,
Expand Down
61 changes: 61 additions & 0 deletions client/src/search-worker/gpu-worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {bindUniforms, createAttributeLocs, createProgram, createUniforms} from './webgl-utils';
import vert from './shaders/vertex.vert';
import frag from './shaders/fragment.frag';
const w = 256;
export class WebGLWorker{
private _canvas: HTMLCanvasElement;
private _gl: WebGL2RenderingContext;
private _program: WebGLProgram;
private _attributes: Record<string, any>;
private _uniforms: Record<string, any>;

constructor(canvas ? : HTMLCanvasElement){
this._canvas = canvas || document.createElement("canvas");
this._canvas.width = w;
this._canvas.height = w;
this._gl = this._canvas.getContext("webgl2") as WebGL2RenderingContext;
this._program = createProgram(this._gl, [vert, frag]);
const pixels = new Float32Array(w * w * 4);
// const framebuffers = [outputTexture, bodyTexture].map(({ texture }) =>
// createFrameBuffer(gl, texture)
// );
// functions computing the simulation and drawing the result on the current FBO
this._attributes = createAttributeLocs(this._gl, this._program, {
position: new Float32Array([-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1])
});

this._uniforms = createUniforms(this._gl, this._program, {

});
this._gl.viewport(0, 0, w, w);

}


frame(){
const {_gl: gl, _program: program, _uniforms: uniforms, _attributes: attributes } = this;
// gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffers[i].handle);
gl.viewport(0, 0, w, w);
// gl.viewport(0, 0, bodyTexture.width, bodyTexture.height);
gl.bindBuffer(gl.ARRAY_BUFFER, attributes.position.buffer);
gl.enableVertexAttribArray(attributes.position.location);
gl.vertexAttribPointer(
attributes.position.location,
2,
gl.FLOAT,
false,
0,
0
);
gl.useProgram(program);
bindUniforms(gl, uniforms, { color: [1, 0, 0, 1] });
gl.drawArrays(gl.TRIANGLES, 0, 6);
}







}
Loading