From 76c19c62cbf7b9977fcba7ed9610f0fb9f1dcc33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20F=2E=20R=C3=B8dseth?= Date: Fri, 22 Nov 2019 11:32:22 +0100 Subject: [PATCH 1/5] Ignore built executables --- .gitignore | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index e333b2d..791c84e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,24 @@ -syntax:glob -*.[568ao] -*.ao -*.so -*.pyc +* +!*.* +!*/ +*.o *.swp +*.tmp +*.bak +*.pro.user +*.dblite +*.so *.swo -._* -.nfs.* -[568a].out -*~ +*.ao +*.pyc *.orig *.pb.go -core +*~ +._* +*.nfs.* +.vscode +*CMakeFiles* _obj _test -src/pkg/Make.deps _testmain.go - -syntax:regexp -^pkg/ -^src/cmd/(.*)/6?\1$ -^.*/core.[0-9]*$ +!img/* From c04fb46686cdf1006b6a77ca0f1b81ef23eb4b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20F=2E=20R=C3=B8dseth?= Date: Fri, 22 Nov 2019 11:32:28 +0100 Subject: [PATCH 2/5] Add CI configuration --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b1288e0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: go + +go: + - "1.11" + - "1.12" + - "1.13" From fcd6da2997a0d0f50e349a74359c742a9a646606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20F=2E=20R=C3=B8dseth?= Date: Fri, 22 Nov 2019 11:32:35 +0100 Subject: [PATCH 3/5] Make the example work again --- example/ex1.go | 26 -------------------------- example/main.go | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 26 deletions(-) delete mode 100644 example/ex1.go create mode 100644 example/main.go diff --git a/example/ex1.go b/example/ex1.go deleted file mode 100644 index 6ebe4a6..0000000 --- a/example/ex1.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "fmt" - "github.com/petar/GoLLRB/llrb" -) - -func lessInt(a, b interface{}) bool { return a.(int) < b.(int) } - -func main() { - tree := llrb.New(lessInt) - tree.ReplaceOrInsert(1) - tree.ReplaceOrInsert(2) - tree.ReplaceOrInsert(3) - tree.ReplaceOrInsert(4) - tree.DeleteMin() - tree.Delete(4) - c := tree.IterAscend() - for { - u := <-c - if u == nil { - break - } - fmt.Printf("%d\n", int(u.(int))) - } -} diff --git a/example/main.go b/example/main.go new file mode 100644 index 0000000..847079a --- /dev/null +++ b/example/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + + "github.com/petar/GoLLRB/llrb" +) + +func lessInt(a, b interface{}) bool { return a.(int) < b.(int) } + +func main() { + tree := llrb.New() + tree.ReplaceOrInsert(llrb.Int(1)) + tree.ReplaceOrInsert(llrb.Int(2)) + tree.ReplaceOrInsert(llrb.Int(3)) + tree.ReplaceOrInsert(llrb.Int(4)) + tree.DeleteMin() // Delete 1 + tree.Delete(llrb.Int(4)) // Delete 4 + + // Will output: + // 2 llrb.Int + // 3 llrb.Int + tree.AscendGreaterOrEqual(llrb.Int(-1), func(i llrb.Item) bool { + fmt.Printf("%d %T\n", i, i) + return true + }) +} From b22d1d0bbb81dd45b02fbea99a4f8ff59b5c3942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20F=2E=20R=C3=B8dseth?= Date: Fri, 22 Nov 2019 11:33:51 +0100 Subject: [PATCH 4/5] Add Go module file --- go.mod | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 go.mod diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6eea46b --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/petar/GoLLRB/llrb + +go 1.11 From f8bdee12fa83fde9236066c61ae59800df09938a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20F=2E=20R=C3=B8dseth?= Date: Fri, 22 Nov 2019 11:34:16 +0100 Subject: [PATCH 5/5] Update documentation, add shields --- README.md | 68 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 742ca0b..ef97a5e 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# GoLLRB +# GoLLRB [![Build Status](https://travis-ci.com/petar/GoLLRB.svg?branch=master)](https://travis-ci.com/petar/GoLLRB) [![Go Report Card](https://goreportcard.com/badge/github.com/petar/GoLLRB)](https://goreportcard.com/report/github.com/petar/GoLLRB) [![GoDoc](https://godoc.org/github.com/petar/GoLLRB?status.svg)](https://godoc.org/github.com/petar/GoLLRB) GoLLRB is a Left-Leaning Red-Black (LLRB) implementation of 2-3 balanced binary search trees in Go Language. ## Overview -As of this writing and to the best of the author's knowledge, +As of this writing and to the best of the author's knowledge, Go still does not have a balanced binary search tree (BBST) data structure. These data structures are quite useful in a variety of cases. A BBST maintains elements in sorted order under dynamic updates (inserts and deletes) and can @@ -28,39 +28,41 @@ I consider it to be in stable, perhaps even production, shape. There are no know ## Installation -With a healthy Go Language installed, simply run `go get github.com/petar/GoLLRB/llrb` +With a healthy Go Language installed, simply run `go get -u github.com/petar/GoLLRB/llrb` ## Example - - package main - - import ( - "fmt" - "github.com/petar/GoLLRB/llrb" - ) - - func lessInt(a, b interface{}) bool { return a.(int) < b.(int) } - - func main() { - tree := llrb.New(lessInt) - tree.ReplaceOrInsert(1) - tree.ReplaceOrInsert(2) - tree.ReplaceOrInsert(3) - tree.ReplaceOrInsert(4) - tree.DeleteMin() - tree.Delete(4) - c := tree.IterAscend() - for { - u := <-c - if u == nil { - break - } - fmt.Printf("%d\n", int(u.(int))) - } - } -## About +```go +package main + +import ( + "fmt" + + "github.com/petar/GoLLRB/llrb" +) + +func lessInt(a, b interface{}) bool { return a.(int) < b.(int) } -GoLLRB was written by [Petar Maymounkov](http://pdos.csail.mit.edu/~petar/). +func main() { + tree := llrb.New() + tree.ReplaceOrInsert(llrb.Int(1)) + tree.ReplaceOrInsert(llrb.Int(2)) + tree.ReplaceOrInsert(llrb.Int(3)) + tree.ReplaceOrInsert(llrb.Int(4)) + tree.DeleteMin() // Delete 1 + tree.Delete(llrb.Int(4)) // Delete 4 + + // Will output: + // 2 llrb.Int + // 3 llrb.Int + tree.AscendGreaterOrEqual(llrb.Int(-1), func(i llrb.Item) bool { + fmt.Printf("%d %T\n", i, i) + return true + }) +} +``` + +## About -Follow me on [Twitter @maymounkov](http://www.twitter.com/maymounkov)! +* GoLLRB was written by [Petar Maymounkov](http://pdos.csail.mit.edu/~petar/). +* Follow me on [Twitter @maymounkov](http://www.twitter.com/maymounkov)!