Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TrieBlock {
- constructor (key) {
- this.related = new Map() // children (key => UID)
- this.key = key // node key in Trie
- this.eof = false // end-of-word stop flag
- this.data = null // additional embeded data, associated with a word
- }
- }
- // and the Trie
- class Trie {
- constructor(debug) {
- this.debug = debug
- this.entries = new Map()
- this.entries.set(null, new TrieBlock()) // Trie ROOT block
- }
- insert(str, withData) {
- // ... ok for me !
- }
- has(word) {
- // walk through Trie
- // seek for the word
- }
- fetch(word) {
- // fetch the data associated with the word
- }
- }
- trie.insert('CAR', 'Vroom!')
- trie.inseert('CAST', 'Habracadabra')
- trie.inseert('CAR', 'Meow!')
- * ROOT
- . C
- . A
- . R : Vroom!
- . S
- . T : Habracadra!
- . T : Meow!
Add Comment
Please, Sign In to add comment