Guest User

Untitled

a guest
Mar 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. class TrieBlock {
  2. constructor (key) {
  3. this.related = new Map() // children (key => UID)
  4. this.key = key // node key in Trie
  5. this.eof = false // end-of-word stop flag
  6. this.data = null // additional embeded data, associated with a word
  7. }
  8. }
  9.  
  10. // and the Trie
  11. class Trie {
  12. constructor(debug) {
  13. this.debug = debug
  14. this.entries = new Map()
  15. this.entries.set(null, new TrieBlock()) // Trie ROOT block
  16.  
  17. }
  18.  
  19. insert(str, withData) {
  20. // ... ok for me !
  21. }
  22.  
  23. has(word) {
  24. // walk through Trie
  25. // seek for the word
  26. }
  27.  
  28. fetch(word) {
  29. // fetch the data associated with the word
  30. }
  31. }
  32.  
  33. trie.insert('CAR', 'Vroom!')
  34. trie.inseert('CAST', 'Habracadabra')
  35. trie.inseert('CAR', 'Meow!')
  36.  
  37. * ROOT
  38. . C
  39. . A
  40. . R : Vroom!
  41. . S
  42. . T : Habracadra!
  43. . T : Meow!
Add Comment
Please, Sign In to add comment