From 0e8f14dcc4db15a509dc2ba4b291e2c28fc51ca0 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 24 Nov 2022 12:33:42 +0100 Subject: prog: refactor HeatMap Provide NumMutations method instead of Size. It allows HeatMap to choose number of mutations better (e.g. for completely empty/flat images w/o interesting data). --- prog/mutation.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'prog/mutation.go') diff --git a/prog/mutation.go b/prog/mutation.go index 881403247..96e11516c 100644 --- a/prog/mutation.go +++ b/prog/mutation.go @@ -401,11 +401,9 @@ func (r *randGen) mutateImage(image []byte) (data []byte, retry bool) { if len(data) == 0 { return image, true // Do not mutate empty data. } - hm := MakeGenericHeatmap(data) - // At least two mutations, up to about one mutation every 128 KB of heatmap size. - numMutations := r.Intn(hm.Size()/(1<<17)+1) + 2 - for i := 0; i < numMutations; i++ { - index := hm.ChooseLocation(r.Rand) + hm := MakeGenericHeatmap(data, r.Rand) + for i := hm.NumMutations(); i > 0; i-- { + index := hm.ChooseLocation() width := 1 << uint(r.Intn(4)) if index+width > len(data) { width = 1 -- cgit mrf-deployment