All Projects → rmandvikar → csharp-trie

rmandvikar / csharp-trie

Licence: MIT license
A trie (prefix tree) data structure implementation in C#.

Programming Languages

C#
18002 projects
shell
77523 projects

Projects that are alternatives of or similar to csharp-trie

trie-perf
Performance shootout of various trie implementations
Stars: ✭ 18 (-40%)
Mutual labels:  trie, prefix-tree
prefixtree
A prefix tree (trie) implementation in go
Stars: ✭ 21 (-30%)
Mutual labels:  trie, prefix-tree
trie
Trie (a.k.a. prefix tree) C# implementation. Has constant-time string prefix lookup.
Stars: ✭ 84 (+180%)
Mutual labels:  trie, prefix-tree
Java Ds Algorithms
Data Structures and Algorithms in Java
Stars: ✭ 125 (+316.67%)
Mutual labels:  trie
Trie4j
PATRICIA, Double Array, LOUDS Trie implementations for Java
Stars: ✭ 139 (+363.33%)
Mutual labels:  trie
Data Structures
A collection of powerful data structures
Stars: ✭ 2,534 (+8346.67%)
Mutual labels:  trie
lexpy
Python package for lexicon; Trie and DAWG implementation.
Stars: ✭ 47 (+56.67%)
Mutual labels:  trie
Gse
Go efficient multilingual NLP and text segmentation; support english, chinese, japanese and other. Go 高性能多语言 NLP 和分词
Stars: ✭ 1,695 (+5550%)
Mutual labels:  trie
trie
My take on an efficient implementation of a Trie in Javascript
Stars: ✭ 72 (+140%)
Mutual labels:  trie
Opencc4j
🇨🇳Open Chinese Convert is an opensource project for conversion between Traditional Chinese and Simplified Chinese.(java 中文繁简体转换)
Stars: ✭ 187 (+523.33%)
Mutual labels:  trie
Leetcode
High-quality LeetCode solutions
Stars: ✭ 178 (+493.33%)
Mutual labels:  trie
Algo Tree
Algo-Tree is a collection of Algorithms and data structures which are fundamentals to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. It contains solutions in various languages such as C++, Python and Java.
Stars: ✭ 166 (+453.33%)
Mutual labels:  trie
Algorithms
A collection of common algorithms and data structures implemented in java, c++, and python.
Stars: ✭ 142 (+373.33%)
Mutual labels:  trie
xcdat
Fast compressed trie dictionary library
Stars: ✭ 51 (+70%)
Mutual labels:  trie
Slim
Surprisingly space efficient trie in Golang(11 bits/key; 100 ns/get).
Stars: ✭ 1,705 (+5583.33%)
Mutual labels:  trie
Trienet
.NET Implementations of Trie Data Structures for Substring Search, Auto-completion and Intelli-sense. Includes: patricia trie, suffix trie and a trie implementation using Ukkonen's algorithm.
Stars: ✭ 122 (+306.67%)
Mutual labels:  trie
Router
⚡️ A lightning fast HTTP router
Stars: ✭ 158 (+426.67%)
Mutual labels:  trie
Patricia
Garbage collector-sensitive patricia tree for IP/CIDR tagging
Stars: ✭ 194 (+546.67%)
Mutual labels:  trie
Algorithms-Java
A collection of common algorithms and data structures implemented in Java.
Stars: ✭ 141 (+370%)
Mutual labels:  trie
rust sequence trie
Ergonomic trie data structure
Stars: ✭ 22 (-26.67%)
Mutual labels:  trie

csharp-trie

A trie (prefix tree) data structure implementation in C#.

main: Build Status dev: Build Status

nuget:

Install-Package rm.Trie

Trie Methods

// Adds a word to the Trie.
void AddWord(string word);

// Removes word from the Trie.
int RemoveWord(string word);

// Removes words by prefix from the Trie.
void RemovePrefix(string prefix);

// Gets all words in the Trie.
IEnumerable<string> GetWords();

// Gets words for given prefix.
IEnumerable<string> GetWords(string prefix);

// Returns true if the word is present in the Trie.
bool HasWord(string word);

// Returns true if the prefix is present in the Trie.
bool HasPrefix(string prefix);

// Gets the equivalent TrieNode in the Trie for given prefix.
TrieNode GetTrieNode(string prefix)

// Returns the count for the word in the Trie.
int WordCount(string word);

// Gets longest words from the Trie.
ICollection<string> GetLongestWords();

// Gets shortest words from the Trie.
ICollection<string> GetShortestWords();

