Skip to content

Commit 55f538a

Browse files
authored
Merge branch 'Workiva:master' into basic_heaps
2 parents 8015f0b + 18d7737 commit 55f538a

File tree

5 files changed

+83
-23
lines changed

5 files changed

+83
-23
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@Workiva/skreams

.github/workflows/tests.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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: write
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/checkout@v4
26+
with:
27+
path: go/src/github.com/Workiva/go-datastructures
28+
29+
- name: Setup Go
30+
uses: actions/[email protected]
31+
with:
32+
go-version: ${{ matrix.go }}
33+
34+
# go install does not work because it needs credentials
35+
- name: install go2xunit
36+
run: |
37+
git clone https://github.com/tebeka/go2xunit.git
38+
cd go2xunit
39+
git checkout v1.4.10
40+
go install
41+
cd ..
42+
43+
- name: Run Tests
44+
timeout-minutes: 10
45+
run: |
46+
cd go/src/github.com/Workiva/go-datastructures
47+
go test ./... | tee ${{github.workspace}}/go-test.txt
48+
49+
- name: XML output
50+
run: |
51+
mkdir artifacts
52+
go2xunit -input ./go-test.txt -output ./artifacts/tests_go_version-${{ matrix.go }}.xml
53+
54+
- name: Upload Test Results
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: go-datastructures test go ${{ matrix.go }}
58+
path: ./artifacts/tests_go_version-${{ matrix.go }}.xml
59+
retention-days: 7
60+
61+
- uses: anchore/sbom-action@v0
62+
with:
63+
path: ./
64+
format: cyclonedx-json

.travis.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
go-datastructures
32
=================
43

@@ -150,7 +149,7 @@ interface and the most expensive operation in CPU profiling is the interface
150149
method which in turn calls into runtime.assertI2T. We need generics.
151150

152151
#### Immutable B Tree
153-
A btree based on two principals, immutablability and concurrency.
152+
A btree based on two principles, immutability and concurrency.
154153
Somewhat slow for single value lookups and puts, it is very fast for bulk operations.
155154
A persister can be injected to make this index persistent.
156155

@@ -229,6 +228,6 @@ Requirements to commit here:
229228

230229

231230
### Maintainers
232-
233-
- Dustin Hiatt <[[email protected]](mailto:[email protected])>
234231
- Alexander Campbell <[[email protected]](mailto:[email protected])>
232+
- Dustin Hiatt <[[email protected]](mailto:[email protected])>
233+
- Ryan Jackson <[[email protected]](mailto:[email protected])>

sort/sort.go

Lines changed: 15 additions & 2 deletions
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)