From fa48a5510dd207759930586e0dc2a1627295c06f Mon Sep 17 00:00:00 2001 From: Duncan Harris Date: Mon, 9 May 2022 08:50:54 +0100 Subject: [PATCH 1/4] Extract func to check map + use for empty test --- uint32_store_test.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/uint32_store_test.go b/uint32_store_test.go index 7ce8942..e945dfb 100644 --- a/uint32_store_test.go +++ b/uint32_store_test.go @@ -14,22 +14,17 @@ 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 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 { From 82b3589445e3f6bf7bc3144e3504f02799aed73f Mon Sep 17 00:00:00 2001 From: Duncan Harris Date: Mon, 9 May 2022 08:51:14 +0100 Subject: [PATCH 2/4] Add failing test --- uint32_store_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/uint32_store_test.go b/uint32_store_test.go index e945dfb..579eb9c 100644 --- a/uint32_store_test.go +++ b/uint32_store_test.go @@ -18,6 +18,11 @@ func TestFastStringToUint32Empty(t *testing.T) { 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) From eed6da68a07f681da6e00f382b73a9848875428c Mon Sep 17 00:00:00 2001 From: Duncan Harris Date: Mon, 9 May 2022 08:52:25 +0100 Subject: [PATCH 3/4] Fix block size computation --- uint32_store.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/uint32_store.go b/uint32_store.go index a909d6b..81f150c 100644 --- a/uint32_store.go +++ b/uint32_store.go @@ -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 From 7718f2854611fc9ad38f9bf23a8f604140c4b6cb Mon Sep 17 00:00:00 2001 From: Duncan Harris Date: Mon, 9 May 2022 08:58:30 +0100 Subject: [PATCH 4/4] Update Go version --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c5eeae..4d18e2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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