interval

package
v0.0.0-...-37990d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"
	"slices"

	"github.com/crystalix007/multi-binned-intervals/interval"
)

func main() {
	intervals := interval.New[string]()

	intervals.Add(interval.Interval{1, 5}, "first")
	intervals.Add(interval.Interval{7, 10}, "second")
	intervals.Add(interval.Interval{1, 2}, "third")

	intersections, ok := intervals.AllIntersections(5, 8)

	fmt.Printf("Found intersecting values: %t\n", ok)

	if ok {
		// Order is non-determinate.
		slices.Sort(intersections)

		fmt.Printf("Values: %v", intersections)
	}

}
Output:

Found intersecting values: true
Values: [first second]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interval

type Interval struct {
	Start uint64
	End   uint64
}

Interval represents the closed interval [Start, End].

type Tree

type Tree[Value any] interface {
	Add(interval Interval, value Value)
	AllIntersections(start, end uint64) ([]Value, bool)
}

Tree is a node in a hierarchical interval tree.

func New

func New[Value any]() Tree[Value]

New creates a new interval tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL