Skip to content

Commit c08900c

Browse files
committed
add: GetIndex func
1 parent 28a2c07 commit c08900c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

chunk.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package chunk
2+
3+
// Index - index
4+
type Index struct {
5+
From, To int
6+
}
7+
8+
// GetIndex - returns index of specified size length
9+
func GetIndex(length int, chunkSize int) <-chan Index {
10+
ch := make(chan Index)
11+
12+
go func() {
13+
defer close(ch)
14+
15+
for i := 0; i < length; i += chunkSize {
16+
idx := Index{i, i + chunkSize}
17+
if length < idx.To {
18+
idx.To = length
19+
}
20+
ch <- idx
21+
}
22+
}()
23+
24+
return ch
25+
}

0 commit comments

Comments
 (0)