riblt

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: MIT Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Implementation of Rateless Invertible Bloom Lookup Tables (Rateless IBLTs), as
proposed in paper Practical Rateless Set Reconciliation by Lei Yang, Yossi
Gilad, and Mohammad Alizadeh, which appeared in ACM SIGCOMM 2024. Full text is
available at https://doi.org/10.1145/3651890.3672219.

Rateless IBLTs solve the "set reconciliation" problem: letting Alice and Bob,
each holding a set of fixed-length bit strings, distributedly compute the
symmetric difference of their sets with minimum communication and computation.

For any set, Rateless IBLTs define an infinite sequence of "coded symbols",
each being the same size as a set element. For any two sets, their coded symbol
sequences alone are sufficient for computing their symmetric difference,
therefore enabling reconciliation. The number of coded symbols needed is linear
to the size of the symmetric difference and the coefficient converges to 1.35
as the difference size goes to infinite.

To run benchmarks that demonstrate the computation and communication efficieny
of Rateless IBLTs, run
  go test -bench .

A good starting point is example_test.go, a self-contained example of using
this package to synchronize two sets of integers. To try the example, run
  go test -v -run Example
Documentation is available at https://pkg.go.dev/github.com/yangl1996/riblt.

Although this library is the artifact of a research project, it is of
relatively high quality and should be suitable for deployment in production
systems where workload given to the library is trusted, i.e., not injected by
malicious actors.

An imcomplete list of implementations in other languages by other folks:
Rust https://github.com/Intersubjective/riblt-rust
Rust https://github.com/samWighton/rateless_iblt
C++  https://github.com/hoytech/riblet

Documentation

Overview

Package riblt implements Rateless Invertible Bloom Lookup Tables (Rateless IBLTs), a family of rateless codes that reconcile set differences.

Rateless IBLTs solve the "set reconciliation" problem. Imagine that two computers, Alice and Bob, each holds a set of fixed-length bit strings. We call the bit strings "source symbols". Alice and Bob wish to distributedly compute the symmetric difference of their sets, i.e., source symbols that are exclusively present on either Alice or Bob but not both computers.

Rateless IBLTs operate by defining an infinite sequence of "coded symbols" for any set. The coded symbol sequences have two strong properties. First, for any two sets, prefixes of their coded symbol sequences alone are sufficient for computing their symmetric difference. Second, the number of coded symbols, i.e., the length of the prefixes, required is linear to the size of the symmetric difference, where the coefficient converges to 1.35.

In practice, Alice and Bob locally generate the coded symbol sequences for their respective sets. Alice streams an increasingly long prefix of her sequence to Bob, who keeps trying to use the received prefix along with his locally generated sequence to recover the symmetric difference, which will happen after Bob receives a sufficiently long prefix.

To use this library, the user needs to define the source symbol being reconciled. See type Symbol. Then, the user instantiates an Encoder for Alice, and a Decoder for Bob. Alice and Bob's sets should be imported into the Encoder and the Decoder, respectively. The user should program Alice to stream coded symbols over a reliable transport to Bob, and program Bob to decode the symbols and signal Alice to stop when successful. See the example.

Example
package main

import (
	"encoding/binary"
	"fmt"
	"github.com/dchest/siphash"
	"github.com/yangl1996/riblt"
)

// item is the type of set elements we will reconcile. It implements
// riblt.Symbol.
type item uint64

// XOR implements the group operation. It is simply the bitwise exclusive-or of
// the operands.
func (t item) XOR(t2 item) item {
	return t ^ t2
}

// Hash hashes t using SipHash.
func (t item) Hash() uint64 {
	buf := [8]byte{}
	binary.LittleEndian.PutUint64(buf[0:8], uint64(t))
	return siphash.Hash(123, 456, buf[:])
}

