Skip to content

Commit 8a280f4

Browse files
committed
typo in README.md
1 parent 53da190 commit 8a280f4

File tree

7 files changed

+273
-280
lines changed

7 files changed

+273
-280
lines changed

.github/workflows/go.yml

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,59 @@
11
name: CI
2-
32
on:
43
push:
5-
branches: [master]
4+
branches: ["main", "master", "devel"]
65
paths:
7-
- '**.go'
8-
- '**.yml'
9-
6+
- '**.go'
7+
- '**.yml'
108
pull_request:
11-
workflow_dispatch:
12-
13-
jobs:
9+
branches: ["main"]
1410

15-
build:
11+
jobs:
12+
test:
13+
strategy:
14+
matrix:
15+
go-version: ['1.20']
16+
os: [ubuntu-latest, macos-latest, windows-latest]
17+
runs-on: ${{ matrix.os }}
18+
steps:
19+
- uses: actions/setup-go@v4
20+
with:
21+
go-version: ${{ matrix.go-version }}
22+
- uses: actions/checkout@v3
23+
- run: go test -v ./...
24+
25+
govulncheck:
1626
runs-on: ubuntu-latest
1727
steps:
18-
- uses: actions/checkout@v3
19-
20-
- name: Set up Go
21-
uses: actions/setup-go@v3
22-
with:
23-
go-version: 1.18
24-
check-latest: true
28+
- uses: golang/govulncheck-action@v1
29+
with:
30+
go-version-input: 1.20
31+
check-latest: true
32+
33+
coverage:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v3
37+
- uses: actions/setup-go@v4
38+
with:
39+
go-version: 1.20
2540

26-
- name: Build
27-
run: go build -v ./...
41+
- name: Test Coverage
42+
run: go test -v -coverprofile=profile.cov ./...
2843

29-
- name: Test Coverage
30-
run: go test -v -coverprofile=profile.cov ./...
44+
- uses: shogo82148/actions-goveralls@v1
45+
with:
46+
path-to-profile: profile.cov
3147

32-
- uses: shogo82148/actions-goveralls@v1
33-
with:
34-
path-to-profile: profile.cov
35-
36-
- name: golangci-lint
37-
uses: golangci/golangci-lint-action@v3
38-
with:
39-
version: latest
48+
linting:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v3
52+
- uses: actions/setup-go@v4
53+
with:
54+
go-version: 1.20
55+
56+
- name: golangci-lint
57+
uses: golangci/golangci-lint-action@v3
58+
with:
59+
version: latest

README.md

Lines changed: 33 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,16 @@
66
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)
77
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
88

9+
## API CHANGE !!!
10+
11+
The API has changed from v0.1.0 to v0.2.0
12+
913
## Overview
1014

1115
`package interval` is an immutable datastructure for fast lookups in one dimensional intervals.
1216

1317
The implementation is based on treaps, augmented for intervals. Treaps are randomized self balancing binary search trees.
1418

15-
Immutability is achieved because insert/delete will return a new treap which will share some nodes with the original treap.
16-
All nodes are read-only after creation, allowing concurrent readers to operate safely with concurrent writers.
17-
18-
The time complexity is **O(log(n))** or **O(k+log(n))** where k is the number of returned items, the space complexity is **O(n)**.
19-
20-
```
21-
Insert() O(log(n))
22-
Delete() O(log(n))
23-
Find() O(log(n))
24-
Intersects() O(log(n))
25-
CoverLCP() O(log(n))
26-
CoverSCP() O(log(n))
27-
28-
Covers() O(k+log(n))
29-
CoveredBy() O(k+log(n))
30-
Precedes() O(k+log(n))
31-
PrecededBy() O(k+log(n))
32-
Intersections() O(k+log(n))
33-
```
34-
3519
The author is propably the first (in december 2022) using augmented treaps
3620
as a very promising [data structure] for the representation of dynamic IP address tables
3721
for arbitrary ranges, that enables most and least specific range matching and even more lookup methods
@@ -79,15 +63,18 @@ To apply this library to types of one-dimensional intervals, you must provide a
7963
import "github.com/gaissmai/interval"
8064

8165
type Tree[T any] struct{ ... }
82-
func NewTree[T any](cmp func(a, b T) (ll, rr, lr, rl int), items ...T) Tree[T]
66+
func NewTree[T any](cmp func(a, b T) (ll, rr, lr, rl int), items ...T) *Tree[T]
8367

