Files
mostlymatter/vendor/github.com/gigawattio/window/rolling.go
Jesús Espino 8d5be2d657 Document extractor service (#15665)
* Document extractor service

* Fixing vendor modules

* Addressing PR Review comments

* Some small simplifications

* Fixing a linter complain

* simplifying a bit the code using package variables

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-27 15:58:38 +01:00

25 строки
482 B
Go

package window
// Rolling generates a rolling window of size N for a sequence of string tokens.
func Rolling(elements []string, n int) [][]string {
if len(elements) == 0 || len(elements) < n || n <= 0 {
return nil
}
var (
accum = make([][]string, len(elements)+1-n)
j int
)
for i := 0; i < len(elements)+1-n; i++ {
win := make([]string, n)
win[0] = elements[i]
for j = 0; j+1 < n; j++ {
win[j+1] = elements[i+j+1]
}
accum[i] = win
}
return accum
}