Skip to content

Commit 7902988

Browse files
committed
API change and bump go version
1 parent 8a280f4 commit 7902988

File tree

5 files changed

+15
-33
lines changed

5 files changed

+15
-33
lines changed

.github/workflows/go.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
test:
1313
strategy:
1414
matrix:
15-
go-version: ['1.20']
15+
go-version: ['1.21']
1616
os: [ubuntu-latest, macos-latest, windows-latest]
1717
runs-on: ${{ matrix.os }}
1818
steps:
@@ -27,7 +27,7 @@ jobs:
2727
steps:
2828
- uses: golang/govulncheck-action@v1
2929
with:
30-
go-version-input: 1.20
30+
go-version-input: 1.21
3131
check-latest: true
3232

3333
coverage:
@@ -36,10 +36,10 @@ jobs:
3636
- uses: actions/checkout@v3
3737
- uses: actions/setup-go@v4
3838
with:
39-
go-version: 1.20
39+
go-version: 1.21
4040

4141
- name: Test Coverage
42-
run: go test -v -coverprofile=profile.cov ./...
42+
run: go test -coverprofile=profile.cov ./...
4343

4444
- uses: shogo82148/actions-goveralls@v1
4545
with:
@@ -51,7 +51,7 @@ jobs:
5151
- uses: actions/checkout@v3
5252
- uses: actions/setup-go@v4
5353
with:
54-
go-version: 1.20
54+
go-version: 1.21
5555

5656
- name: golangci-lint
5757
uses: golangci/golangci-lint-action@v3

README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## API CHANGE !!!
1010

11-
The API has changed from v0.1.0 to v0.2.0
11+
The API has changed from v0.9.1 to v0.10.0
1212

1313
## Overview
1414

@@ -104,15 +104,6 @@ The benchmark for `Insert()` shows the values for inserting an item into trees w
104104

105105
The trees are randomly generated, as is the item to be inserted.
106106

107-
The trees are immutable, insertions and deletions generate new nodes on the path. The expected depth
108-
of the trees is **O(log(n))** and the **allocs/op** represent this well.
109-
110-
The data structure is a randomized BST, the expected depth is determined with very
111-
high probability (for large n) but not deterministic.
112-
113-
If the original tree is allowed to mutate during insert and delete because the old state is no longer needed,
114-
then the values are correspondingly better.
115-
116107
```
117108
$ go test -benchmem -bench='Insert'
118109
goos: linux
@@ -131,8 +122,6 @@ BenchmarkInsert/Into1_000_000-8 645523 1863 ns/op 64 B/o
131122

132123
### Delete
133124

134-
The benchmark for `Delete()` shows the same asymptotic behavior:
135-
136125
```
137126
$ go test -benchmem -bench='Delete'
138127
goos: linux

example_period_test.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package interval_test
22

33
import (
4+
"cmp"
45
"fmt"
56
"os"
67

@@ -12,18 +13,10 @@ type uintInterval [2]uint
1213

1314
// cmp function for uintInterval
1415
func cmpUintInterval(p, q uintInterval) (ll, rr, lr, rl int) {
15-
return cmpUint(p[0], q[0]), cmpUint(p[1], q[1]), cmpUint(p[0], q[1]), cmpUint(p[1], q[0])
16-
}
17-
18-
// little helper
19-
func cmpUint(a, b uint) int {
20-
switch {
21-
case a == b:
22-
return 0
23-
case a < b:
24-
return -1
25-
}
26-
return 1
16+
return cmp.Compare(p[0], q[0]),
17+
cmp.Compare(p[1], q[1]),
18+
cmp.Compare(p[0], q[1]),
19+
cmp.Compare(p[1], q[0])
2720
}
2821

2922
// example data

helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func (t Tree[T]) Statistics() (size int, maxDepth int, average, deviation float6
327327
variance = variance / float64(sum)
328328
deviation = math.Sqrt(variance)
329329

330-
return size, maxDepth, average, deviation
330+
return size, maxDepth, math.Round(average*10000) / 10000, math.Round(deviation*10000) / 10000
331331
}
332332

333333
// Min returns the min item in tree.
@@ -392,9 +392,9 @@ func (t Tree[T]) Visit(start, stop T, visitFn func(item T) bool) {
392392

393393
// Clone, deep cloning of the tree structure.
394394
func (t Tree[T]) Clone() *Tree[T] {
395-
c := NewTree[T](t.cmp)
395+
c := t
396396
c.root = t.clone(t.root)
397-
return c
397+
return &c
398398
}
399399

400400
// clone rec-descent

treap_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func TestMutable(t *testing.T) {
282282
clone := tree1.Clone()
283283

284284
if !equalStatistics(tree1, clone) {
285-
t.Fatalf("Clone, something wrong, statistics differs")
285+
t.Error("Clone, something wrong, statistics differs")
286286
}
287287

288288
min := tree1.Min()

0 commit comments

Comments
 (0)