retrieval 1.0.1 copy "retrieval: ^1.0.1" to clipboard
retrieval: ^1.0.1 copied to clipboard

A trie data structure Dart implementation — useful for autocomplete.

example/example.dart

import 'package:retrieval/key_value_trie.dart';
import 'package:retrieval/trie.dart';

void main() {
  final trie = Trie();

  // Insert a word into trie with trie.insert().
  trie.insert('crikey');
  trie.insert('crocodile');

  // You can use the list's forEach method for repeated insertion.
  final words = <String>['brekky', 'breakfast'];
  words.forEach(trie.insert);

  // Check for existence of words.
  print(trie.has('brekky')); // true
  print(trie.has('ghost')); // false

  // Find matching words by prefix.
  print(trie.find('br')); // ['breakfast', 'brekky']
  print(trie.find('cr')); // ['crocodile', 'crikey']
  print(trie.find('crikey')); // ['crikey']
  print(trie.find('ghost')); // []

  // Use a key-value trie to associate each word with a value.
  final keyValueTrie = KeyValueTrie<String>(); // Values of type String.

  keyValueTrie.insert('trophy', '🏆');
  keyValueTrie.insert('train', '🚆');

  // When finding matching words by prefix, the associated value is returned.
  print(keyValueTrie.find('tr')); // ['🚆', '🏆']
  print(keyValueTrie.find('trophy')); // ['🏆']
  print(keyValueTrie.find('trie')); // []
}
6
likes
150
pub points
66%
popularity

Publisher

verified publisherrohanchandra.dev

A trie data structure Dart implementation — useful for autocomplete.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

characters

More

Packages that depend on retrieval