Implements option to generate prefix-free hints

- Declares --prefix-free CLI flag in main.py.
- Implements dynamic index offset shifting in marks.go to prevent
  generating hints that prefix other hints.
- Integrates prefix-free encoding in main.go.
- Includes tests.

Implements #10195
This commit is contained in:
Hector Tellez
2026-07-01 00:38:32 -07:00
parent f6d1b11b29
commit 5d1215b11d
5 changed files with 226 additions and 5 deletions

View File

@@ -706,13 +706,28 @@ process_answer:
}
largest_index := ans[len(ans)-1].Index
offset := max(0, opts.HintsOffset)
if opts.PrefixFree {
alphabetLength := len(opts.Alphabet)
if alphabetLength == 0 {
alphabetLength = len(DEFAULT_HINT_ALPHABET)
}
offset = max(offset, hints_to_skip(len(ans), alphabetLength))
}
index_map = make(map[int]*Mark, len(ans))
for i := range ans {
m := &ans[i]
if opts.Ascending {
m.Index += offset
if opts.PrefixFree {
if opts.Ascending {
m.Index = i + offset + 1
} else {
m.Index = (largest_index - m.Index) + offset + 1
}
} else {
m.Index = largest_index - m.Index + offset
if opts.Ascending {
m.Index += offset
} else {
m.Index = largest_index - m.Index + offset
}
}
index_map[m.Index] = m
}