-
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
1 parent
0df5f50
commit 4bb25de
Showing
13 changed files
with
324 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# @ultify/datastructure | ||
|
||
## 0.4.0 | ||
|
||
### Minor Changes | ||
|
||
- Added Trie | ||
|
||
## 0.3.5 | ||
|
||
### Patch Changes | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './stack'; | ||
export * from './queue'; | ||
export * from './heap'; | ||
export * from './trie'; |
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 @@ | ||
export * from './trie'; |
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,137 @@ | ||
import { Trie } from './trie'; | ||
|
||
describe('Trie', () => { | ||
describe('constructor', () => { | ||
it('Should construct a trie', () => { | ||
const trie = new Trie(); | ||
trie | ||
.insert('abc') | ||
.insert('xyz') | ||
.insert('foo') | ||
.insert('bar') | ||
.insert('atmosphere'); | ||
expect(trie.nodeCount).toBe(22); | ||
expect(trie.wordCount).toBe(5); | ||
}); | ||
|
||
it('Should construct a trie', () => { | ||
const trie = new Trie('abc', 'xyz', 'foo', 'bar'); | ||
expect(trie.nodeCount).toBe(13); | ||
expect(trie.wordCount).toBe(4); | ||
}); | ||
|
||
it('Should construct a trie', () => { | ||
const trie = Trie.fromArray(['abc', 'xyz', 'foo', 'bar']); | ||
expect(trie.nodeCount).toBe(13); | ||
expect(trie.wordCount).toBe(4); | ||
}); | ||
}); | ||
|
||
describe('Search', () => { | ||
it('Should work correctly', () => { | ||
const trie = new Trie(); | ||
trie | ||
.insert('abc') | ||
.insert('xyz') | ||
.insert('foo') | ||
.insert('bar') | ||
.insert('atmosphere'); | ||
expect(trie.has('abc')).toBe(true); | ||
expect(trie.has('bar')).toBe(true); | ||
expect(trie.has('atmosphere')).toBe(true); | ||
expect(trie.has('gy')).toBe(false); | ||
expect(trie.has('atmospher')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('Starts with', () => { | ||
it('Should work correctly', () => { | ||
const trie = new Trie(); | ||
trie | ||
.insert('abc') | ||
.insert('xyz') | ||
.insert('foo') | ||
.insert('bar') | ||
.insert('atmosphere'); | ||
expect(trie.startsWith('abc')).toBe(true); | ||
expect(trie.startsWith('bar')).toBe(true); | ||
expect(trie.startsWith('gy')).toBe(false); | ||
expect(trie.startsWith('atmospher')).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('Iteration', () => { | ||
it('Should be iterable', () => { | ||
const trie = new Trie(); | ||
trie | ||
.insert('abc') | ||
.insert('xyz') | ||
.insert('foo') | ||
.insert('bar') | ||
.insert('atmosphere'); | ||
expect([...trie]).toContain('abc'); | ||
expect([...trie]).toContain('xyz'); | ||
expect([...trie]).toContain('foo'); | ||
expect([...trie]).toContain('bar'); | ||
expect([...trie]).toContain('atmosphere'); | ||
}); | ||
|
||
it('toArray should return new array', () => { | ||
const trie = new Trie(); | ||
trie | ||
.insert('abc') | ||
.insert('xyz') | ||
.insert('foo') | ||
.insert('bar') | ||
.insert('atmosphere'); | ||
expect(Array.isArray(trie.toArray())).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('Remove', () => { | ||
it('Should work correctly', () => { | ||
const trie = new Trie(); | ||
trie | ||
.insert('abc') | ||
.insert('xyz') | ||
.insert('foo') | ||
.insert('bar') | ||
.insert('atmosphere'); | ||
trie.remove('atmosphere'); | ||
expect([...trie]).toContain('abc'); | ||
expect([...trie]).toContain('xyz'); | ||
expect([...trie]).toContain('foo'); | ||
expect([...trie]).toContain('bar'); | ||
expect([...trie]).not.toContain('atmosphere'); | ||
expect(trie.nodeCount).toBe(13); | ||
expect(trie.wordCount).toBe(4); | ||
|
||
trie.remove('b'); | ||
expect([...trie]).toContain('abc'); | ||
expect([...trie]).toContain('xyz'); | ||
expect([...trie]).toContain('foo'); | ||
expect([...trie]).toContain('bar'); | ||
expect(trie.nodeCount).toBe(13); | ||
expect(trie.wordCount).toBe(4); | ||
|
||
trie.remove('k'); | ||
expect([...trie]).toContain('abc'); | ||
expect([...trie]).toContain('xyz'); | ||
expect([...trie]).toContain('foo'); | ||
expect([...trie]).toContain('bar'); | ||
expect(trie.nodeCount).toBe(13); | ||
expect(trie.wordCount).toBe(4); | ||
}); | ||
}); | ||
|
||
describe('Clear', () => { | ||
it('Should clear all nodes', () => { | ||
const trie = new Trie('abc', 'xyz', 'foo', 'bar'); | ||
expect(trie.nodeCount).toBe(13); | ||
expect(trie.wordCount).toBe(4); | ||
trie.clear(); | ||
expect(trie.nodeCount).toBe(1); | ||
expect(trie.wordCount).toBe(0); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.