pax_global_header00006660000000000000000000000064136225627370014527gustar00rootroot0000000000000052 comment=260131d1c2fa3fa1c0bcd2a233409bc5a814f2f3 golang-github-gigawattio-window-0.0~git20180317.0f5467e/000077500000000000000000000000001362256273700223065ustar00rootroot00000000000000golang-github-gigawattio-window-0.0~git20180317.0f5467e/.gitignore000066400000000000000000000012341362256273700242760ustar00rootroot00000000000000## # Vim swap/working files. *.sw[opa] ## # SublimeText files. *.sublime-project *.sublime-workspace ## # IDEA IntelliJ files. *.idea *.iml ## # Visual Studio Code files. .vscode ## # Mac OS-X miscellany. .DS_Store .AppleDouble .LSOverride ._* ## # Windows image file caches Thumbs.db ehthumbs.db # Folder config file Desktop.ini ## # Compiled Object files, Static and Dynamic libs (Shared Objects). *.o *.a *.so ## # Folders. _obj _test ## # Architecture specific extensions/prefixes. *.[568vq] [568vq].out *.cgo1.go *.cgo2.c _cgo_defun.c _cgo_gotypes.go _cgo_export.* _testmain.go *.exe *.test *.prof ## # Certificate files. id_[rd]sa *.pem *.crt *.key golang-github-gigawattio-window-0.0~git20180317.0f5467e/.travis.yml000066400000000000000000000002371362256273700244210ustar00rootroot00000000000000language: go go: - tip - "1.10" - 1.9 - 1.8 - 1.7 script: - go test ./... notifications: email: on_success: change on_failure: always golang-github-gigawattio-window-0.0~git20180317.0f5467e/LICENSE000066400000000000000000000020531362256273700233130ustar00rootroot00000000000000MIT License Copyright (c) 2018 GigawattIO Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. golang-github-gigawattio-window-0.0~git20180317.0f5467e/README.md000066400000000000000000000014241362256273700235660ustar00rootroot00000000000000# window [![Documentation](https://godoc.org/github.com/gigawattio/window?status.svg)](https://godoc.org/github.com/gigawattio/window) [![Build Status](https://travis-ci.org/gigawattio/window.svg?branch=master)](https://travis-ci.org/gigawattio/window) [![Report Card](https://goreportcard.com/badge/github.com/gigawattio/window)](https://goreportcard.com/report/github.com/gigawattio/window) ### About Window is a golang package for generating a rolling window of size N for a sequence of string tokens. Created by [Jay Taylor](https://jaytaylor.com/) and used by [Gigawatt](https://gigawatt.io/). ### Requirements * Go version 1.7 or newer ### Running the test suite go test ./... #### License Permissive MIT license, see the [LICENSE](LICENSE) file for more information. golang-github-gigawattio-window-0.0~git20180317.0f5467e/rolling.go000066400000000000000000000007421362256273700243060ustar00rootroot00000000000000package 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 } golang-github-gigawattio-window-0.0~git20180317.0f5467e/rolling_test.go000066400000000000000000000030501362256273700253400ustar00rootroot00000000000000package window import ( "reflect" "testing" ) func TestRolling(t *testing.T) { testCases := []struct { elements []string n int expected [][]string }{ { elements: nil, n: 0, expected: nil, }, { elements: []string{}, n: 0, expected: nil, }, { elements: []string{"bail", "early"}, n: -1, expected: nil, }, { elements: []string{"foo", "bar", "baz"}, n: 0, expected: nil, }, { elements: []string{"foo", "bar", "baz"}, n: 1, expected: [][]string{ []string{"foo"}, []string{"bar"}, []string{"baz"}, }, }, { elements: []string{"foo", "bar", "baz"}, n: 1, expected: [][]string{ []string{"foo"}, []string{"bar"}, []string{"baz"}, }, }, { elements: []string{"foo", "bar", "baz"}, n: 2, expected: [][]string{ []string{"foo", "bar"}, []string{"bar", "baz"}, }, }, { elements: []string{"foo", "bar", "baz"}, n: 3, expected: [][]string{ []string{"foo", "bar", "baz"}, }, }, { elements: []string{"foo", "bar", "baz", "boo"}, n: 2, expected: [][]string{ []string{"foo", "bar"}, []string{"bar", "baz"}, []string{"baz", "boo"}, }, }, } for i, testCase := range testCases { actual := Rolling(testCase.elements, testCase.n) if !reflect.DeepEqual(actual, testCase.expected) { t.Errorf("[i=%v] Actual rolling window result did not match expected value\n\tExpected: %+v\n\t Actual: %+v", i, testCase.expected, actual) } } }