func main() {
	// Alice and Bob each holds a set of items. Bob wishes to know the items
	// that Alice has but he does not, as well as items that he has but Alice
	// does not. Their sets are mostly the same.
	alice := []item{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} // only Alice has 2
	bob := []item{1, 3, 4, 5, 6, 7, 8, 9, 10, 11}  // only Bob has 11

	// Alice creates an encoder and gives it her set.
	enc := riblt.Encoder[item]{}
	for _, v := range alice {
		enc.AddSymbol(v)
	}
	// Bob creates a decoder and gives it his set.
	dec := riblt.Decoder[item]{}
	for _, v := range bob {
		dec.AddSymbol(v)
	}

	cost := 0
	for {
		// Alice generates the next coded symbol and sends to Bob.
		s := enc.ProduceNextCodedSymbol()
		cost += 1
		// Bob receives the next coded symbol from Alice, and tries to decode.
		dec.AddCodedSymbol(s)
		dec.TryDecode()
		if dec.Decoded() {
			break
		}
	}

	fmt.Println(dec.Remote()[0].Symbol, "is exclusive to Alice")
	fmt.Println(dec.Local()[0].Symbol, "is exclusive to Bob")
	fmt.Println(cost, "coded symbols sent")
}
Output:
2 is exclusive to Alice
11 is exclusive to Bob
2 coded symbols sent

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodedSymbol

type CodedSymbol[T Symbol[T]] struct {
	HashedSymbol[T]
	Count int64
}

CodedSymbol is a coded symbol produced by a Rateless IBLT encoder.

type Decoder

type Decoder[T Symbol[T]] struct {
	// contains filtered or unexported fields
}

Decoder computes the symmetric difference between two sets A, B. The Decoder knows B (the local set) and expects coded symbols for A (the remote set).

func (*Decoder[T]) AddCodedSymbol

func (d *Decoder[T]) AddCodedSymbol(c CodedSymbol[T])

AddCodedSymbol passes the next coded symbol in A's sequence to the Decoder. Coded symbols must be passed in the same ordering as they are generated by A's Encoder.

func (*Decoder[T]) AddHashedSymbol

func (d *Decoder[T]) AddHashedSymbol(s HashedSymbol[T])

AddHashedSymbol adds a source symbol to B, the Decoder's local set. It is undefined behavior to call AddHashedSymbol after AddCodedSymbol has been called one or multiple times.

func (*Decoder[T]) AddSymbol

func (d *Decoder[T]) AddSymbol(s T)

AddSymbol adds a source symbol to B, the Decoder's local set. It is undefined behavior to call AddSymbol after AddCodedSymbol has been called one or multiple times.

func (*Decoder[T]) Decoded

func (d *Decoder[T]) Decoded() bool

Decoded returns true if and only if every existing coded symbols d received so far have been decoded.

func (*Decoder[T]) Local

func (d *Decoder[T]) Local() []HashedSymbol[T]

Local returns the list of source symbols that are present in B but not in A.

func (*Decoder[T]) Remote

func (d *Decoder[T]) Remote() []HashedSymbol[T]

Remote returns the list of source symbols that are present in A but not in B.

func (*Decoder[T]) Reset

func (d *Decoder[T]) Reset()

Reset clears d. It is more efficient to call Reset to reuse an existing Decoder than creating a new one.

func (*Decoder[T]) TryDecode

func (d *Decoder[T]) TryDecode()

TryDecode tries to decode all coded symbols received so far.

type Encoder

type Encoder[T Symbol[T]] codingWindow[T]

Encoder is an incremental encoder of Rateless IBLTs. Once initialized with a set of source symbols by calling AddSymbol or AddHashedSymbol, a Encoder can incrementally generate coded symbols in the infinite sequence defined for the set. The set must not change after one or multiple coded symbols have been generated by calling ProduceNextCodedSymbol.

func (*Encoder[T]) AddHashedSymbol

func (e *Encoder[T]) AddHashedSymbol(s HashedSymbol[T])

AddHashedSymbol adds source symbol s to e. It is undefined behavior to call AddHashedSymbol after calling ProduceNextCodedSymbol.

func (*Encoder[T]) AddSymbol

func (e *Encoder[T]) AddSymbol(s T)

AddSymbol adds source symbol s to e. It is undefined behavior to call AddSymbol after calling ProduceNextCodedSymbol.

