rmq

package
v0.0.0-...-881dfb5 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package rmq implements a range-minimum-query data structure that 1. precomputes a sparse table on O(N*logN) time 2. answers the minimum value of any subarray of a static array in O(1) time.

Example usage.

q := NewRMQ[int]([]int{6, 1, 0, 10, 9}, func(v1, v2 int) bool { return v1 < v2 })
q.RMQ(0, 0) // 6
q.RMQ(0,1) // 1

See https://cp-algorithms.com/sequences/rmq.html for more info.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RMQ

type RMQ[V any] struct {
	// contains filtered or unexported fields
}

RMQ is a data structure that precomputes a sparse table on O(N*logN) time and answers the minimum value of any subarray of a static array in O(1) time.

func NewRMQ

func NewRMQ[V any](elements []V, compare func(v1, v2 V) int) *RMQ[V]

NewRMQ creates a RMQ with the elements and compare function.

func (*RMQ[V]) RMQ

func (q *RMQ[V]) RMQ(l, r int) V

RMQ returns the minimum value between elements[l:r], inclusive at both ends.

Jump to

Keyboard shortcuts

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