prometheus/util
Julien 1c449737e1
util/strutil: add Jaro-Winkler similarity implementation (#18405)
* util/strutil: add Jaro-Winkler similarity implementation

This is part of the implementation of prometheus/proposals#74

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>

* util/strutil: optimise JaroWinkler with string-native ASCII path

Replace the generic jaroWinkler[T byte|rune] with two specialised
functions: jaroWinklerString (ASCII path) operates directly on the
string values and avoids the []byte conversion that previously caused
two heap allocations per call; jaroWinklerRunes (Unicode path) is
unchanged in algorithm but split out from the generic.

Both paths replace the repeated float64 divisions in the Jaro formula
with precomputed reciprocals (invL1, invL2).

Result: short ASCII strings drop from 2 allocs/op to 0 allocs/op;
long ASCII drops from 4 allocs/op to 2 allocs/op (bool match arrays
only).

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>

* util/strutil: replace JaroWinkler with JaroWinklerMatcher

Remove the free JaroWinkler function and replace it with a
JaroWinklerMatcher struct. NewJaroWinklerMatcher pre-computes the
ASCII check and rune conversion for the search term once; Score then
runs the comparison against each candidate without repeating that work.

This is the expected usage pattern in Prometheus: one fixed term scored
against many label names or values.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>

* Update util/strutil/jarowinkler.go and util/strutil/jarowinkler_test.go

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Julien <291750+roidelapluie@users.noreply.github.com>
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>

---------

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
Signed-off-by: Julien <291750+roidelapluie@users.noreply.github.com>
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
2026-04-14 16:58:46 +02:00
..
almost Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
annotations annotations: add warning for ineffective sort in range queries 2026-04-09 15:21:11 +02:00
compression Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
convertnhcb convertnhcb: reject NaN bucket boundary in SetBucketCount (#18383) 2026-03-31 14:23:17 +02:00
documentcli chore: fix emptyStringTest issues from gocritic (#18226) 2026-03-04 08:24:50 +01:00
features API: Add a /api/v1/features endpoint 2025-12-09 16:13:14 +01:00
fmtutil Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
fuzzing fuzzing: generate libFuzzer dictionary for FuzzParseExpr 2026-04-08 17:38:23 +02:00
gate Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
httputil chore: fix httpNoBody issues from gocritic 2026-03-02 20:06:30 +01:00
jsonutil Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
junitxml Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
kahansum perf(PromQL): allow inlining kahansum.Inc (#18319) 2026-03-19 15:31:20 +01:00
logging chore(kubernetes): deduplicate warning logs from the API 2026-03-12 08:34:33 +01:00
namevalidationutil Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
netconnlimit Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
notifications Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
osutil Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
pool Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
runtime Update FsType magic list 2026-04-08 11:02:49 +02:00
runutil Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
stats Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
strutil util/strutil: add Jaro-Winkler similarity implementation (#18405) 2026-04-14 16:58:46 +02:00
testrecord tsdb: ST-in-WAL: Counter implementation and benchmarks (#17671) 2026-02-12 13:17:50 -05:00
teststorage chore: enable staticcheck linter and update golangci-lint to 2.10.1 2026-02-18 15:58:16 +00:00
testutil chore: remove util/testutil/synctest now that we use Go>=1.25 2026-03-30 19:48:39 +02:00
testwal post merge conflict fixes 2026-03-12 09:03:08 +00:00
treecache chore(lint): enable wg.Go 2026-02-17 15:21:51 +01:00
zeropool Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00