func (*Encoder[T]) ProduceNextCodedSymbol

func (e *Encoder[T]) ProduceNextCodedSymbol() CodedSymbol[T]

ProduceNextCodedSymbol returns the next coded symbol in the sequence.

func (*Encoder[T]) Reset

func (e *Encoder[T]) Reset()

Reset clears e. It is more efficient to call Reset to reuse an existing Encoder than creating a new one.

type HashedSymbol

type HashedSymbol[T Symbol[T]] struct {
	Symbol T
	Hash   uint64
}

HashedSymbol is the bundle of a symbol and its hash computed using its Hash method.

type Sketch

type Sketch[T Symbol[T]] []CodedSymbol[T]

Sketch is a prefix of the coded symbol sequence for a set of source symbols. When generating a prefix of predetermined length, compared to generating the prefix incrementally using an Encoder, it is more efficient to use Sketch. Sketch also allows inserting or deleting source symbols from the set after it has been created.

func (Sketch[T]) AddHashedSymbol

func (s Sketch[T]) AddHashedSymbol(t HashedSymbol[T])

AddHashedSymbol inserts source symbol t to the set of which s is a sketch.

func (Sketch[T]) AddSymbol

func (s Sketch[T]) AddSymbol(t T)

AddSymbol inserts source symbol t to the set of which s is a sketch.

func (Sketch[T]) Decode

func (s Sketch[T]) Decode() (fwd []HashedSymbol[T], rev []HashedSymbol[T], succ bool)

Decode tries to decode s, where s can be one of the following

  1. A sketch of set S.
  2. Content of s after calling s.Subtract(s2), where s is a sketch of set S, and s2 is a sketch of set S2.

When successful, indicated by succ being true, fwd contains all source symbols in S in case 1, or S \ S2 in case 2 (\ is the set subtraction operation). rev is empty in case 1, or S2 \ S in case 2.

func (Sketch[T]) RemoveHashedSymbol

func (s Sketch[T]) RemoveHashedSymbol(t HashedSymbol[T])

RemoveHashedSymbol deletes source symbol t from the set of which s is a sketch.

func (Sketch[T]) RemoveSymbol

func (s Sketch[T]) RemoveSymbol(t T)

RemoveSymbol deletes source symbol t from the set of which s is a sketch.

func (Sketch[T]) Subtract

func (s Sketch[T]) Subtract(s2 Sketch[T])

Subtract subtracts s2 from s by modifying s in place. s and s2 must be of equal length. If s is a sketch of set S and s2 is a sketch of set S2, then the result is a sketch of the symmetric difference between S and S2.

type Symbol

type Symbol[T any] interface {
	// XOR returns t $ t2, where t is the method receiver. XOR is allowed to
	// modify the method receiver in-place (when T is a pointer) and return the
	// modified t. Although the method is called XOR (because the bitwise
	// exclusive-or operation is a valid group operation for groups of
	// fixed-length byte strings), it can implement any operation that satisfy
	// the aforementioned properties.
	XOR(t2 T) T
	// Hash returns the hash of the method receiver. It must not modify the
	// method receiver. It must not be homomorphic over the group operation.
	// That is, the probability that
	//   (a $ b).Hash() == a.Hash() ^ b.Hash()
	// must be negligible. Here, ^ on the right-hand side is the bitwise
	// exclusive-or operation.
	Hash() uint64
}

Symbol is the interface that source symbols (set elements being reconciled) should implement. It specifies a Boolean group, where type T (or its subset) is the underlying set, and $ is the group operation. It should satisfy the following properties:

  1. For all a, b, c in the group, (a $ b) $ c = a $ (b $ c).
  2. Let e be the default value of T. For every a in the group, e $ a = a and a $ e = a.
  3. For every a in the group, a $ a = e.

As an example, when source symbols are plain byte strings of length 32, T is [32]byte. $ can be the bitwise exclusive-or (XOR) operation. e is the byte string where every byte is zero.

Jump to

Keyboard shortcuts

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