Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add implementation of ChunkUInts, ChunkUInt32s, ChunkUInt64s #154

Merged
merged 1 commit into from Dec 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 57 additions & 0 deletions typesafe.go
Expand Up @@ -1123,6 +1123,63 @@ func ChunkInt64s(arr []int64, size int) [][]int64 {
return results
}

// ChunkUInts creates an array of uints split into groups with the length of size.
// If array can't be split evenly, the final chunk will be
// the remaining element.
func ChunkUInts(arr []uint, size int) [][]uint {
var results [][]uint

for i := 0; i < len(arr); i += size {
end := i + size

if end > len(arr) {
end = len(arr)
}

results = append(results, arr[i:end])
}

return results
}

// ChunkUInt32s creates an array of uint32s split into groups with the length of size.
// If array can't be split evenly, the final chunk will be
// the remaining element.
func ChunkUInt32s(arr []uint32, size int) [][]uint32 {
var results [][]uint32

for i := 0; i < len(arr); i += size {
end := i + size

if end > len(arr) {
end = len(arr)
}

results = append(results, arr[i:end])
}

return results
}

// ChunkUInt64s creates an array of uint64s split into groups with the length of size.
// If array can't be split evenly, the final chunk will be
// the remaining element.
func ChunkUInt64s(arr []uint64, size int) [][]uint64 {
var results [][]uint64

for i := 0; i < len(arr); i += size {
end := i + size

if end > len(arr) {
end = len(arr)
}

results = append(results, arr[i:end])
}

return results
}

// ChunkFloat64s creates an array of float64s split into groups with the length of size.
// If array can't be split evenly, the final chunk will be
// the remaining element.
Expand Down