setsum

package module
v0.0.0-...-414dcc8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 3 Imported by: 0

README

setsum - Order agnostic, Commutative checksum

This is Go port of setsum from Rust [crate, source].

For introduction to setsum, check this post - http://avi.im/blag/2025/setsum

Documentation

Index

Examples

Constants

View Source
const SetsumBytes = 32
View Source
const SetsumBytesPerColumn = 4
View Source
const SetsumColumns = SetsumBytes / SetsumBytesPerColumn

Variables

View Source
var SetsumPrimes = [...]uint32{
	4294967291, 4294967279, 4294967231, 4294967197, 4294967189, 4294967161, 4294967143, 4294967111}

Functions

This section is empty.

Types

type Setsum

type Setsum struct {
	// contains filtered or unexported fields
}
Example
s1 := NewSetsum()

// add some items
s1.Insert([]byte("hello"))
s1.Insert([]byte("world"))

// add same items but in different order
s2 := NewSetsum()
s2.Insert([]byte("world"))
s2.Insert([]byte("hello"))

fmt.Printf("Digests equal: %t\n", s1.Digest() == s2.Digest())
Output:
Digests equal: true

func NewSetsum

func NewSetsum() *Setsum

func (*Setsum) Add

func (s *Setsum) Add(other *Setsum)

func (*Setsum) Digest

func (s *Setsum) Digest() [SetsumBytes]byte

func (*Setsum) HexDigest

func (s *Setsum) HexDigest() string

func (*Setsum) Insert

func (s *Setsum) Insert(item []byte)
Example
s := NewSetsum()
s.Insert([]byte("hello"))
s.Insert([]byte("hello"))

// remove the dupe
s.Remove([]byte("hello"))

c := NewSetsum()
c.Insert([]byte("hello"))
fmt.Printf("`hello hello` after removing one 'hello' equals digest of 'hello': %t\n", s.Digest() == c.Digest())
Output:
`hello hello` after removing one 'hello' equals digest of 'hello': true

func (*Setsum) InsertMany

func (s *Setsum) InsertMany(items [][]byte)

func (*Setsum) Remove

func (s *Setsum) Remove(item []byte)
Example
s := NewSetsum()
s.Insert([]byte("hello"))
s.Insert([]byte("world"))

// remove in different order
s.Remove([]byte("hello"))

{
	world := NewSetsum()
	world.Insert([]byte("world"))
	fmt.Printf("`hello world` after removing 'hello' equals digest of 'world': %t\n", s.Digest() == world.Digest())
}

s.Remove([]byte("world"))

empty := NewSetsum()
fmt.Printf("Digest after removing all items equals empty digest: %t\n", s.Digest() == empty.Digest())
Output:
`hello world` after removing 'hello' equals digest of 'world': true
Digest after removing all items equals empty digest: true

func (*Setsum) RemoveMany

func (s *Setsum) RemoveMany(items [][]byte)

func (*Setsum) Subtract

func (s *Setsum) Subtract(other *Setsum)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL