QCaml/common/zkey.org

10 KiB

Zkey

Encodes the powers of x, y, z in a compact form, suitable for being used as keys in a hash table.

Internally, the Zkey.t is made of two integers, left and right. The small integers x, y and z are stored compactly in this 126-bits space:

Example:

                              Left                                                                Right
3 [--------------------------------------------------------------]       [------------------|---------------|---------------|---------------]
                                                                                                   x               y               z        

6 [--------------------------------------------------------------]       [---|----------|----------|----------|----------|----------|---------]
                                                                                 x1         y1         z1         x2         y2         z2        

9 [---------------------------------|----------|----------|---------]    [---|----------|----------|----------|----------|----------|---------]
                                        x1         y1         z1                 x2         y2         z2         x3         y3         z3        

12 [---|----------|----------|----------|----------|----------|---------] [---|----------|----------|----------|----------|----------|---------]
          x1         y1         z1         x2         y2         z2              x3         y3         z3         x4         y4         z4

The values of x,y,z should be positive and should not exceed 32767 for kind=3. For all other kinds kinds the values should not exceed 1023.

Types

<<<~Zkey.t~>>>

type t 

type kind =
| Three  of  Powers.t
| Four   of (int * int * int * int)
| Six    of (Powers.t * Powers.t)
| Nine   of (Powers.t * Powers.t * Powers.t)
| Twelve of (Powers.t * Powers.t * Powers.t * Powers.t)

Conversions

val of_powers_three  : Powers.t -> t
val of_powers_six    : Powers.t -> Powers.t -> t
val of_powers_nine   : Powers.t -> Powers.t -> Powers.t -> t
val of_powers_twelve : Powers.t -> Powers.t -> Powers.t -> Powers.t -> t
val of_powers        : kind -> t
val of_int_array     : int array -> t
val of_int_four      : int -> int -> int -> int -> t
val to_int_array     : t -> int array
val to_powers        : t -> kind
val to_string        : t -> string
of_powers_three Create from a Powers.t
of_powers_six Create from two Powers.t
of_powers_nine Create from three Powers.t
of_powers_twelve Create from four Powers.t
of_powers Create using the kind type
of_int_array Convert from an int array
of_int_four Create from four ints
to_int_array Convert to an int array
to_powers Convert to an Powers.t array
to_string Pretty printing

Functions for hash tables

val hash    : t -> int
val equal   : t -> t -> bool
val compare : t -> t -> int
hash Associates a nonnegative integer to any Zkey
equal The equal function. True if two Zkeys are equal
compare Comparison function, used for sorting

Printers

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