From e5c190814194019962f67e3a81efd18bed3a3a85 Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Tue, 12 Sep 2023 11:57:12 -0400 Subject: [PATCH 1/5] Github Actions --- .github/CODEOWNERS | 1 + .github/workflows/tests.yaml | 37 ++++++++++++++++++++++++++++++++++++ .travis.yml | 17 ----------------- sort/sort.go | 17 +++++++++++++++-- 4 files changed, 53 insertions(+), 19 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/tests.yaml delete mode 100644 .travis.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..e9d2163 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +@Workiva/skreams diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..64cffc0 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,37 @@ +name: "Tests" + +on: + pull_request: + push: + branches: + - 'master' + tags: + - '*' + +permissions: + pull-requests: write + contents: read + id-token: write + +env: + GOLANG_VERSION: "1.16" + +jobs: + Tests: + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v3.3.0 + with: + path: go/src/github.com/Workiva/go-datastructures + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GOLANG_VERSION }} + + - name: Run Tests + timeout-minutes: 10 + run: | + cd go/src/github.com/Workiva/go-datastructures + go test ./... diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c4cb4f4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: go - -go: - - tip - -before_install: go get golang.org/x/tools/cmd/cover - -install: -- go mod vendor - -script: go test -race -v -cover ./... - -env: -- GOMAXPROCS=8 GORACE="halt_on_error=1" - -notifications: - email: false diff --git a/sort/sort.go b/sort/sort.go index 3b949d5..0d7ce59 100644 --- a/sort/sort.go +++ b/sort/sort.go @@ -27,8 +27,11 @@ func MultithreadedSortComparators(comparators Comparators) Comparators { var wg sync.WaitGroup numCPU := int64(runtime.NumCPU()) - if numCPU%2 == 1 { // single core machine - numCPU++ + if numCPU == 1 { // single core machine + numCPU = 2 + } else { + // otherwise this algo only works with a power of two + numCPU = int64(prevPowerOfTwo(uint64(numCPU))) } chunks := chunk(toBeSorted, numCPU) @@ -70,3 +73,13 @@ func chunk(comparators Comparators, numParts int64) []Comparators { } return parts } + +func prevPowerOfTwo(x uint64) uint64 { + x = x | (x >> 1) + x = x | (x >> 2) + x = x | (x >> 4) + x = x | (x >> 8) + x = x | (x >> 16) + x = x | (x >> 32) + return x - (x >> 1) +} From 81f596204193bc706ecf5416a70abd0c0bea7f71 Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Wed, 13 Sep 2023 08:53:48 -0400 Subject: [PATCH 2/5] Update CODEOWNERS, matrix go test versions --- .github/CODEOWNERS | 2 +- .github/workflows/tests.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e9d2163..f86d098 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -@Workiva/skreams +/.github/ @Workiva/skreams diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 64cffc0..a33763b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -13,12 +13,12 @@ permissions: contents: read id-token: write -env: - GOLANG_VERSION: "1.16" - jobs: Tests: runs-on: ubuntu-latest + matrix: + go: [ '1.15', 'stable' ] + name: Tests on Go ${{ matrix.go }} steps: - name: Checkout Repo uses: actions/checkout@v3.3.0 @@ -28,7 +28,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ${{ env.GOLANG_VERSION }} + go-version: ${{ matrix.go }} - name: Run Tests timeout-minutes: 10 From 60d75cb45a64f88a4da70b98d1c73bd841e02191 Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Wed, 13 Sep 2023 08:55:55 -0400 Subject: [PATCH 3/5] Forgot to nest matrix in strategy --- .github/workflows/tests.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a33763b..eb00815 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -16,8 +16,9 @@ permissions: jobs: Tests: runs-on: ubuntu-latest - matrix: - go: [ '1.15', 'stable' ] + strategy: + matrix: + go: [ '1.15', 'stable' ] name: Tests on Go ${{ matrix.go }} steps: - name: Checkout Repo From 50b59c90371010e8adee4d50160d04d26416233b Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Wed, 13 Sep 2023 09:00:49 -0400 Subject: [PATCH 4/5] Move CODEOWNERS to root --- .github/CODEOWNERS => CODEOWNERS | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/CODEOWNERS => CODEOWNERS (100%) diff --git a/.github/CODEOWNERS b/CODEOWNERS similarity index 100% rename from .github/CODEOWNERS rename to CODEOWNERS From 1479081895d4a07844e308044bc15d1a148942bc Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Wed, 13 Sep 2023 09:01:52 -0400 Subject: [PATCH 5/5] Move CODEOWNERS back, full repo --- .github/CODEOWNERS | 1 + CODEOWNERS | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 .github/CODEOWNERS delete mode 100644 CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..e9d2163 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +@Workiva/skreams diff --git a/CODEOWNERS b/CODEOWNERS deleted file mode 100644 index f86d098..0000000 --- a/CODEOWNERS +++ /dev/null @@ -1 +0,0 @@ -/.github/ @Workiva/skreams