84-
func NewTreeConcurrent[T any](jobs int, cmp func(a, b T) (ll, rr, lr, rl int), items ...T) Tree[T]
68+
func NewTreeConcurrent[T any](jobs int, cmp func(a, b T) (ll, rr, lr, rl int), items ...T) *Tree[T]
8569

86-
func (t Tree[T]) Insert(items ...T) Tree[T]
87-
func (t Tree[T]) Delete(item T) (Tree[T], bool)
70+
func (t *Tree[T]) Insert(items ...T)
71+
func (t *Tree[T]) Delete(item T) bool
72+
func (t *Tree[T]) Union(other *Tree[T], overwrite bool)
8873

89-
func (t *Tree[T]) InsertMutable(items ...T)
90-
func (t *Tree[T]) DeleteMutable(item T) bool
74+
func (t Tree[T]) InsertImmutable(items ...T) *Tree[T]
75+
func (t Tree[T]) DeleteImmutable(item T) (*Tree[T], bool)
76+
func (t Tree[T]) UnionImmutable(other *Tree[T], overwrite bool) *Tree[T]
77+
func (t Tree[T]) Clone() *Tree[T]
9178

9279
func (t Tree[T]) Find(item T) (result T, ok bool)
9380
func (t Tree[T]) CoverLCP(item T) (result T, ok bool)
@@ -102,9 +89,6 @@ To apply this library to types of one-dimensional intervals, you must provide a
10289

10390
func (t Tree[T]) Intersections(item T) []T
10491

105-
func (t Tree[T]) Clone() Tree[T]
106-
func (t Tree[T]) Union(other Tree[T], overwrite bool, immutable bool) Tree[T]
107-
10892
func (t Tree[T]) Visit(start, stop T, visitFn func(item T) bool)
10993
func (t Tree[T]) Fprint(w io.Writer) error
11094
func (t Tree[T]) String() string
@@ -135,21 +119,14 @@ goos: linux
135119
goarch: amd64
136120
pkg: github.com/gaissmai/interval
137121
cpu: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
138-
BenchmarkInsert/Into1-8 7488871 189 ns/op 128 B/op 2 allocs/op
139-
BenchmarkInsert/Into10-8 3276116 398 ns/op 256 B/op 4 allocs/op
140-
BenchmarkInsert/Into100-8 1496136 951 ns/op 512 B/op 8 allocs/op
141-
BenchmarkInsert/Into1_000-8 533299 1959 ns/op 960 B/op 15 allocs/op
142-
BenchmarkInsert/Into10_000-8 727627 1398 ns/op 832 B/op 13 allocs/op
143-
BenchmarkInsert/Into100_000-8 342596 3339 ns/op 1600 B/op 25 allocs/op
144-
BenchmarkInsert/Into1_000_000-8 396890 3681 ns/op 1728 B/op 27 allocs/op
145-
146-
BenchmarkInsertMutable/Into1-8 10415164 128 ns/op 64 B/op 1 allocs/op
147-
BenchmarkInsertMutable/Into10-8 5160836 245 ns/op 64 B/op 1 allocs/op
148-
BenchmarkInsertMutable/Into100-8 2707705 443 ns/op 64 B/op 1 allocs/op
149-
BenchmarkInsertMutable/Into1_000-8 1694250 723 ns/op 64 B/op 1 allocs/op
150-
BenchmarkInsertMutable/Into10_000-8 1204220 963 ns/op 64 B/op 1 allocs/op
151-
BenchmarkInsertMutable/Into100_000-8 966566 1249 ns/op 64 B/op 1 allocs/op
152-
BenchmarkInsertMutable/Into1_000_000-8 645523 1863 ns/op 64 B/op 1 allocs/op
122+
123+
BenchmarkInsert/Into1-8 10415164 128 ns/op 64 B/op 1 allocs/op
124+
BenchmarkInsert/Into10-8 5160836 245 ns/op 64 B/op 1 allocs/op
125+
BenchmarkInsert/Into100-8 2707705 443 ns/op 64 B/op 1 allocs/op
126+
BenchmarkInsert/Into1_000-8 1694250 723 ns/op 64 B/op 1 allocs/op
127+
BenchmarkInsert/Into10_000-8 1204220 963 ns/op 64 B/op 1 allocs/op
128+
BenchmarkInsert/Into100_000-8 966566 1249 ns/op 64 B/op 1 allocs/op
129+
BenchmarkInsert/Into1_000_000-8 645523 1863 ns/op 64 B/op 1 allocs/op
153130
```
154131

155132
### Delete
@@ -162,31 +139,27 @@ goos: linux
162139
goarch: amd64
163140
pkg: github.com/gaissmai/interval
164141
cpu: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
165-
BenchmarkDelete/DeleteFrom10-8 8018518 150 ns/op 128 B/op 2 allocs/op
166-
BenchmarkDelete/DeleteFrom100-8 2349710 708 ns/op 448 B/op 7 allocs/op
167-
BenchmarkDelete/DeleteFrom1_000-8 616173 2051 ns/op 1536 B/op 24 allocs/op
168-
BenchmarkDelete/DeleteFrom10_000-8 446180 2362 ns/op 1856 B/op 29 allocs/op
169-
BenchmarkDelete/DeleteFrom100_000-8 272798 4224 ns/op 2816 B/op 44 allocs/op
170-
BenchmarkDelete/DeleteFrom1_000_000-8 231808 5897 ns/op 3520 B/op 55 allocs/op
171-
172-
BenchmarkDeleteMutable/DeleteFrom10-8 7682869 156 ns/op 0 B/op 0 allocs/op
173-
BenchmarkDeleteMutable/DeleteFrom100-8 13009023 92 ns/op 0 B/op 0 allocs/op
174-
BenchmarkDeleteMutable/DeleteFrom1_000-8 1912417 627 ns/op 0 B/op 0 allocs/op
175-
BenchmarkDeleteMutable/DeleteFrom10_000-8 1362752 889 ns/op 0 B/op 0 allocs/op
176-
BenchmarkDeleteMutable/DeleteFrom100_000-8 893157 1334 ns/op 0 B/op 0 allocs/op
177-
BenchmarkDeleteMutable/DeleteFrom1_000_000-8 647199 1828 ns/op 0 B/op 0 allocs/op
142+
143+
BenchmarkDelete/DeleteFrom10-8 7682869 156 ns/op 0 B/op 0 allocs/op
144+
BenchmarkDelete/DeleteFrom100-8 13009023 92 ns/op 0 B/op 0 allocs/op
145+
BenchmarkDelete/DeleteFrom1_000-8 1912417 627 ns/op 0 B/op 0 allocs/op
146+
BenchmarkDelete/DeleteFrom10_000-8 1362752 889 ns/op 0 B/op 0 allocs/op
147+
BenchmarkDelete/DeleteFrom100_000-8 893157 1334 ns/op 0 B/op 0 allocs/op
148+
BenchmarkDelete/DeleteFrom1_000_000-8 647199 1828 ns/op 0 B/op 0 allocs/op
178149
```
179150

