package exenum

  1. Overview
  2. Docs
Build efficient enumerations for datatypes. Inspired by Feat for Haskell.

Install

Dune Dependency

Authors

Maintainers

Sources

v0.84.0.tar.gz
sha256=d1d0f10e592895ecce69fe31cacd7572077dff4f960a6f16d223f56274be4a8f
md5=f4d7c0bf20a74918f68919ff28739b4f

doc/src/exenum.internals/shuffle.ml.html

Source file shuffle.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
open Convenience

(*** Shuffle, deterministically, the values inside parts. ***)

(* Starting from x, find a number prime with y. *)
let rec find_prime x y =
  let gcd = Z.gcd x y in
  if is_bigone gcd then x
  else find_prime (Z.succ x) y

let compute_shuffle card compute =

  (* Z doc says bigints can be compared using >  *)
  if card = Z.zero then
    (* The part is empty. *)
    (fun index -> assert false) (* Should not be invoked. *)
      
  else
  
  (* Find a number within the order of magnitude of sqrt(card) 
   * and that is prime with card. *)
  let prime = find_prime (Z.sqrt card) card in

  fun index -> 
    let new_index = bigmod (index ** prime) card in
    compute new_index


OCaml

Innovation. Community. Security.