// Clears all words from the Trie.
void Clear();

// Gets total word count in the Trie.
int Count();

// Gets unique word count in the Trie.
int UniqueCount();

// Gets the root trieNode.
TrieNode GetRootTrieNode();

Trie Example

// Creates a new trie.
ITrie trie = new Trie();

// Adds words.
trie.AddWord("test");
trie.AddWord("this");

// Gets all words.
var allWords = trie.GetWords();

// Gets words for a prefix.
var tePrefixWords = trie.GetWords("te");

// Checks if a word is present.
var hasWord = trie.HasWord("test");

// Checks if a prefix is present.
var hasPrefix = trie.HasPrefix("tes");

// Gets trieNode for prefix.
TrieNode trieNode = trie.GetTrieNode("tes");

// Gets trieNode from trieNode by prefix.
TrieNode testTrieNode = trieNode.GetTrieNode("t");

// Gets word count for a word.
var wordCount = trie.WordCount("test");

// Removes word.
int removeCount = trie.RemoveWord("test"); // removeCount = 1

// Removes words by prefix.
trie.RemovePrefix("thi");

// Gets longest words.
var longestWords = trie.GetLongestWords();

// Gets shortest words.
var shortestWords = trie.GetShortestWords();

// Clears all words.
trie.Clear();

// Gets counts.
trie.AddWord("test"); // adding "test" again
var count = trie.Count();
var uniqueCount = trie.UniqueCount();

// Gets the root trieNode.
var root = trie.GetRootTrieNode();

TrieMap Methods

// Gets TValue item for key from TrieMap.
TValue ValueBy(string key);

// Gets TValue items by key prefix from TrieMap.
IEnumerable<TValue> ValuesBy(string keyPrefix);

// Gets all TValue items from TrieMap.
IEnumerable<TValue> Values();

// Gets keys by key prefix from TrieMap.
IEnumerable<string> KeysBy(string keyPrefix);

// Gets all keys from TrieMap.
IEnumerable<string> Keys();

// Gets string->TValue pairs by key prefix from TrieMap.
IEnumerable<KeyValuePair<string, TValue>> KeyValuePairsBy(string keyPrefix);

// Gets all string->TValue pairs from TrieMap.
IEnumerable<KeyValuePair<string, TValue>> KeyValuePairs();

// Adds TValue item for key to TrieMap.
void Add(string key, TValue value);

// Returns true if key present in TrieMap.
bool HasKey(string key);

// Returns true if key prefix present in TrieMap.
bool HasKeyPrefix(string keyPrefix);

// Gets TrieNode for given key prefix.
TrieNode<TValue> GetTrieNode(string keyPrefix)

// Removes key from TrieMap.
void Remove(string key);

// Removes key prefix from TrieMap and return true else false.
bool RemoveKeyPrefix(string keyPrefix);

// Clears all values from TrieMap.
void Clear();

// Gets the root trieNode.
TrieNode<TValue> GetRootTrieNode();

TrieMap Example

ITrieMap<int> trieMap = new TrieMap<int>();

// Adds key-value.
trieMap.Add("key1", 1);
trieMap.Add("key12", 12);
trieMap.Add("key2", 2);

// Gets value item for key.
var value = trieMap.ValueBy("key1"); // value = 1

// Gets value items by key prefix.
var values = trieMap.ValuesBy("key1"); // values = { 1, 12 }

// Gets all value items.
var values = trieMap.Values(); // values = { 1, 12, 2 }

// Gets all value items.
var keys = trieMap.Keys(); // keys = { "key1", "key12", "key2" }

// Gets all key-value items.
var kvPairs = trieMap.KeyValuePairs();

// Returns true if key present.
bool hasKey = trieMap.HasKey("key1"); // hasKey = true

// Returns true if key prefix present.
bool hasKeyPrefix = trieMap.HasKeyPrefix("key"); // hasKeyPrefix = true

// Gets trieNode for key prefix.
TrieNode<int> key1TrieNode = trie.GetTrieNode("key1");

// Gets trieNode from trieNode by prefix.
TrieNode<int> key12TrieNode = key1TrieNode.GetTrieNode("2");

// Removes key.
trieMap.Remove("key1");
trieMap.Remove("key"); // throws

// Removes by key prefix.
bool isKeyPrefixRemoved = trieMap.RemoveKeyPrefix("key"); // isKeyPrefixRemoved = true

// Clears triemap.
trieMap.Clear();

// Gets the root trieNode.
var root = trie.GetRootTrieNode();

Note:

Not thread-safe.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].