Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/Claudiu/Trie

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/Claudiu/Trie

  • v0.0.0-20151026120200-ae8ac0727f5e
  • Source
  • Go
  • Socket score

Version published
Created
Source

Build Status GoDoc

Trie / Radix Tree / Digital Tree

In computer science, a trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes), is an ordered tree data structure that is used to store a dynamic set or associative array where the keys are usually strings.

Read More on: https://en.wikipedia.org/wiki/Trie

Usage

You start by defining the root of the Trie. Using trie.NewTrie()

package main

import "github.com/claudiu/trie"

func main() {
    rootTrie := trie.NewTrie()
    rootTrie.Add("heart")

    node := rootTrie.Find("heart")

    // do stuff with the node here
}

You can now return the trie node using:

rootTrie.Find("heart")

If the node is not found rootTrie.Find("heart") will return nil

Word Count

You can return the word count in a trie using:

rootTrie.Count()

Metadata

Each Trie node can hold metadata. Here's a small demo:

package main

import (
    "github.com/claudiu/trie"
    "fmt"
)

func main() {
    rootTrie := trie.NewTrie()
    rootTrie.Add("heart")

    node := rootTrie.Find("heart")

    node.Set("test", "alpha")

    item, found := node.Get("test")

    if found {
        fmt.Println(item.(string))
    }
}

FAQs

Package last updated on 26 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc