Skip to content

Commit e824661

Browse files
refactor: Removed FastTrieBlob part 1 (#8266)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent c756150 commit e824661

28 files changed

+162
-776
lines changed

packages/cspell-trie-lib/api/api.d.ts

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cspell-trie-lib/perf/charIndex.perf.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,19 @@ import { suite } from 'perf-insight';
22

33
import { CharIndex } from '../src/lib/TrieBlob/CharIndex.ts';
44
import { encodeTextToUtf8 } from '../src/lib/TrieBlob/Utf8.ts';
5-
import { readFastTrieBlobFromConfig, readTrieFromConfig } from '../src/test/dictionaries.test.helper.ts';
5+
import { readTrieBlobFromConfig, readTrieFromConfig } from '../src/test/dictionaries.test.helper.ts';
66

77
// const measureTimeout = 100;
88

99
const getTrie = memorize(_getTrie);
10-
const getFastTrieBlob = memorize(_getFastTrieBlob);
1110
const getWords = memorize(async () => [...(await getTrie()).words()]);
1211

1312
suite('encode to sequence', async (test) => {
1413
const words = await getWords();
1514
const msgSuffix = ' - ' + words.length + ' words';
16-
const fastTrieBlob = await getFastTrieBlob();
1715
const charIndex = CharIndex.fromIterable(words);
1816
const encoder = new TextEncoder();
1917

20-
test('fastTrieBlob.wordToNodeCharIndexSequence' + msgSuffix, () => {
21-
for (const word of words) {
22-
fastTrieBlob.wordToUtf8Seq(word);
23-
}
24-
});
25-
2618
test('charIndex.wordToCharIndexSequence' + msgSuffix, () => {
2719
for (const word of words) {
2820
charIndex.wordToUtf8Seq(word);
@@ -116,7 +108,7 @@ function _getTrie() {
116108
}
117109

118110
function _getFastTrieBlob() {
119-
return readFastTrieBlobFromConfig('@cspell/dict-en_us/cspell-ext.json');
111+
return readTrieBlobFromConfig('@cspell/dict-en_us/cspell-ext.json');
120112
}
121113

122114
function memorize<T, P extends []>(fn: (...p: P) => T): (...p: P) => T {

packages/cspell-trie-lib/perf/create.perf.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { suite } from 'perf-insight';
33
import { buildITrieFromWords } from '../src/lib/index.ts';
44
import { createTrieBlobFromTrieRoot } from '../src/lib/TrieBlob/createTrieBlob.ts';
55
import { FastTrieBlob } from '../src/lib/TrieBlob/FastTrieBlob.ts';
6-
import { FastTrieBlobBuilder } from '../src/lib/TrieBlob/FastTrieBlobBuilder.ts';
6+
import { TrieBlobBuilder } from '../src/lib/TrieBlob/TrieBlobBuilder.ts';
77
import { createTrieRootFromList } from '../src/lib/TrieNode/trie-util.ts';
88
import { readTrieFromConfig } from '../src/test/dictionaries.test.helper.ts';
99

@@ -15,16 +15,15 @@ const getWords = memorize(async () => [...(await getTrie()).words()]);
1515
suite('trie create', async (test) => {
1616
const words = await getWords();
1717
const trie = createTrieRootFromList(words);
18-
const fastTrie = FastTrieBlobBuilder.fromWordList(words);
18+
const trieBlob = TrieBlobBuilder.fromWordList(words);
1919
console.error('Info: %o', {
2020
wordsSize: words.length,
21-
fastTrieSize: fastTrie.size,
22-
fastTrieSmallSize: FastTrieBlobBuilder.fromWordList(words.slice(-1000)).size,
21+
TrieBlobSize: trieBlob.size,
22+
fastTrieSmallSize: TrieBlobBuilder.fromWordList(words.slice(-1000)).size,
2323
});
24-
const trieBlob = fastTrie.toTrieBlob();
2524

2625
test('FastTrieBlobBuilder.insert.build', () => {
27-
const builder = new FastTrieBlobBuilder();
26+
const builder = new TrieBlobBuilder();
2827
builder.insert(words);
2928
builder.build();
3029
});
@@ -34,11 +33,11 @@ suite('trie create', async (test) => {
3433
});
3534

3635
test('FastTrieBlobBuilder.fromWordList', () => {
37-
FastTrieBlobBuilder.fromWordList(words);
36+
TrieBlobBuilder.fromWordList(words);
3837
});
3938

4039
test('FastTrieBlobBuilder.fromTrieRoot', () => {
41-
FastTrieBlobBuilder.fromTrieRoot(trie);
40+
TrieBlobBuilder.fromTrieRoot(trie);
4241
});
4342

4443
test('FastTrieBlob.fromTrie', () => {
@@ -52,10 +51,6 @@ suite('trie create', async (test) => {
5251
test('TrieBlob createTrieBlobFromTrieRoot', () => {
5352
createTrieBlobFromTrieRoot(trie);
5453
});
55-
56-
test('TrieBlob fastTrie.toTrieBlob', () => {
57-
fastTrie.toTrieBlob();
58-
});
5954
});
6055

6156
function _getTrie() {

packages/cspell-trie-lib/perf/has.perf.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ import assert from 'node:assert';
33
import { suite } from 'perf-insight';
44

55
import { ITrieImpl } from '../src/lib/ITrie.ts';
6-
import { readFastTrieBlobFromConfig, readTrieFromConfig } from '../src/test/dictionaries.test.helper.ts';
6+
import { readTrieBlobFromConfig, readTrieFromConfig } from '../src/test/dictionaries.test.helper.ts';
77

88
// const measureTimeout = 100;
99

1010
const getTrie = memorize(_getTrie);
11-
const getFastTrieBlob = memorize(_getFastTrieBlob);
11+
const getTrieBlob = memorize(_getTrieBlob);
1212
const getWords = memorize(async () => [...(await getTrie()).words()]);
1313

1414
suite('trie has', async (test) => {
1515
const trie = await getTrie();
1616
const words = await getWords();
17-
const fastTrieBlob = await getFastTrieBlob();
18-
const trieBlob = fastTrieBlob.toTrieBlob();
19-
const iTrieFast = new ITrieImpl(fastTrieBlob);
17+
const trieBlob = await getTrieBlob();
2018
const iTrieBlob = new ITrieImpl(trieBlob);
2119
const setOfWords = new Set(words);
2220
console.log(`Number of words: ${words.length}`);
@@ -29,18 +27,10 @@ suite('trie has', async (test) => {
2927
trieHasWords(trie, words);
3028
});
3129

32-
test('fastTrieBlob has words', () => {
33-
trieHasWords(fastTrieBlob, words);
34-
});
35-
3630
test('trieBlob has words', () => {
3731
trieHasWords(trieBlob, words);
3832
});
3933

40-
test('iTrieFast has words', () => {
41-
trieHasWords(iTrieFast, words);
42-
});
43-
4434
test('iTrieBlob has words', () => {
4535
trieHasWords(iTrieBlob, words);
4636
});
@@ -50,8 +40,8 @@ function _getTrie() {
5040
return readTrieFromConfig('@cspell/dict-en_us/cspell-ext.json');
5141
}
5242

53-
function _getFastTrieBlob() {
54-
return readFastTrieBlobFromConfig('@cspell/dict-en_us/cspell-ext.json');
43+
function _getTrieBlob() {
44+
return readTrieBlobFromConfig('@cspell/dict-en_us/cspell-ext.json');
5545
}
5646

5747
function trieHasWords(trie: { has: (word: string) => boolean }, words: string[]): boolean {

packages/cspell-trie-lib/perf/perfSuite.perf.ts

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import assert from 'node:assert';
33
import { suite } from 'perf-insight';
44

55
import type { Trie } from '../src/lib/index.ts';
6-
import type { FastTrieBlob } from '../src/lib/TrieBlob/FastTrieBlob.ts';
7-
import { FastTrieBlobBuilder } from '../src/lib/TrieBlob/FastTrieBlobBuilder.ts';
86
import { TrieBlob } from '../src/lib/TrieBlob/TrieBlob.ts';
7+
import { TrieBlobBuilder } from '../src/lib/TrieBlob/TrieBlobBuilder.ts';
98
import type { TrieData } from '../src/lib/TrieData.ts';
109
import { TrieNodeTrie } from '../src/lib/TrieNode/TrieNodeTrie.ts';
1110
import { walkerWordsITrie } from '../src/lib/walker/walker.ts';
12-
import { readFastTrieBlobFromConfig, readTrieFromConfig } from '../src/test/dictionaries.test.helper.ts';
11+
import { readTrieBlobFromConfig, readTrieFromConfig } from '../src/test/dictionaries.test.helper.ts';
1312

1413
// const weightMapEn = getEnglishWeightMap();
1514

@@ -29,16 +28,16 @@ class DI {
2928
}
3029

3130
private _trieFast = lazy(() => {
32-
return getFastTrieBlob();
31+
return getTrieBlob();
3332
});
3433

35-
get trieFastNL() {
34+
get trieBlobNL() {
3635
return this._trieFastNL();
3736
}
3837

39-
private _trieFastNL = lazy(() => getFastTrieBlobNL());
38+
private _trieFastNL = lazy(() => getTrieBlobNL());
4039

41-
get trieFast() {
40+
get trieBlob() {
4241
return this._trieFast();
4342
}
4443

@@ -56,8 +55,8 @@ class DI {
5655
interface TestDependencies {
5756
trie: Trie;
5857
words: string[];
59-
trieFast: FastTrieBlob;
60-
trieFastNL: FastTrieBlob;
58+
trieBlob: TrieBlob;
59+
trieBlobNL: TrieBlob;
6160
}
6261

6362
type DependenciesKeys = keyof TestDependencies;
@@ -67,22 +66,12 @@ const di = new DI();
6766
// const measureTimeout = 100;
6867

6968
suite('blob.FastTrieBlobBuilder', async (test) => {
70-
const { trie, words, trieFast } = await prepareDI(['trie', 'words', 'trieFast']);
71-
const trieBlob = FastTrieBlobBuilder.fromTrieRoot(trie.root).toTrieBlob();
72-
const trieBlobFromFast = trieFast.toTrieBlob();
73-
assert(!words.some((w) => !trieFast.has(w)), 'Expect all words to be found in trieFast.');
74-
assert(!words.some((w) => !trieBlobFromFast.has(w)), 'Expect all words to be found in trieBlobFromFast.');
69+
const { trie, words, trieBlob } = await prepareDI(['trie', 'words', 'trieBlob']);
70+
assert(!words.some((w) => !trieBlob.has(w)), 'Expect all words to be found in trieFast.');
7571
assert(!words.some((w) => !trie.has(w)), 'Expect all words to be found in trie.');
7672
assert(!words.some((w) => !trieBlob.has(w)), 'Expect all words to be found in trieBlob. p1');
7773

78-
test('FastTrieBlobBuilder.fromTrieRoot', () => FastTrieBlobBuilder.fromTrieRoot(trie.root));
79-
80-
test.prepare(() => FastTrieBlobBuilder.fromTrieRoot(trie.root)).test(
81-
'blob.FastTrieBlobBuilder.fromTrieRoot',
82-
(ft) => ft.toTrieBlob(),
83-
);
84-
85-
test('blob.createTrieBlobFromITrieNodeRoot', () => FastTrieBlobBuilder.fromTrieRoot(trie.root).toTrieBlob());
74+
test('TrieBlobBuilder.fromTrieRoot', () => TrieBlobBuilder.fromTrieRoot(trie.root));
8675

8776
test('blob.TrieBlob.has', () => trieHasWords(trieBlob, words));
8877
test('blob.words', () => [...trieBlob.words()]);
@@ -118,12 +107,12 @@ function getTrie() {
118107
return readTrieFromConfig('@cspell/dict-en_us/cspell-ext.json');
119108
}
120109

121-
function getFastTrieBlob() {
122-
return readFastTrieBlobFromConfig('@cspell/dict-en_us/cspell-ext.json');
110+
function getTrieBlob() {
111+
return readTrieBlobFromConfig('@cspell/dict-en_us/cspell-ext.json');
123112
}
124113

125-
function getFastTrieBlobNL() {
126-
return readFastTrieBlobFromConfig('@cspell/dict-nl-nl/cspell-ext.json');
114+
function getTrieBlobNL() {
115+
return readTrieBlobFromConfig('@cspell/dict-nl-nl/cspell-ext.json');
127116
}
128117

129118
function trieHasWords(trie: TrieData, words: string[]): boolean {

packages/cspell-trie-lib/src/lib/ITrie.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { CompoundWordsMethod, WalkerIterator } from './ITrieNode/walker/wal
1212
import type { SuggestionCollector, SuggestionResult } from './suggestCollector.ts';
1313
import { createSuggestionOptions, type SuggestionOptions } from './suggestions/genSuggestionsOptions.ts';
1414
import { genSuggestions, suggest } from './suggestions/suggestTrieData.ts';
15-
import { FastTrieBlobBuilder } from './TrieBlob/FastTrieBlobBuilder.ts';
15+
import { TrieBlobBuilder } from './TrieBlob/TrieBlobBuilder.ts';
1616
import type { TrieData } from './TrieData.ts';
1717
import { clean } from './utils/clean.ts';
1818
import { memorizeLastCall } from './utils/memorizeLastCall.ts';
@@ -427,7 +427,7 @@ export class ITrieImpl implements ITrie {
427427
}
428428

429429
static create(words: Iterable<string> | IterableIterator<string>, info?: PartialTrieInfo): ITrie {
430-
const builder = new FastTrieBlobBuilder(info);
430+
const builder = new TrieBlobBuilder(info);
431431
builder.insert(words);
432432
const root = builder.build();
433433
return new ITrieImpl(root);

packages/cspell-trie-lib/src/lib/ITrieNode/find.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, test } from 'vitest';
22

33
import { parseDictionaryLegacy } from '../SimpleDictionaryParser.ts';
4-
import { FastTrieBlobBuilder } from '../TrieBlob/FastTrieBlobBuilder.ts';
4+
import { TrieBlobBuilder } from '../TrieBlob/TrieBlobBuilder.ts';
55
import type { TrieData } from '../TrieData.ts';
66
import type { TrieRoot } from '../TrieNode/TrieNode.ts';
77
import { TrieNodeTrie } from '../TrieNode/TrieNodeTrie.ts';
@@ -14,7 +14,7 @@ const findLegacyCompoundWord = __testing__.findLegacyCompoundWord;
1414
describe('Validate findWord', () => {
1515
const trie = dictionaryTrieNodeTrie().getRoot();
1616
const trieBlob = dictionaryTrieBlob().getRoot();
17-
const trieFast = FastTrieBlobBuilder.fromTrieRoot(dictionaryTrieRoot()).getRoot();
17+
const trieFast = TrieBlobBuilder.fromTrieRoot(dictionaryTrieRoot()).getRoot();
1818

1919
const cModeC = { compoundMode: 'compound' };
2020
const mCaseT = { matchCase: true };
@@ -265,8 +265,7 @@ function dictionaryTrieNodeTrie(): TrieData {
265265
}
266266

267267
function dictionaryTrieBlob(): TrieData {
268-
const ft = FastTrieBlobBuilder.fromTrieRoot(dictionaryTrieRoot());
269-
return ft.toTrieBlob();
268+
return TrieBlobBuilder.fromTrieRoot(dictionaryTrieRoot());
270269
}
271270

272271
const sampleWords = [

packages/cspell-trie-lib/src/lib/TrieBlob/FastTrieBlob.en.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { opSkip, opTake, pipe } from '@cspell/cspell-pipe/sync';
44
import { describe, expect, test } from 'vitest';
55

66
import { readTrieFromConfig } from '../../test/dictionaries.test.helper.ts';
7-
import { FastTrieBlobBuilder } from './FastTrieBlobBuilder.ts';
7+
import { TrieBlobBuilder } from './TrieBlobBuilder.ts';
88

99
function getTrie() {
1010
return readTrieFromConfig('@cspell/dict-en_us/cspell-ext.json');
@@ -17,11 +17,11 @@ describe('Validate English FastTrieBlob', async () => {
1717
const pTrie = getTrie();
1818
const sampleTrie = await pTrie;
1919
const sampleWordsLarge = [...pipe(sampleTrie.words(), opSkip(1000), opTake(6000))];
20-
const fastTrieBlob = FastTrieBlobBuilder.fromTrieRoot(sampleTrie.root);
20+
const fastTrieBlob = TrieBlobBuilder.fromTrieRoot(sampleTrie.root);
2121

2222
test('insert', () => {
2323
const words = sampleWordsLarge;
24-
const ft = FastTrieBlobBuilder.fromWordList(words);
24+
const ft = TrieBlobBuilder.fromWordList(words);
2525
const result = [...ft.words()];
2626
expect(result).toEqual(words.sort());
2727
});
@@ -35,7 +35,7 @@ describe('Validate English FastTrieBlob', async () => {
3535

3636
test('words', async () => {
3737
const words = await sampleWords;
38-
const ft = FastTrieBlobBuilder.fromWordList(words);
38+
const ft = TrieBlobBuilder.fromWordList(words);
3939
const result = [...ft.words()].sort();
4040

4141
const rSet = new Set(result);

0 commit comments

Comments
 (0)