package optint
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=295cff2c134b0385b13ba81d5005d9f841ba40d4a502aed10c997f239ef1147b
sha512=15ec97a076584e8ea28c589f1db3b9a0dd6fd5a7950528a1d136761cc13bca0e6e7bf6e0f87c73578a37393c213a7a0f3e7beaabd924e176459b29af52b8dd11
Description
This library provides two new integer types, Optint.t
and Int63.t
, which
guarantee efficient representation on 64bit architectures and provide a
besteffort boxed representation on 32bit architectures.
Implementation depends on target architecture.
Published: 23 Dec 2022
README
Optint  Efficient integer types on 64bit architectures
This library provides two new integer types, Optint.t
and Int63.t
, which guarantee efficient representation on 64bit architectures and provide a besteffort boxed representation on 32bit architectures.
Goal
The standard Int32.t
and Int64.t
types provided by the standard library have the same heapallocated representation on all architectures. This consistent representation has costs in both memory and runtime performance.
On 64bit architectures, it's often more efficient to use the native int
directly. This library provides types to do exactly this:
Optint.t
: an integer containing at least 32 bits. On 64bit, this is an immediate integer; on 32bit, it is a boxed 32bit value. The overflow behaviour is platformdependent.Int63.t
: an integer containing exactly 63 bits. On 64bit, this is an immediate integer; on 32bit, it is a boxed 64bit integer that is wrapped to provide 63bit two's complement semantics. The two implementations are observationally equivalent, modulo use ofMarshal
andObj
.
In summary:
Integer type  32bit representation  64bit representation  Semantics 

Stdlib.Int.t 
31bit immediate ✅  63bit immediate ✅  Always immediate 
Stdlib.Nativeint.t 
32bit boxed ❌  64bit boxed ❌  Exactly word size 
Stdlib.Int32.t 
32bit boxed ❌  32bit boxed ❌  Exactly 32 bits 
Stdlib.Int64.t 
64bit boxed ❌  64bit boxed ❌  Exactly 64 bits 
Optint.t (new) 
32bit boxed ❌  63bit immediate ✅  At least 32 bits 
Int63.t (new) 
64bit boxed ❌  63bit immediate ✅  Exactly 63 bits 
These new types are safe and welltested, but their architecturedependent implementation makes them unsuitable for use with the Marshal
module. Use the provided encode and decode functions instead.
Used by (24)
 cactus
 carton
 cartonlwt
 chamelon

checkseum
>= "0.3.1"

decompress
>= "0.8"
 eio

git
>= "3.0.0"

index
>= "1.4.0"

indexbench
>= "1.4.0"

irminpack
>= "2.7.0"
 irminserver

miragekv
>= "6.0.0"

miragekvmem
>= "3.2.1"
 multibase
 oneffs
 ppx_optint

ppx_repr
>= "0.5.0"

progress
>= "0.2.0"

repr
>= "0.5.0"

rfc1951
< "1.0.0"  >= "1.3.0"

tarmirage
>= "2.3.0"
 uring
 wumanberfuzzysearch
Conflicts
None