From 04f45ca1883161536d92c9600553b0611f0d21ff Mon Sep 17 00:00:00 2001 From: Nick White Date: Thu, 20 Feb 2020 11:41:24 +0000 Subject: [pare-gt] Fix sampling formula, make robust in the face of a 100% sample request, and fix up test output --- pare-gt/main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pare-gt/main.go') diff --git a/pare-gt/main.go b/pare-gt/main.go index 0a8b067..5e2daa1 100644 --- a/pare-gt/main.go +++ b/pare-gt/main.go @@ -74,7 +74,7 @@ func samplePrefixes(perctosample int, prefixes Prefixes) (filestomove []string) keys = append(keys, i) } - sample = total / perctosample + sample = (total * perctosample ) / 100 // This ensures the map is looped over deterministically sort.Strings(keys) @@ -85,6 +85,9 @@ func samplePrefixes(perctosample int, prefixes Prefixes) (filestomove []string) continue } numtoget := int(float64(sample) / float64(total) * float64(len)) + if numtoget >= len { + numtoget = len - 1 + } if numtoget < 1 { numtoget = 1 } -- cgit v1.2.1-24-ge1ad