presence

package
v1.64.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package presence holds the Bloom filter an agent consults before uploading a blob: a positive answer is probably right, a negative one is certain.

Index

Constants

View Source
const FalsePositiveRate = 0.01

FalsePositiveRate is what filters are sized for.

View Source
const Version = 1

Version is the format written by Proto.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {

	// Commit and Set say which commit the filter was built from.
	Commit *proto.Ref
	Set    string
	// contains filtered or unexported fields
}

Filter is a Bloom filter over refs.

func FromProto

func FromProto(p *proto.PresenceFilter) (*Filter, error)

FromProto decodes a filter written by Proto.

func New

func New(n uint64) *Filter

New returns an empty filter sized for n refs at FalsePositiveRate.

func Sized

func Sized(n uint64, p float64) *Filter

Sized returns an empty filter sized for n refs at false-positive rate p.

func (*Filter) Add

func (f *Filter) Add(hash []byte)

Add records a ref. Refs shorter than 16 bytes are ignored.

func (*Filter) Entries

func (f *Filter) Entries() uint64

Entries is the number of refs added.

func (*Filter) Proto

func (f *Filter) Proto() *proto.PresenceFilter

Proto encodes the filter for storage and transport.

func (*Filter) Size

func (f *Filter) Size() int

Size is the byte size of the bit array.

func (*Filter) Test

func (f *Filter) Test(hash []byte) bool

Test reports whether the ref may have been added.

type Set

type Set []*Filter

Set is the filters of one scope, consulted together.

func (Set) Entries

func (s Set) Entries() uint64

Entries is the number of refs over all filters.

func (Set) Size

func (s Set) Size() int

Size is the byte size of all bit arrays.

func (Set) Test

func (s Set) Test(hash []byte) bool

Test reports whether any filter may hold the ref.

Jump to

Keyboard shortcuts

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