package bloomimport ()// Filter is an interface representing read-only bloom filters where programs// can probe for the possible presence of a hash key.typeFilterinterface {Check(uint64) bool}// SplitBlockFilter is an in-memory implementation of the parquet bloom filters.//// This type is useful to construct bloom filters that are later serialized// to a storage medium.typeSplitBlockFilter []Block// MakeSplitBlockFilter constructs a SplitBlockFilter value from the data byte// slice.func ( []byte) SplitBlockFilter {returnunsafecast.Slice[Block]()}// NumSplitBlocksOf returns the number of blocks in a filter intended to hold// the given number of values and bits of filter per value.//// This function is useful to determine the number of blocks when creating bloom// filters in memory, for example://// f := make(bloom.SplitBlockFilter, bloom.NumSplitBlocksOf(n, 10))func ( int64, uint) int { := ((uint() * ) + 7) / 8 := ( + (BlockSize - 1)) / BlockSizereturnint()}// Reset clears the content of the filter f.func ( SplitBlockFilter) () {for := range { [] = Block{} }}// Block returns a pointer to the block that the given value hashes to in the// bloom filter.func ( SplitBlockFilter) ( uint64) *Block { return &[fasthash1x64(, int32(len()))] }// InsertBulk adds all values from x into f.func ( SplitBlockFilter) ( []uint64) { filterInsertBulk(, ) }// Insert adds x to f.func ( SplitBlockFilter) ( uint64) { filterInsert(, ) }// Check tests whether x is in f.func ( SplitBlockFilter) ( uint64) bool { returnfilterCheck(, ) }// Bytes converts f to a byte slice.//// The returned slice shares the memory of f. The method is intended to be used// to serialize the bloom filter to a storage medium.func ( SplitBlockFilter) () []byte {returnunsafecast.Slice[byte]()}// CheckSplitBlock is similar to bloom.SplitBlockFilter.Check but reads the// bloom filter of n bytes from r.//// The size n of the bloom filter is assumed to be a multiple of the block size.func ( io.ReaderAt, int64, uint64) (bool, error) { := acquireBlock()deferreleaseBlock() := BlockSize * fasthash1x64(, int32(/BlockSize)) , := .ReadAt(.Bytes(), int64())return .Check(uint32()), }var ( blockPool sync.Pool)func acquireBlock() *Block { , := blockPool.Get().(*Block)if == nil { = new(Block) }return}func releaseBlock( *Block) {if != nil {blockPool.Put() }}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.