Giter Site home page Giter Site logo

trying's Introduction

trying

Provides a simple Trie implementation for storing "keys" composed of "atoms".

The trie imposes restrictions on the key, atom and value types:

  • keys must be: Clone + Default + Ord + FromIterator (aggregate trait: TrieKey)
  • atoms must be: Copy + Default + PartialEq + Ord (aggregate trait: TrieAtom)
  • values must be: Default (aggregate trait: TrieValue)

(where A represents the Atom type that the key will be represented as)

With these restrictions in place, the trie implements a reasonably efficient mechanism for:

  • prefix matching
  • representing large quantities of data with common prefixes
  • finding shortest unique prefix
  • finding alternative values
  • finding longest common prefixes

For Example:

use trying::trie::TrieVec;
use unicode_segmentation::UnicodeSegmentation;

// Declare a trie which will store &str keys
// with usize values.
let mut trie = TrieVec::<&str, usize>::new();
let s = "a̐éö̲\r\n";
let input = s.graphemes(true);
// Insert our graphemes into the trie
trie.insert(input.clone());
// Anything which implements IntoIterator<Item=&str> can now be used
// to interact with our Trie
assert!(trie.contains(input.clone()));
assert!(trie.remove(input.clone()).is_none());
assert!(!trie.contains(input));

If you don't need prefix matching, then a HashMap is almost always a better choice than a trie...

Crates.io

API Docs

Installation

[dependencies]
trying = "0.5"

Features are available.

License

Apache 2.0 licensed. See LICENSE for details.

trying's People

Contributors

garypen avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.