Skip to content

This package provides functionality for indexing a set of integer intervals, e.g. [start, end).

License

Notifications You must be signed in to change notification settings

danilovkiri/gointervaltree

Repository files navigation

GoIntervalTree

An IntervalTree package for Go


Description

This package provides functionality for indexing a set of integer intervals (e.g. [start, end)) with corresponding per-interval data based on Wikipedia reference. No interval removal is implemented. Inspired by Centered Interval Tree Python implementation.

Installation

Use go get to install gointervaltree.

go get github.com/danilovkiri/gointervaltree

Usage

package main

import (
	"fmt"
	"github.com/danilovkiri/gointervaltree"
)

func main() {
	t, _ := gointervaltree.NewIntervalTree(0, 100)
	_ = t.AddInterval(1, 10, []string{"a", "b"})
	_ = t.AddInterval(20, 30, []bool{true, false})
	_ = t.AddInterval(32, 35, []int{1, 2, 3})
	_ = t.AddInterval(32, 38, nil)
	t.Sort()
	fmt.Println(t.Len())
	// 4
	fmt.Println(t.Iter())
	// [{1 10 [a b]} {32 35 [1 2 3]} {32 38 <nil>} {20 30 [true false]}]
	fmt.Println(t.Query(33))
	// [{32 35 [1 2 3]} {32 38 <nil>}]
}

Contributing

Any contribution is appreciated unless no tests are provided and/or updated accordingly.

License

FOSSA Status

About

This package provides functionality for indexing a set of integer intervals, e.g. [start, end).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages