[][src]Crate pergola

This is a small crate that provides a generic unital-join-semilattice type (hereafter: "lattice") along with a few common instances.

Lattices are defined in two separate pieces: a definition trait LatticeDef that provides the type-and-functions for a given lattice and a user interface struct LatticeElt that's parameterized by a LatticeDef and provides convenient methods to work with (including impls of standard Rust operator traits).

This unusual split exists because many types have multiple equally viable lattices you can build on them (eg. u32-with-min or u32-with-max) and we want to avoid both coupling any given lattice definition to the type or accidentally inheriting an impl for any of the type's "standard semantics" as the lattice semantics, eg. we don't want to inherit u32's standard partial order as any lattice's partial order, unless explicitly building such a lattice.

Structs

BTreeMapWithIntersection

Similar to other intersection-based lattices in this crate, this lattice is a map that stores inner lattices and joins using intersection. Maps are represented as Option<BTreeMap> and the unit is again a putative "maximum" map-with-all-possible-keys (represented by None).

BTreeMapWithUnion

This is a lattice for maps that contain other lattices as values. The join operator takes the union of (key, value) pairs for keys present in only one map -- equivalent to an elementwise join-with-unit -- and the elementwise join of values for keys that exist in both maps.

BTreeSetWithIntersection

This is the same semantics as the BitSetWithIntersection lattice, but covering sets of arbitrary ordered values.

BTreeSetWithUnion

This is the same semantics as the BitSetWithUnion lattice, but covering sets of arbitrary ordered values.

BitSetWithIntersection

This lattice is a standard bitset-with-intersection.

BitSetWithUnion

This lattice is a standard bitset-with-union.

LatticeElt

Write code that uses lattices over this type, and it will delegate to the functions of the parameter LatticeDef.

MaxDef

This lattice definition recycles the Ord::max and Ord::cmp of its element type, as well as either Default::default as its unit. In other words this is the "most normal" lattice over unsigned scalar, vector or string types, probably the one you want most of the time.

MaxNum

This lattice definition recycles the Ord::max and Ord::cmp of its element type, as well as Bounded::min_value as its unit. This is similar to MaxDef except it works with signed types.

MinNum

This is like MinOpt but for numeric (or specifically Bounded) types that have a numeric upper bound: it uses that as the unit rather than the additional "maximal value" tacked on in MinOpt. Best option for numeric lattices with join as minimum.

MinOpt

This lattice is similar to MaxDef but inverts the order, with the minimal value according to Ord::cmp as its join, and the unit being a putative "maximal" value of the element type. Since several Ord types do not have a maximal value (think strings, maps, etc.) MinOpt represents its element using an Option where None is the "maximal" value (that forms the lattice unit) and Some(M) is for the rest.

Tuple2

Cartesian product lattices or 2, 3, 4, 5 inner lattices. Join joins elements pairwise, order is the product order (not lexicographical order) i.e. where (a, b) <= (c, d) iff a <= c and b <= d.

Tuple3
Tuple4
Tuple5

Traits

LatticeDef

Implement this trait on a (typically vacuous) type to define a specific lattice as a type-with-some-choice-of-operators.

MaxUnitDefault

A marker trait here to pick out types where Default::default is safe to use as a unit for a max-lattice. In particular it's not safe in types like signed integers, where there are many values less than Default::default.

MaxUnitMinValue

A marker type for other types that use the Bounded::min_value as the unit for a max-lattice.