Programming-Idioms

This language bar is your friend. Select your favorite languages!

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 struct {
	c        rune
	children map[rune]*Trie
	isEntry  bool
	value    V
}
data Trie v 
  = Branch Char (Map Char (Trie v))
  | Leaf Char v
use Data::Trie qw();
my $trie = Data::Trie->new;
class Trie:
   def __init__(self, prefix, value=None):
       self.prefix = prefix
       self.children = []
       self.value = value
struct Trie {
    val: String,
    nodes: Vec<Trie>
}

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org