Documentation
¶
Index ¶
Constants ¶
const LenOfMetadataSize = 2
Variables ¶
var InconsistentMetadataSizeErr = fmt.Errorf("inconsistent metadata size")
var (
InvalidPatternErr = fmt.Errorf("invalid pattern")
)
Functions ¶
Types ¶
type Controller ¶
type Controller struct { Fsync FsyncMode // Size in bytes MetadataSize uint16 // Control will be invoked every second. // // | len of metadata size(2 bytes) | metadata | bloom filter | Control func(f *os.File, modified bool) // GetParam will be invoked when New. // // | len of metadata size(2 bytes) | metadata | bloom filter | GetParam func(metadata []byte) (param FilterParam, updatedMetadata []byte) }
type DiskFilter ¶
type DiskFilter struct {
// contains filtered or unexported fields
}
Disk-based Classic Bloom Filter
func New ¶
func New(filename string, controller Controller) (*DiskFilter, error)
New creates a classic Bloom Filter. h is a double hash that takes an entry and returns two different hashes.
func (*DiskFilter) Close ¶
func (f *DiskFilter) Close() error
Close should be invoked if the filter is not needed anymore
func (*DiskFilter) Controller ¶
func (f *DiskFilter) Controller() Controller
func (*DiskFilter) Exist ¶
func (f *DiskFilter) Exist(b []byte) bool
Exist returns if an entry is in the filter
func (*DiskFilter) ExistOrAdd ¶
func (f *DiskFilter) ExistOrAdd(b []byte) (exist bool)
ExistOrAdd returns whether the entry was in the filter, and adds an entry to the filter if it was not in.
func (*DiskFilter) FilterParam ¶
func (f *DiskFilter) FilterParam() FilterParam
func (*DiskFilter) Size ¶
func (f *DiskFilter) Size() uint64
Size returns the size of the filter in bytes
type FilterGroup ¶
type FilterGroup struct {
// contains filtered or unexported fields
}
FilterGroup manages a group of DiskFilter. To make sure each filter meets the best performance, it will add new filters to the group if necessary.
func NewGroup ¶
func NewGroup(pattern string, fsync FsyncMode, n uint64, p float64, hash func([]byte) (uint64, uint64)) (*FilterGroup, error)
NewGroup returns a FilterGroup, each filter is a file. The filenames are generated by taking pattern and adding a index to the end. the Pattern should includes a "*", and the index replaces the last "*". n is the expected number of entries in single file. p is the expected false positive rate.
func (*FilterGroup) Exist ¶
func (g *FilterGroup) Exist(b []byte) (exist bool)
Exist returns if an entry is in the filterGroup
func (*FilterGroup) ExistOrAdd ¶
func (g *FilterGroup) ExistOrAdd(b []byte) (exist bool)
ExistOrAdd returns whether the entry was in the filter, and adds an entry to the filterGroup if it was not in. TODO: batch?