Skip to content

Commit debf11a

Browse files
committed
feat: adding compaction
1 parent 3cfb166 commit debf11a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

matchers.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"encoding/gob"
77
"fmt"
8+
"hash/fnv"
89
"log/slog"
910
"runtime"
1011
"strconv"
@@ -14,6 +15,8 @@ import (
1415

1516
var DefaultMatcher = MatchByLevelAndMessage()
1617

18+
// Matcher is a function that returns a string hash for a given record.
19+
// Returning []byte would have been much much better, but go's hashmap doesn't support it. 🤬
1720
type Matcher func(context.Context, *slog.Record) string
1821

1922
func MatchAll() func(context.Context, *slog.Record) string {
@@ -113,3 +116,19 @@ func anyToString(value any) string {
113116

114117
return buf.String()
115118
}
119+
120+
func CompactionFNV32a(input string) string {
121+
hash := fnv.New32a()
122+
hash.Write([]byte(input))
123+
return strconv.FormatInt(int64(hash.Sum32()), 10)
124+
}
125+
126+
func CompactionFNV64a(input string) string {
127+
hash := fnv.New64a()
128+
hash.Write([]byte(input))
129+
return strconv.FormatInt(int64(hash.Sum64()), 10)
130+
}
131+
132+
func CompactionFNV128a(input string) string {
133+
return string(fnv.New128a().Sum([]byte(input)))
134+
}

0 commit comments

Comments
 (0)