Skip to content

Commit b0c60b5

Browse files
Merge pull request #226 from Workiva/gha
Github Actions
2 parents 68e77ee + 1479081 commit b0c60b5

File tree

4 files changed

+54
-19
lines changed

4 files changed

+54
-19
lines changed

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@Workiva/skreams

.github/workflows/tests.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Tests"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- 'master'
8+
tags:
9+
- '*'
10+
11+
permissions:
12+
pull-requests: write
13+
contents: read
14+
id-token: write
15+
16+
jobs:
17+
Tests:
18+
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
go: [ '1.15', 'stable' ]
22+
name: Tests on Go ${{ matrix.go }}
23+
steps:
24+
- name: Checkout Repo
25+
uses: actions/[email protected]
26+
with:
27+
path: go/src/github.com/Workiva/go-datastructures
28+
29+
- name: Setup Go
30+
uses: actions/setup-go@v4
31+
with:
32+
go-version: ${{ matrix.go }}
33+
34+
- name: Run Tests
35+
timeout-minutes: 10
36+
run: |
37+
cd go/src/github.com/Workiva/go-datastructures
38+
go test ./...

.travis.yml

-17
This file was deleted.

sort/sort.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ func MultithreadedSortComparators(comparators Comparators) Comparators {
2727
var wg sync.WaitGroup
2828

2929
numCPU := int64(runtime.NumCPU())
30-
if numCPU%2 == 1 { // single core machine
31-
numCPU++
30+
if numCPU == 1 { // single core machine
31+
numCPU = 2
32+
} else {
33+
// otherwise this algo only works with a power of two
34+
numCPU = int64(prevPowerOfTwo(uint64(numCPU)))
3235
}
3336

3437
chunks := chunk(toBeSorted, numCPU)
@@ -70,3 +73,13 @@ func chunk(comparators Comparators, numParts int64) []Comparators {
7073
}
7174
return parts
7275
}
76+
77+
func prevPowerOfTwo(x uint64) uint64 {
78+
x = x | (x >> 1)
79+
x = x | (x >> 2)
80+
x = x | (x >> 4)
81+
x = x | (x >> 8)
82+
x = x | (x >> 16)
83+
x = x | (x >> 32)
84+
return x - (x >> 1)
85+
}

0 commit comments

Comments
 (0)