Files
mgdigital 85bf13bc6a Deletion (#75)
- Add a stable bloom filter, stored in the database, for blocked and deleted torrents
- Add GraphQL mutations for blocking and deleting torrents
- Add web UI for bulk actions (tagging and deleting)
- Some minor cosmetic web UI tweaks
- Move database operations to dao package
2023-11-28 17:54:49 +00:00

40 lines
831 B
Go

package bloom
import (
"database/sql/driver"
"errors"
boom "github.com/tylertreat/BoomFilters"
)
type StableBloomFilter struct {
boom.StableBloomFilter
}
const defaultCapacity = 100_000_000
const defaultD = 2
const defaultFpRate = 0.001
func NewDefaultStableBloomFilter() *StableBloomFilter {
return &StableBloomFilter{*boom.NewStableBloomFilter(defaultCapacity, defaultD, defaultFpRate)}
}
func (s *StableBloomFilter) Scan(value interface{}) error {
bytes, ok := value.([]byte)
if !ok {
return errors.New("invalid type for StableBloomFilter")
}
bf := boom.NewStableBloomFilter(0, 0, 0)
if err := bf.GobDecode(bytes); err != nil {
return err
}
s.StableBloomFilter = *bf
return nil
}
func (s StableBloomFilter) Value() (driver.Value, error) {
if s.Cells() == 0 {
return nil, nil
}
return s.GobEncode()
}