New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/kanocz/go-prefixsearch

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/kanocz/go-prefixsearch

  • v0.0.0-20151117230902-1ee33bc7311c
  • Source
  • Go
  • Socket score

Version published
Created
Source

go-prefixsearch

Golang string prefix search (for autocomplete)

GoDoc

Installation

Install and update this go package with go get -u github.com/kanocz/go-prefixsearch

Examples

spackage main

import (
	"fmt"

	"github.com/kanocz/go-prefixsearch"
)

type someInfo struct {
	ID      int
	Name    string
	Comment string
}

func main() {

	data := []someInfo{
		{1, "Hello world!", "First example"},
		{2, "New impressions", "Second example"},
		{3, "Hello golang!", "Some other important info"},
		{4, "Привет, мир!", "Unicode symbols also work"},
		{5, "こんにちは世界", "Even this one may work"},
	}

	st := prefixsearch.New()
	for _, x := range data {
		st.Add(x.Name, x)
	}

	fmt.Println(st.AutoComplete("HE"))
  // Output: [{1 Hello world! First example} {3 Hello golang! Some other important info}]
	fmt.Println(st.AutoComplete("こん"))
  // Output: [{5 こんにちは世界 Even this one may work}]

	fmt.Println(st.Search("HE"))
  // Output: <nil>
	fmt.Println(st.Search("HELLO WORLD!"))
  // Output: {1 Hello world! First example}
	fmt.Println(st.Search("HELLO WORLD!!"))
  // Output: <nil>
}

FAQs

Package last updated on 17 Nov 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