summaryrefslogtreecommitdiff
path: root/pare-gt/main.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2020-02-20 11:41:24 +0000
committerNick White <git@njw.name>2020-02-20 11:41:24 +0000
commit04f45ca1883161536d92c9600553b0611f0d21ff (patch)
tree4c41fb349f1ae43125259aae837de1673c82624f /pare-gt/main.go
parent62512ca0abb651780a01ba535bdc31f6930d4300 (diff)
[pare-gt] Fix sampling formula, make robust in the face of a 100% sample request, and fix up test output
Diffstat (limited to 'pare-gt/main.go')
-rw-r--r--pare-gt/main.go5
1 files changed, 4 insertions, 1 deletions
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
}