package grenier

  1. Overview
  2. Docs
A collection of various algorithms in OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

grenier-0.17.tbz
sha256=adce547fae9b5648d902d91173bb787466a197f81610b76757424ab33980e625
sha512=dccce42254660831fbd45129718ce01d2a4fcf10d05fa40f10eb3be4e5c94300af7235cc88c76b2e5aff7a02b8a1e8e6150d2d3376d8b630911d1dc6247b7df6

doc/src/grenier.maxtrie/bit_lib.ml.html

Source file bit_lib.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
(* Bit-twiddling primitives, implemented in C (see bit_stubs.c). *)

external pop_count : (int [@untagged]) -> (int [@untagged]) =
  "maxtrie_pop_count_tagged" "maxtrie_pop_count" [@@noalloc]

external msb_index : (int [@untagged]) -> (int [@untagged]) =
  "maxtrie_msb_index_tagged" "maxtrie_msb_index" [@@noalloc]

external lsb_index : (int [@untagged]) -> (int [@untagged]) =
  "maxtrie_lsb_index_tagged" "maxtrie_lsb_index" [@@noalloc]

external extract_msb : (int [@untagged]) -> (int [@untagged]) =
  "maxtrie_extract_msb_tagged" "maxtrie_extract_msb" [@@noalloc]

let[@inline] extract_lsb x = x land (-x)

(* [lt_msb x y] holds iff the most significant bit of [x] is strictly lower
   than the most significant bit of [y]. Both must be non-negative. *)
let[@inline] lt_msb x y = x < y && x < x lxor y

(* [share_choose a b] chooses which of two equal values to keep when unifying
   them: a value outside the minor heap if there is one, otherwise the one at
   the higher address. *)
external share_choose : 'a -> 'a -> 'a = "maxtrie_share_choose" [@@noalloc]