ck/segtree▲toc

Segment tree

Segment tree is a data structure for efficient range operations on sequences.

Notes:

Usage:

import ck/algebra/monoid
import ck/segtree

fun main()
  val seg = segtree(10, ?monoid=int/add/monoid)

  seg.set(1, 3, ?monoid=int/add/monoid)
  seg.set(3, 8, ?monoid=int/add/monoid)
  seg.product(0, 10, ?monoid=int/add/monoid).println // 11
import ck/algebra/monoidck/algebra/monoid
import ck/segtreeck/segtree

fun main()
  val seg = segtree(10, @implicit/monoid=int/add/monoidck/algebra/monoid/int/add/monoid: monoid<int>)

  seg.set(1, 3, @implicit/monoid=int/add/monoidck/algebra/monoid/int/add/monoid: monoid<int>)
  seg.set(3, 8, @implicit/monoid=int/add/monoidck/algebra/monoid/int/add/monoid: monoid<int>)
  seg.productck/segtree/product: forall<a,h> (seg : segtree<h,a>, left : int, right : int, @implicit/monoid : monoid<a>) -> <read<h>,div,exn> a(0, 10, @implicit/monoid=int/add/monoidck/algebra/monoid/int/add/monoid: monoid<int>).println // 11

.

type segtreeck/segtree/segtree: (H, V) -> V<h,a>

Return the smallest integer k between start (inclusive) and end (exclusive) such that the product from the start-th element (inclusive) to the k-th element (inclusive) holds p. If no such k exists, return end. The first element is at position 0 (0-based). p must be increasing.

Return the product from the left-th element (inclusive) to right-th element (exclusive). The first element is at position 0 (0-based).

private import std/core/typesstd/core/types, std/core/hndstd/core/hnd, std/core/exnstd/core/exn, std/core/boolstd/core/bool, std/core/orderstd/core/order, std/core/charstd/core/char, std/core/vectorstd/core/vector, std/core/stringstd/core/string, std/core/sslicestd/core/sslice, std/core/liststd/core/list, std/core/maybestd/core/maybe, std/core/maybe2std/core/maybe2, std/core/eitherstd/core/either, std/core/tuplestd/core/tuple, std/core/lazystd/core/lazy, std/core/showstd/core/show, std/core/debugstd/core/debug, std/core/delayedstd/core/delayed, std/core/consolestd/core/console, std/corestd/core, std/core/intstd/core/int, std/core/undivstd/core/undiv, ck/algebra/monoidck/algebra/monoid, ck/mathck/math