From 78f2633fa2ee61eda9e5889389113e8e90828ec3 Mon Sep 17 00:00:00 2001 From: Karl Gaissmaier Date: Sat, 6 Jan 2024 13:06:42 +0100 Subject: [PATCH] API change and bump go version --- .github/workflows/go.yml | 10 +++++----- README.md | 5 +---- example_period_test.go | 17 +++++------------ helpers.go | 6 +++--- treap_test.go | 2 +- 5 files changed, 15 insertions(+), 25 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f470204..aac5078 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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: @@ -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: @@ -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: @@ -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 diff --git a/README.md b/README.md index cd7d039..5721058 100644 --- a/README.md +++ b/README.md @@ -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 @@ -110,9 +110,6 @@ 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 diff --git a/example_period_test.go b/example_period_test.go index ceab64a..df7a45a 100644 --- a/example_period_test.go +++ b/example_period_test.go @@ -1,6 +1,7 @@ package interval_test import ( + "cmp" "fmt" "os" @@ -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 diff --git a/helpers.go b/helpers.go index af6d14f..0e18744 100644 --- a/helpers.go +++ b/helpers.go @@ -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. @@ -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 diff --git a/treap_test.go b/treap_test.go index b4b33f1..6283b60 100644 --- a/treap_test.go +++ b/treap_test.go @@ -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()