Skip to content

Commit e5c1908

Browse files
Github Actions
1 parent 68e77ee commit e5c1908

File tree

4 files changed

+53
-19
lines changed

4 files changed

+53
-19
lines changed

.github/CODEOWNERS

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

.github/workflows/tests.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
env:
17+
GOLANG_VERSION: "1.16"
18+
19+
jobs:
20+
Tests:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout Repo
24+
uses: actions/checkout@v3.3.0
25+
with:
26+
path: go/src/github.com/Workiva/go-datastructures
27+
28+
- name: Setup Go
29+
uses: actions/setup-go@v4
30+
with:
31+
go-version: ${{ env.GOLANG_VERSION }}
32+
33+
- name: Run Tests
34+
timeout-minutes: 10
35+
run: |
36+
cd go/src/github.com/Workiva/go-datastructures
37+
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)