Skip to Content
ReferenceLibrary

pair

An unordered pair {lo, hi} of distinct positions of V, lo before hi.

Generated from spec/std/pair.cp by cpl doc --format json.

Pair

pub struct Pair<V>(lo: V, hi: V)

An unordered pair {lo, hi} of distinct positions of V, lo before hi. Pair<V> is a domain of V.count * (V.count - 1) / 2 positions, so [Pair<V>]T stores one value per pair, packed, with no diagonal and no mirrored half. It walks by hi, then by lo: (0, 1), (0, 2), (1, 2), (0, 3), ..., which is the order a lower triangle is given in (row i lists the pairs with every earlier j), so read<[Pair<V>]Int>() reads one. An array over it takes two positions in either order: d[u, v] == d[v, u], trapping when u == v.

Source

Pair.new

fn new(u: V, v: V) -> Pair<V>

The pair of u and v, in either order: the smaller position becomes lo.

  • cost: O(1)
  • traps: when u == v

Examples:

  • Pair<0..4>(3, 1).lo == 1
  • Pair<0..4>(3, 1) == Pair<0..4>(1, 3)

Source

Pair.at

fn at(u: V, v: V) -> ?Pair<V>

The pair of u and v in either order, or None when u == v: the non-trapping new.

  • cost: O(1)
  • traps: never

Examples:

  • Pair<0..4>.at(2, 2) == None
  • Pair<0..4>.at(2, 0) == Some(Pair<0..4>(0, 2))

Source

Pair.other

fn other(self, v: V) -> V

The end of the pair that is not v: p.other(p.lo) == p.hi and p.other(p.hi) == p.lo.

  • cost: O(1)
  • traps: when v is neither self.lo nor self.hi

Examples:

  • Pair<0..4>(1, 3).other(3) == 1

Source

On this page