Files
SnowLuma/.pnpm-store/v11/files/0e/1eadca5daac45b9f0f2c605295ee485d37a3de88e5edb32063a78adf6f7b0113e5472e2375df6daa75c20b11a7b9f0c78ad3da9921ea1649da653fb9a4ef67
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

24 lines
792 B
Plaintext

import {
BRUTEFORCE_CARDINALITY,
MIN_SUBMATCH_GUESSES_SINGLE_CHAR,
MIN_SUBMATCH_GUESSES_MULTI_CHAR,
} from '../../data/const'
import { MatchEstimated, MatchExtended } from '../../types'
export default ({ token }: MatchExtended | MatchEstimated) => {
let guesses = BRUTEFORCE_CARDINALITY ** token.length
if (guesses === Number.POSITIVE_INFINITY) {
guesses = Number.MAX_VALUE
}
let minGuesses
// small detail: make bruteforce matches at minimum one guess bigger than smallest allowed
// submatch guesses, such that non-bruteforce submatches over the same [i..j] take precedence.
if (token.length === 1) {
minGuesses = MIN_SUBMATCH_GUESSES_SINGLE_CHAR + 1
} else {
minGuesses = MIN_SUBMATCH_GUESSES_MULTI_CHAR + 1
}
return Math.max(guesses, minGuesses)
}