sparsetable

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package sparsetable implements a sparse table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RMQpm1 added in v0.2.0

type RMQpm1[T constraints.Integer] struct {
	// contains filtered or unexported fields
}

RMQpm1 represents a special case of RMQ. All neighbour elements should differ in 1. Allows to answer rmq queries in constant time with linear preprocessing time.

func NewRMQpm1 added in v0.2.0

func NewRMQpm1[T constraints.Signed](elements []T) RMQpm1[T]

NewRMQpm1 returns RMQpm1 struct. All neighbour elements should differ in 1.

func (*RMQpm1[T]) Min added in v0.2.0

func (rmq *RMQpm1[T]) Min(l, r int) T

Min returns minimum in range l, r.

type SparseTable

type SparseTable[T any] struct {
	// contains filtered or unexported fields
}

SparseTable represents a sparse table. Zero value of SparseTable is invalid sparse table, should be used only with New().

func New

func New[T any](op func(T, T) T, elements []T) *SparseTable[T]

New returns an initialized sparse table. op should be idempotent, commutative and associative.

func (*SparseTable[T]) Query

func (s *SparseTable[T]) Query(l, r int) T

Query returns result of operation on elements[l:r+1].

Jump to

Keyboard shortcuts

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