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
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,32 @@ I consider it to be in stable, perhaps even production, shape. There are no know
With a healthy Go Language installed, simply run `go get 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 Print(item llrb.Item) bool {
i, ok := item.(llrb.Int)
if !ok {
return false
}
fmt.Println(int(i))
return true
}

func main() {
tree := llrb.New(lessInt)
tree.ReplaceOrInsert(1)
tree.ReplaceOrInsert(2)
tree.ReplaceOrInsert(3)
tree.ReplaceOrInsert(4)
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()
tree.Delete(4)
c := tree.IterAscend()
for {
u := <-c
if u == nil {
break
}
fmt.Printf("%d\n", int(u.(int)))
}
tree.Delete(llrb.Int(4))
tree.AscendGreaterOrEqual(tree.Min(), Print)
}

## About
Expand Down
30 changes: 15 additions & 15 deletions example/ex1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import (
"github.com/petar/GoLLRB/llrb"
)

func lessInt(a, b interface{}) bool { return a.(int) < b.(int) }
func Print(item llrb.Item) bool {
i, ok := item.(llrb.Int)
if !ok {
return false
}
fmt.Println(int(i))
return true
}

func main() {
tree := llrb.New(lessInt)
tree.ReplaceOrInsert(1)
tree.ReplaceOrInsert(2)
tree.ReplaceOrInsert(3)
tree.ReplaceOrInsert(4)
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()
tree.Delete(4)
c := tree.IterAscend()
for {
u := <-c
if u == nil {
break
}
fmt.Printf("%d\n", int(u.(int)))
}
tree.Delete(llrb.Int(4))
tree.AscendGreaterOrEqual(tree.Min(), Print)
}