180151
### Lookups
181152

182-
The benchmark for `CoverLCP()` (a.k.a. longest-prefix-match if the interval is an IP CIDR prefix) is very promising:
153+
The benchmark for `CoverLCP()` (also known as longest-prefix-match when the interval is an IP-CIDR prefix) is very
154+
promising, as it is a generalized algorithm that is not specifically optimized only for IP address lookup:
183155

184156
```
185157
$ go test -benchmem -bench='CoverLCP'
186158
goos: linux
187159
goarch: amd64
188160
pkg: github.com/gaissmai/interval
189161
cpu: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
162+
190163
BenchmarkCoverLCP/In100-8 4833073 239 ns/op 0 B/op 0 allocs/op
191164
BenchmarkCoverLCP/In1_000-8 3714054 323 ns/op 0 B/op 0 allocs/op
192165
BenchmarkCoverLCP/In10_000-8 1897353 630 ns/op 0 B/op 0 allocs/op
@@ -203,6 +176,7 @@ goos: linux
203176
goarch: amd64
204177
pkg: github.com/gaissmai/interval
205178
cpu: Intel(R) Core(TM) i5-7500T CPU @ 2.70GHz
179+
206180
BenchmarkIntersects/In1-4 58757540 19 ns/op 0 B/op 0 allocs/op
207181
BenchmarkIntersects/In10-4 27267051 40 ns/op 0 B/op 0 allocs/op
208182
BenchmarkIntersects/In100-4 17559418 60 ns/op 0 B/op 0 allocs/op
@@ -220,6 +194,7 @@ goos: linux
220194
goarch: amd64
221195
pkg: github.com/gaissmai/interval
222196
cpu: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
197+
223198
BenchmarkFind/In100-8 17299449 63 ns/op 0 B/op 0 allocs/op
224199
BenchmarkFind/In1_000-8 17327350 69 ns/op 0 B/op 0 allocs/op
225200
BenchmarkFind/In10_000-8 12858908 90 ns/op 0 B/op 0 allocs/op

bench_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var intMap = map[int]string{
1717
1_000_000: "1_000_000",
1818
}
1919

20-
func BenchmarkInsert(b *testing.B) {
20+
func BenchmarkInsertImmutable(b *testing.B) {
2121
for n := 1; n <= 1_000_000; n *= 10 {
2222
tree := interval.NewTree(cmpUintInterval, genUintIvals(n)...)
2323

@@ -27,13 +27,13 @@ func BenchmarkInsert(b *testing.B) {
2727
b.Run(name, func(b *testing.B) {
2828
b.ResetTimer()
2929
for n := 0; n < b.N; n++ {
30-
_ = tree.Insert(probe)
30+
_ = tree.InsertImmutable(probe)
3131
}
3232
})
3333
}
3434
}
3535

36-
func BenchmarkInsertMutable(b *testing.B) {
36+
func BenchmarkInsert(b *testing.B) {
3737
for n := 1; n <= 1_000_000; n *= 10 {
3838
tree := interval.NewTree(cmpUintInterval, genUintIvals(n)...)
3939
probe := genUintIvals(1)[0]
@@ -42,13 +42,13 @@ func BenchmarkInsertMutable(b *testing.B) {
4242
b.Run(name, func(b *testing.B) {
4343
b.ResetTimer()
4444
for n := 0; n < b.N; n++ {
45-
(&tree).InsertMutable(probe)
45+
tree.Insert(probe)
4646
}
4747
})
4848
}
4949
}
5050

51-
func BenchmarkDelete(b *testing.B) {
51+
func BenchmarkDeleteImmutable(b *testing.B) {
5252
for n := 1; n <= 1_000_000; n *= 10 {
5353
ivals := genUintIvals(n)
5454
probe := ivals[rand.Intn(len(ivals))]
@@ -59,13 +59,13 @@ func BenchmarkDelete(b *testing.B) {
5959
b.Run(name, func(b *testing.B) {
6060
b.ResetTimer()
6161
for n := 0; n < b.N; n++ {
62-
_, _ = tree.Delete(probe)
62+
_, _ = tree.DeleteImmutable(probe)
6363
}
6464
})
6565
}
6666
}
6767

68-
func BenchmarkDeleteMutable(b *testing.B) {
68+
func BenchmarkDelete(b *testing.B) {
6969
for n := 1; n <= 1_000_000; n *= 10 {
7070
ivals := genUintIvals(n)
7171
probe := ivals[rand.Intn(len(ivals))]
@@ -76,7 +76,7 @@ func BenchmarkDeleteMutable(b *testing.B) {
7676
b.Run(name, func(b *testing.B) {
7777
b.ResetTimer()
7878
for n := 0; n < b.N; n++ {
79-
_ = (&tree).DeleteMutable(probe)
79+
_ = tree.Delete(probe)
8080
}
8181
})
8282
}
@@ -105,13 +105,13 @@ func BenchmarkUnionImmutable(b *testing.B) {
105105
b.Run(name, func(b *testing.B) {
106106
b.ResetTimer()
107107
for n := 0; n < b.N; n++ {
108-
_ = this100_000.Union(tree, false, true)
108+
_ = this100_000.UnionImmutable(tree, false)
109109
}
110110
})
111111
}
112112
}
113113

114-
func BenchmarkUnionMutable(b *testing.B) {
114+
func BenchmarkUnion(b *testing.B) {
115115
for n := 10; n <= 100_000; n *= 10 {
116116
this100_000 := interval.NewTree(cmpUintInterval, genUintIvals(100_000)...)
117117
tree := interval.NewTree(cmpUintInterval, genUintIvals(n)...)
@@ -120,7 +120,7 @@ func BenchmarkUnionMutable(b *testing.B) {
120120
b.Run(name, func(b *testing.B) {
121121
b.ResetTimer()
122122
for n := 0; n < b.N; n++ {
123-
_ = this100_000.Union(tree, false, false)
123+
this100_000.Union(tree, false)
124124
}
125125
})
126126
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/gaissmai/interval
22

3-
go 1.18
3+
go 1.20

0 commit comments

Comments
 (0)