jon.recoil.org

Module Misc.Maybe_boundedSource

A bounded non-negative integer. The possible ranges are 0 ..< n, represented by Bounded { bound = n} and 0 ..< ∞ represented by Unbounded.

Sourcetype t =
  1. | Unbounded
  2. | Bounded of {
    1. mutable bound : int;
    }
    (*

    The bound is not included.

    *)
Sourceval decr : t -> unit

decr decreases the current bound and truncates at zero. As such, decr and then incr is not always a no-op.

Sourceval incr : t -> unit

incr increases the current bound. Raises an exception when attempting to increment max_int.

Sourceval is_depleted : t -> bool
Sourceval is_in_bounds : int -> t -> bool

is_in_bounds n t returns true if n is in bounds. A number counts as in bounds if it is non-negative and strictly smaller than the bound. For Unbounded, returns true if n >= 0.

Sourceval is_out_of_bounds : int -> t -> bool

is_out_of_bounds n t returns true if n is out of bounds. A number is out of bounds if it is negative or greater than or equal to the bound. For Unbounded, returns false if n < 0 and true otherwise.

Sourceval of_option : int option -> t

of_option opt maps None to no bound and Some n to the bound n (not inclusive).

Sourceval of_int : int -> t

of_int n creates a bounded integer with bound n (not inclusive).