Skip to content

Commit

Permalink
Merge pull request #3 from sensiblecodeio/duncan/fix-cap
Browse files Browse the repository at this point in the history
Fix block size computation
  • Loading branch information
phynes-sensiblecode authored May 9, 2022
2 parents 99e4718 + 7718f28 commit 79084ac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '~1.16.6'
go-version: '~1.17.9'
id: go

- name: Install utilities
Expand Down
7 changes: 5 additions & 2 deletions uint32_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,13 @@ func (b *uint32Builder) alloc(nByteValues byte) []byteValue {
*cur = (*cur)[: curLen+n : curCap]
return (*cur)[curLen:]
}
newCap := curCap
if newCap < maxBuildBufSize {
newCap := curCap * 2
for newCap < n {
newCap *= 2
}
if newCap > maxBuildBufSize {
newCap = maxBuildBufSize
}
a := make([]byteValue, n, newCap)
b.all = append(b.all, a)
return a
Expand Down
22 changes: 11 additions & 11 deletions uint32_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ import (
)

func TestFastStringToUint32Empty(t *testing.T) {
ms := mapSliceN(nil, 0)
fm := faststringmap.NewUint32Store(ms)
if keys := ms.AppendKeys(nil); len(keys) != 0 {
t.Errorf("keys should be empty, got %#v", keys)
}
for _, k := range []string{"", "a", "foo", "ß"} {
if actV, ok := fm.LookupString(k); ok {
t.Errorf("%q present when not expected, got %d", k, actV)
}
}
ms := mapSliceN(map[string]uint32{"": 1, "a": 2, "foo": 3, "ß": 4}, 0)
checkWithMapSlice(t, ms)
}

func TestFastStringToUint32BigSpan(t *testing.T) {
ms := mapSliceN(map[string]uint32{"a!": 1, "a~": 2}, 2)
checkWithMapSlice(t, ms)
}

func TestFastStringToUint32(t *testing.T) {
const nStrs = 8192
m := randomSmallStrings(nStrs, 8)
ms := mapSliceN(m, len(m)/2)
checkWithMapSlice(t, mapSliceN(m, len(m)/2))
}

func checkWithMapSlice(t *testing.T, ms mapSlice) {
fm := faststringmap.NewUint32Store(ms)

for _, k := range ms.in {
Expand Down

0 comments on commit 79084ac

Please sign in to comment.