-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tyler Rockwood
committed
Sep 21, 2022
1 parent
9b21b97
commit 3c9a492
Showing
11 changed files
with
2,399 additions
and
34,841 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import contacts from './contacts.json'; | ||
import Trie from '../src/index'; | ||
import {describe, bench, beforeEach} from 'vitest' | ||
|
||
function setup(t: Trie<unknown>) { | ||
contacts.forEach(function(data) { | ||
const email = (data.email || '-').toLowerCase(); | ||
const name = data.name.toLowerCase(); | ||
|
||
const score = data.score; | ||
|
||
t.add({ | ||
key: email, | ||
score: score, | ||
value: data, | ||
distinct: email + name, | ||
}); | ||
|
||
t.add({ | ||
key: name, | ||
score: score, | ||
value: data, | ||
distinct: email + name, | ||
}); | ||
}); | ||
} | ||
|
||
describe('Trie', () => { | ||
bench('populate', () => { | ||
setup(new Trie()); | ||
}); | ||
|
||
|
||
describe('lookupPrefix', () => { | ||
|
||
let t = new Trie<unknown>(); | ||
beforeEach(() => { | ||
t = new Trie(); | ||
setup(t); | ||
}); | ||
|
||
function addBenchmarkTest(prefix: string, limit: number) { | ||
bench(`(${prefix}, ${limit})`, () => { | ||
t.prefixSearch(prefix, { limit, unique: true }); | ||
}); | ||
} | ||
|
||
addBenchmarkTest('t', 5); | ||
addBenchmarkTest('tee', 3); | ||
addBenchmarkTest('tee', 6); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import path from "path"; | ||
import { defineConfig } from "vitest/config"; | ||
import dts from 'vite-plugin-dts' | ||
|
||
const fileName = { | ||
es: `trie.mjs`, | ||
cjs: `trie.cjs`, | ||
}; | ||
|
||
export default defineConfig({ | ||
plugins: [dts()], | ||
base: "./", | ||
build: { | ||
lib: { | ||
entry: path.resolve(__dirname, "src/index.ts"), | ||
name: "trie", | ||
formats: ["es", "cjs"], | ||
fileName: (format) => fileName[format], | ||
}, | ||
rollupOptions: { | ||
output: { | ||
// Since we publish our ./src folder, there's no point | ||
// in bloating sourcemaps with another copy of it. | ||
sourcemapExcludeSources: true, | ||
}, | ||
}, | ||
sourcemap: true, | ||
target: 'es6', | ||
minify: false, | ||
}, | ||
}); |