Coder Social home page Coder Social logo

dunkelhaus / trie-hadt Goto Github PK

View Code? Open in Web Editor NEW
11.0 4.0 1.0 99 KB

A Holochain Abstract Data Type (HADT) for abstracting the low-levels of implementing a radix tree / trie on Holochain.

License: GNU General Public License v3.0

Rust 95.35% JavaScript 4.65%
hadt holochain holochain-adt trie radix-tree

trie-hadt's Introduction

Radix Tree (Trie) HADT

Overview

trie-hadt is a library for Rust-based holochain dApps that intend to use a known Abstract Data Type, in this case, a Trie, as a Zome backend.

  • This HDK provides a wrapper to abstract the low-levels of using the Holograph data structure proposed by Holochain as a Trie.
  • Accepts a string, the term itself, and grafts it onto the tree in the prefix-searchable manner.
  • Categorizes the terms with keys, and a categoryString to them, which can be used in a different form of lookup (or a dump, since getting all the words from the trie requires BFS/DFS or some other exhaustive search).
    • The categorization is implemented in the backend with anchors.

Usage

First, Rust must be installed on your computer.

Being a Rust library, trie-hadt can be added as a dependency to any Rust crate. When you generate Rust based Zomes with holochain-cmd add the HADT to the zome's Cargo.toml in a new field labelled hadt, under the line hdk = { path = "..." }.

Sample:

hadt = { path = "<path to folder where trie-hadt is located>" }

Specification for App Development

  • Macro expansions for the entry type definitions have been provided within the trie-hadt.
  • Add extern crate hadt to the top of your src/lib.rs within the Zome whose backend you intend to use as a Trie.
  • When defining your zome, in src/lib.rs, define it like so:
#[macro_use]
extern crate hdk;
#[macro_use]
extern crate hadt;

// --- Other crates/modules you may need ---

define_zome! {
    entries: [
		hadt::entries::defineTrie(),
		hadt::entries::defineTrieNode(),
		hadt::entries::defineNull()
    ]

    genesis: || {
        Ok(())
    }
    
    functions: {
        // ... Your Zome Functions ...
    }

Functions Provided [API]

  • Trie(type, bucketing) [Constructor]

    • type, a string, is needed to semantically categorize an entire trie - if higher order tries are a preference.
    • bucketing, a boolean that says whether collisions of terms should be supported, or it should err instead, and not support duplicates.
  • insert(string, [category], [id])

    • Adds provided string to the trie.
    • Also adds link from anchor of type category to root of string. anchorText is string itself, or id if provided.
  • drop(string)

    • A soft delete, just removes the terminator link that designates the word, but retains the TrieNodes it used in case they are in use for other strings, or some other reason.
  • delete(string, [category], [id])

    • Removes string from trie.
    • Also destroys links from anchorType - id needed if specified id was different from standard lookup (by string).
  • lookup(string)

    • Looks for the string in the trie - returns true if found and false if not.
  • find(category, id)

    • This function instead looks with the id within the anchorType category to lookup rather than use the trie
    • Only exists for times when ID is different and the word is being found from a different context, where it itself is not known.

Contribute

  • The trie-hadt is an open source project. To contribute/add your own hadt, feel free to fork, and if any comments, questions, concerns - contact me via email -> Suraj Jena.
  • Holochain is also an open source project. To contribute, check out contributing guidelines for our general practices and protocols on participating in the community.

Built on (& for)

Built for Holochain Chat

trie-hadt's People

Contributors

dlee67 avatar dunkelhaus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.