refset.go 647 Bytes
Newer Older
1
package set
2 3 4 5 6 7 8 9 10 11

import (
	"github.com/jbenet/go-ipfs/blocks/bloom"
	"github.com/jbenet/go-ipfs/util"
)

type refCntBlockSet struct {
	blocks map[util.Key]int
}

12
func NewRefCountBlockSet() BlockSet {
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
	return &refCntBlockSet{blocks: make(map[util.Key]int)}
}

func (r *refCntBlockSet) AddBlock(k util.Key) {
	r.blocks[k]++
}

func (r *refCntBlockSet) RemoveBlock(k util.Key) {
	v, ok := r.blocks[k]
	if !ok {
		return
	}
	if v <= 1 {
		delete(r.blocks, k)
	} else {
		r.blocks[k] = v - 1
	}
}

func (r *refCntBlockSet) HasKey(k util.Key) bool {
	_, ok := r.blocks[k]
	return ok
}

func (r *refCntBlockSet) GetBloomFilter() bloom.Filter {
	return nil
}