File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 5
5
"context"
6
6
"encoding/gob"
7
7
"fmt"
8
+ "hash/fnv"
8
9
"log/slog"
9
10
"runtime"
10
11
"strconv"
@@ -14,6 +15,8 @@ import (
14
15
15
16
var DefaultMatcher = MatchByLevelAndMessage ()
16
17
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. 🤬
17
20
type Matcher func (context.Context , * slog.Record ) string
18
21
19
22
func MatchAll () func (context.Context , * slog.Record ) string {
@@ -113,3 +116,19 @@ func anyToString(value any) string {
113
116
114
117
return buf .String ()
115
118
}
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
+ }
You can’t perform that action at this time.
0 commit comments