Skip to content

Instantly share code, notes, and snippets.

@weaming
Created February 1, 2023 04:34
Show Gist options
  • Save weaming/82adf9c233c076f88f8b09b8f64d5956 to your computer and use it in GitHub Desktop.
Save weaming/82adf9c233c076f88f8b09b8f64d5956 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func one(n int64) {
ids := []int64{}
for i := int64(1); i <= n; i++ {
ids = append(ids, i)
}
chunkSize := len(ids)
if chunkSize > 100 {
chunkSize = len(ids) / 10
}
var lastEnd int64
seen := map[int64]bool{}
for startIndex := 0; startIndex < len(ids); startIndex += chunkSize {
endIndex := startIndex + chunkSize - 1
if endIndex >= len(ids) {
endIndex = len(ids) - 1
}
start, end := ids[startIndex], ids[endIndex]
fmt.Println(start, end)
if lastEnd != 0 && start != lastEnd+1 {
panic("missing")
}
for i := start; i <= end; i++ {
seen[i] = true
}
lastEnd = end
}
if len(ids) != len(seen) {
panic("missing 2")
}
}
func main() {
for i := int64(1); i <= 10000; i++ {
one(i)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment