trie.nim 488 B

123456789101112131415161718192021222324252627
  1. import
  2. hashes, tables, trie_database
  3. type
  4. MemDBTable = Table[KeccakHash, string]
  5. MemDB* = object
  6. tbl: MemDBTable
  7. proc hash*(key: KeccakHash): int =
  8. hashes.hash(key.data)
  9. proc get*(db: MemDB, key: KeccakHash): string =
  10. db.tbl[key]
  11. proc del*(db: var MemDB, key: KeccakHash): bool =
  12. if db.tbl.hasKey(key):
  13. db.tbl.del(key)
  14. return true
  15. else:
  16. return false
  17. proc put*(db: var MemDB, key: KeccakHash, value: string): bool =
  18. db.tbl[key] = value
  19. return true