GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tannerryan/ring: Package ring provides a high performance and thread safe Go implementation of a bloom filter.

BranchesTags
Open more actions menu

Latest commit

 

History

30 Commits
30 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
example
example
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
doc.go
doc.go
 
 
go.mod
go.mod
 
 
hash.go
hash.go
 
 
hash_test.go
hash_test.go
 
 
ring.go
ring.go
 
 
ring_test.go
ring_test.go
 
 

Repository files navigation

ring

Go Reference License

A small, thread-safe Bloom filter for Go. A Bloom filter can rule out membership with certainty. Positive results are probabilistic.

Go 1.27 or newer is required.

Installation

go get github.com/tannerryan/ring@latest

Usage

package main

import (
	"fmt"

	"github.com/tannerryan/ring"
)

func main() {
	filter, err := ring.Init(100_000, 0.001)
	if err != nil {
		panic(err)
	}

	filter.Add([]byte("hello"))
	fmt.Println(filter.Test([]byte("hello"))) // true
	fmt.Println(filter.Test([]byte("world"))) // probably false
}

Init takes the expected number of elements and the desired false-positive rate. Adding more than the expected number increases the rate. After initialization, all methods are safe for concurrent use. Use InitByParameters when the exact bit count and number of hash rounds are already known. Both values must be positive, and the hash rounds cannot exceed the bit count. Entries cannot be removed individually. Reset clears the entire filter.

Persistence

encoded, err := filter.MarshalBinary()
if err != nil {
	panic(err)
}

var restored ring.Ring
err = restored.UnmarshalBinary(encoded)
if err != nil {
	panic(err)
}

fmt.Println(restored.Test([]byte("hello"))) // true

MarshalBinary and UnmarshalBinary save and restore a filter. Merge combines filters with the same sizing and binary version. Version 1 filters remain readable and retain their original hash behavior. New encodings use version 2 and cannot be read by older releases.

The implementation uses MurmurHash3, a fast non-cryptographic hash. Treat the filter as a probabilistic data structure, not as a security boundary.

Development

Install the development tools with make deps, then run make check.

License

This project is available under the BSD 2-Clause License.

About

Package ring provides a high performance and thread safe Go implementation of a bloom filter.

pkg.go.dev/github.com/tannerryan/ring

Topics

gogolang

Resources

Readme
BSD-2-Clause license
Activity

Stars

147 stars

Watchers

1 watching

Forks

16 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.