Skip to content

Commit

Permalink
Merge pull request #226 from Workiva/gha
Browse files Browse the repository at this point in the history
Github Actions
  • Loading branch information
rmconsole2-wf authored Sep 13, 2023
2 parents 68e77ee + 1479081 commit b0c60b5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@Workiva/skreams
38 changes: 38 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Tests"

on:
pull_request:
push:
branches:
- 'master'
tags:
- '*'

permissions:
pull-requests: write
contents: read
id-token: write

jobs:
Tests:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.15', 'stable' ]
name: Tests on Go ${{ matrix.go }}
steps:
- name: Checkout Repo
uses: actions/[email protected]
with:
path: go/src/github.com/Workiva/go-datastructures

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}

- name: Run Tests
timeout-minutes: 10
run: |
cd go/src/github.com/Workiva/go-datastructures
go test ./...
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

17 changes: 15 additions & 2 deletions sort/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

0 comments on commit b0c60b5

Please sign in to comment.