-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Hunspell make sure COMPOUNDFLAG is supported (#2088)
* fix: Hunspell make sure COMPOUNDFLAG is supported * Make sure `isCompoundPermitted` is honored
- Loading branch information
Showing
8 changed files
with
137 additions
and
103 deletions.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
packages/cspell-trie-lib/src/lib/secondChanceCache.test.ts
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,47 @@ | ||
import { SecondChanceCache } from './secondChanceCache'; | ||
|
||
describe('Validate SecondChanceCache', () => { | ||
test('SecondChanceCache', () => { | ||
const cache = new SecondChanceCache<string, number>(3); | ||
let cnt = 0; | ||
cache.set('a', ++cnt); | ||
expect(cache.has('a')).toBe(true); | ||
cache.set('b', ++cnt); | ||
expect(cache.size).toBe(2); | ||
cache.set('a', 1); | ||
expect(cache.size).toBe(2); | ||
cache.set('c', ++cnt); | ||
expect(cache.size).toBe(3); | ||
expect(cache.get('c')).toBe(3); | ||
expect(cache.size).toBe(3); | ||
cache.set('d', ++cnt); | ||
expect(cache.size).toBe(4); | ||
cache.set('e', ++cnt); | ||
expect(cache.size).toBe(5); | ||
cache.set('f', ++cnt); | ||
expect(cache.size).toBe(6); | ||
expect(cache.get('b')).toBe(2); | ||
expect(cache.size).toBe(4); | ||
expect(cache.size0).toBe(1); | ||
expect(cache.size1).toBe(3); | ||
expect(cache.toArray()).toEqual([ | ||
['d', 4], | ||
['e', 5], | ||
['f', 6], | ||
['b', 2], | ||
]); | ||
cache.set('g', ++cnt); | ||
expect(cache.size).toBe(5); | ||
expect(cache.size0).toBe(2); | ||
expect(cache.has('a')).toBe(false); | ||
expect(cache.get('a')).toBe(undefined); | ||
expect(cache.has('f')).toBe(true); | ||
expect(cache.size0).toBe(3); | ||
expect(cache.size1).toBe(2); | ||
expect(cache.get('f')).toBe(6); | ||
expect(cache.size0).toBe(3); | ||
expect(cache.size1).toBe(2); | ||
expect(cache.clear()).toBe(cache); | ||
expect(cache.size).toBe(0); | ||
}); | ||
}); |
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,65 @@ | ||
export class SecondChanceCache<Key, Value> { | ||
private map0: Map<Key, Value>; | ||
private map1: Map<Key, Value>; | ||
|
||
constructor(readonly maxL0Size: number) { | ||
this.map0 = new Map<Key, Value>(); | ||
this.map1 = new Map<Key, Value>(); | ||
} | ||
|
||
public has(key: Key) { | ||
if (this.map0.has(key)) return true; | ||
if (this.map1.has(key)) { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
this.set(key, this.get1(key)!); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public get(key: Key): Value | undefined { | ||
return this.map0.get(key) ?? this.get1(key); | ||
} | ||
|
||
public set(key: Key, value: Value): this { | ||
if (this.map0.size >= this.maxL0Size && !this.map0.has(key)) { | ||
this.map1 = this.map0; | ||
this.map0 = new Map<Key, Value>(); | ||
} | ||
this.map0.set(key, value); | ||
return this; | ||
} | ||
|
||
public get size(): number { | ||
return this.map0.size + this.map1.size; | ||
} | ||
|
||
public get size0(): number { | ||
return this.map0.size; | ||
} | ||
|
||
public get size1(): number { | ||
return this.map1.size; | ||
} | ||
|
||
public clear(): this { | ||
this.map0.clear(); | ||
this.map1.clear(); | ||
return this; | ||
} | ||
|
||
private get1(key: Key): Value | undefined { | ||
if (this.map1.has(key)) { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const v = this.map1.get(key)!; | ||
this.map1.delete(key); | ||
this.set(key, v); | ||
return v; | ||
} | ||
return undefined; | ||
} | ||
|
||
public toArray(): [Key, Value][] { | ||
return [...this.map1, ...this.map0]; | ||
} | ||
} |
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