Skip to content

Commit

Permalink
Merge pull request #541 from proost/fix-incorrect-conversion
Browse files Browse the repository at this point in the history
fix: incorrect conversion
  • Loading branch information
rueian authored May 1, 2024
2 parents 0a8dd45 + 728343c commit 4dd52dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
16 changes: 6 additions & 10 deletions rueidisprob/bloomfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type BloomFilter interface {
Delete(ctx context.Context) error

// Count returns count of items in Bloom filter.
Count(ctx context.Context) (uint, error)
Count(ctx context.Context) (uint64, error)
}

type bloomFilter struct {
Expand Down Expand Up @@ -317,26 +317,22 @@ func (c *bloomFilter) Delete(ctx context.Context) error {
return resp.Error()
}

func (c *bloomFilter) Count(ctx context.Context) (uint, error) {
func (c *bloomFilter) Count(ctx context.Context) (uint64, error) {
resp := c.client.Do(
ctx,
c.client.B().
Get().
Key(c.counter).
Build(),
)
if resp.Error() != nil {
if rueidis.IsRedisNil(resp.Error()) {
count, err := resp.AsUint64()
if err != nil {
if rueidis.IsRedisNil(err) {
return 0, nil
}

return 0, resp.Error()
}

count, err := resp.AsUint64()
if err != nil {
return 0, err
}

return uint(count), nil
return count, nil
}
18 changes: 9 additions & 9 deletions rueidisprob/countingbloomfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ type CountingBloomFilter interface {
// ItemMinCount returns the minimum count of item in the Counting Bloom Filter.
// If the item is not in the Counting Bloom Filter, it returns a zero value.
// Minimum count is not always accurate because of the hash collisions.
ItemMinCount(ctx context.Context, key string) (uint, error)
ItemMinCount(ctx context.Context, key string) (uint64, error)

// ItemMinCountMulti returns the minimum count of items in the Counting Bloom Filter.
// If the item is not in the Counting Bloom Filter, it returns a zero value.
// Minimum count is not always accurate because of the hash collisions.
ItemMinCountMulti(ctx context.Context, keys []string) ([]uint, error)
ItemMinCountMulti(ctx context.Context, keys []string) ([]uint64, error)

// Count returns count of items in Counting Bloom Filter.
Count(ctx context.Context) (uint, error)
Count(ctx context.Context) (uint64, error)
}

type countingBloomFilter struct {
Expand Down Expand Up @@ -343,7 +343,7 @@ func (f *countingBloomFilter) Delete(ctx context.Context) error {
return resp.Error()
}

func (f *countingBloomFilter) ItemMinCount(ctx context.Context, key string) (uint, error) {
func (f *countingBloomFilter) ItemMinCount(ctx context.Context, key string) (uint64, error) {
counts, err := f.ItemMinCountMulti(ctx, []string{key})
if err != nil {
return 0, err
Expand All @@ -352,7 +352,7 @@ func (f *countingBloomFilter) ItemMinCount(ctx context.Context, key string) (uin
return counts[0], nil
}

func (f *countingBloomFilter) ItemMinCountMulti(ctx context.Context, keys []string) ([]uint, error) {
func (f *countingBloomFilter) ItemMinCountMulti(ctx context.Context, keys []string) ([]uint64, error) {
if len(keys) == 0 {
return nil, nil
}
Expand All @@ -376,7 +376,7 @@ func (f *countingBloomFilter) ItemMinCountMulti(ctx context.Context, keys []stri
return nil, err
}

counts := make([]uint, 0, len(messages))
counts := make([]uint64, 0, len(messages))
minCount := uint64(math.MaxUint64)
for i, message := range messages {
cnt, err := message.AsUint64()
Expand All @@ -393,15 +393,15 @@ func (f *countingBloomFilter) ItemMinCountMulti(ctx context.Context, keys []stri
}

if (i+1)%int(f.hashIterations) == 0 {
counts = append(counts, uint(minCount))
counts = append(counts, minCount)
minCount = uint64(math.MaxUint64)
}
}

return counts, nil
}

func (f *countingBloomFilter) Count(ctx context.Context) (uint, error) {
func (f *countingBloomFilter) Count(ctx context.Context) (uint64, error) {
resp := f.client.Do(
ctx,
f.client.B().
Expand All @@ -418,5 +418,5 @@ func (f *countingBloomFilter) Count(ctx context.Context) (uint, error) {
return 0, err
}

return uint(count), nil
return count, nil
}

0 comments on commit 4dd52dd

Please sign in to comment.