Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/*
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: go

go:
- "1.11"
- "1.12"
- "1.13"
68 changes: 35 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)!
26 changes: 0 additions & 26 deletions example/ex1.go

This file was deleted.

27 changes: 27 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -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
})
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/petar/GoLLRB/llrb

go 1.11