Skip to content

first try #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@Workiva/skreams
37 changes: 37 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -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 ./...
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)
}