Skip to content

Commit

Permalink
API change and bump go version
Browse files Browse the repository at this point in the history
  • Loading branch information
gaissmai committed Jan 6, 2024
1 parent 8a280f4 commit 7902988
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 33 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
test:
strategy:
matrix:
go-version: ['1.20']
go-version: ['1.21']
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -27,7 +27,7 @@ jobs:
steps:
- uses: golang/govulncheck-action@v1
with:
go-version-input: 1.20
go-version-input: 1.21
check-latest: true

coverage:
Expand All @@ -36,10 +36,10 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: 1.20
go-version: 1.21

- name: Test Coverage
run: go test -v -coverprofile=profile.cov ./...
run: go test -coverprofile=profile.cov ./...

- uses: shogo82148/actions-goveralls@v1
with:
Expand All @@ -51,7 +51,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: 1.20
go-version: 1.21

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## API CHANGE !!!

The API has changed from v0.1.0 to v0.2.0
The API has changed from v0.9.1 to v0.10.0

## Overview

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

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

The trees are immutable, insertions and deletions generate new nodes on the path. The expected depth
of the trees is **O(log(n))** and the **allocs/op** represent this well.

The data structure is a randomized BST, the expected depth is determined with very
high probability (for large n) but not deterministic.

If the original tree is allowed to mutate during insert and delete because the old state is no longer needed,
then the values are correspondingly better.

```
$ go test -benchmem -bench='Insert'
goos: linux
Expand All @@ -131,8 +122,6 @@ BenchmarkInsert/Into1_000_000-8 645523 1863 ns/op 64 B/o

### Delete

The benchmark for `Delete()` shows the same asymptotic behavior:

```
$ go test -benchmem -bench='Delete'
goos: linux
Expand Down
17 changes: 5 additions & 12 deletions example_period_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package interval_test

import (
"cmp"
"fmt"
"os"

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

// cmp function for uintInterval
func cmpUintInterval(p, q uintInterval) (ll, rr, lr, rl int) {
return cmpUint(p[0], q[0]), cmpUint(p[1], q[1]), cmpUint(p[0], q[1]), cmpUint(p[1], q[0])
}

// little helper
func cmpUint(a, b uint) int {
switch {
case a == b:
return 0
case a < b:
return -1
}
return 1
return cmp.Compare(p[0], q[0]),
cmp.Compare(p[1], q[1]),
cmp.Compare(p[0], q[1]),
cmp.Compare(p[1], q[0])
}

// example data
Expand Down
6 changes: 3 additions & 3 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (t Tree[T]) Statistics() (size int, maxDepth int, average, deviation float6
variance = variance / float64(sum)
deviation = math.Sqrt(variance)

return size, maxDepth, average, deviation
return size, maxDepth, math.Round(average*10000) / 10000, math.Round(deviation*10000) / 10000
}

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

// Clone, deep cloning of the tree structure.
func (t Tree[T]) Clone() *Tree[T] {
c := NewTree[T](t.cmp)
c := t
c.root = t.clone(t.root)
return c
return &c
}

// clone rec-descent
Expand Down
2 changes: 1 addition & 1 deletion treap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func TestMutable(t *testing.T) {
clone := tree1.Clone()

if !equalStatistics(tree1, clone) {
t.Fatalf("Clone, something wrong, statistics differs")
t.Error("Clone, something wrong, statistics differs")
}

min := tree1.Min()
Expand Down

0 comments on commit 7902988

Please sign in to comment.