package granary

  1. Overview
  2. Docs
Pure-OCaml SQL engine

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.0.3.tar.gz
sha256=8b18780ea373be48301d9f333925860a2f9110fc0ac28684295118d72b65a67e
sha512=25ca3c9c5e2b528704a542502e0f37dc33ba003f65622d969b8c2b800778585f8ef0cf89b36e6679832e3993e8303aecddfc662742baf7044d6afe4a796b8f11

doc/granary.ivm/Granary_ivm/Aggregate/Make/argument-1-S/In/index.html

Module S.In

Input Z-set (the rows being aggregated).

type elt

The element type this Z-set ranges over.

type t

A Z-set: a finitely-supported elt -> int weight map, kept canonical (no zero-weight entries).

val zero : t

The empty Z-set (additive identity).

val is_zero : t -> bool

is_zero z is true iff z has no elements (equivalently, total weight everywhere is 0).

val singleton : elt -> int -> t

singleton e w is the Z-set mapping e to w (and zero if w = 0).

val of_list : (elt * int) list -> t

of_list pairs sums the weights of repeated elements; entries that sum to 0 are dropped.

val to_list : t -> (elt * int) list

to_list z returns the (element, nonzero-weight) pairs, ordered by the element ELEMENT.compare.

val weight : t -> elt -> int

weight z e is the weight of e in z (0 if absent).

val add : t -> t -> t

add a b is the pointwise sum of weights, dropping any that cancel to 0. Commutative, associative, with identity zero.

val negate : t -> t

negate z flips the sign of every weight (the additive inverse: add z (negate z) = zero).

val sub : t -> t -> t

sub a b is add a (negate b).

val scale : int -> t -> t

scale n z multiplies every weight by n (zero when n = 0).

val map : (elt -> elt) -> t -> t

map f z applies f to each element, summing the weights of elements that collide onto the same image (and dropping any that cancel). A linear operator: map f (add a b) = add (map f a) (map f b).

val filter : (elt -> bool) -> t -> t

filter p z keeps the entries whose element satisfies p, weights unchanged. A linear operator.

val distinct : t -> t

distinct z is the set-semantics projection: every element with weight > 0 is mapped to weight 1; elements with weight <= 0 are dropped. Idempotent.

val support : t -> elt list

support z is the list of elements with nonzero weight, ordered by ELEMENT.compare.

val cardinality : t -> int

cardinality z is the number of distinct elements with nonzero weight.

val total_weight : t -> int

total_weight z is the sum of all weights (may be negative).

val iter : (elt -> int -> unit) -> t -> unit

iter f z applies f element weight to each entry, in element order.

val fold : (elt -> int -> 'a -> 'a) -> t -> 'a -> 'a

fold f z acc folds f element weight over the entries, in element order.

val equal : t -> t -> bool

Structural equality (canonical form makes this exact set/weight equality).

val pp : Format.formatter -> t -> unit

Pretty-print a Z-set as {e1: w1, e2: w2, …}.