Logo

Programming-Idioms

  • Groovy
  • D

Idiom #159 Trie

Define a Trie data structure, where entries have an associated value.
(Not all nodes are entries)

struct Trie
{
    Rune c;
    Trie*[Rune] children;
    bool isEntry;
    bool value;
}
  type trie_p
     type(trie), pointer :: p => NULL()
  end type trie_p
  type trie
     class(*), allocatable :: value
     type(trie_p), dimension(:), allocatable :: nodes
  end type trie

value can be any type at runtine, including a string.

New implementation...
< >
programming-idioms.org