package optint
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=27847660223c16cc7eaf8fcd9d5589a0b802114330a2529578f8007d3b01185d
sha512=6ec2f6977b2cb148b0b9c2664e8a8525b0d0b987652f5a4c9754d200d8026de8bfab664d31807e68b5f1dffa8bbe5b51167435e6e66faf5baefb509c667e0c77
Description
This library provides two new integer types, Optint.t
and Int63.t
, which
guarantee efficient representation on 64-bit architectures and provide a
best-effort boxed representation on 32-bit architectures.
Implementation depends on target architecture.
Published: 30 Mar 2021
README
Optint - Efficient integer types on 64-bit architectures
This library provides two new integer types, Optint.t
and Int63.t
, which guarantee efficient representation on 64-bit architectures and provide a best-effort boxed representation on 32-bit architectures.
Goal
The standard Int32.t
and Int64.t
types provided by the standard library have the same heap-allocated representation on all architectures. This consistent representation has costs in both memory and run-time performance.
On 64-bit 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 64-bit, this is an immediate integer; on 32-bit, it is a boxed 32-bit value. The overflow behaviour is platform-dependent.Int63.t
: an integer containing exactly 63 bits. On 64-bit, this is an immediate integer; on 32-bit, it is a boxed 64-bit integer that is wrapped to provide 63-bit two's complement semantics. The two implementations are observationally equivalent, modulo use ofMarshal
andObj
.
In summary:
Integer type | 32-bit representation | 64-bit representation | Semantics |
---|---|---|---|
Stdlib.Int.t |
31-bit immediate ✅ | 63-bit immediate ✅ | Always immediate |
Stdlib.Nativeint.t |
64-bit boxed ❌ | 32-bit boxed ❌ | Exactly word size |
Stdlib.Int32.t |
32-bit boxed ❌ | 32-bit boxed ❌ | Exactly 32 bits |
Stdlib.Int64.t |
64-bit boxed ❌ | 64-bit boxed ❌ | Exactly 64 bits |
Optint.t (new) |
32-bit boxed ❌ | 63-bit immediate ✅ | At least 32 bits |
Int63.t (new) |
64-bit boxed ❌ | 63-bit immediate ✅ | Exactly 63 bits |
These new types are safe and well-tested, but their architecture-dependent implementation makes them unsuitable for use with the Marshal
module. Use the provided encode and decode functions instead.
Dev Dependencies (4)
Used by (25)
- cactus
- carton
- carton-lwt
- chamelon
-
checkseum
>= "0.3.1" & < "0.3.3"
-
decompress
>= "0.8"
- eio
-
git
>= "3.0.0"
-
index
>= "1.4.0"
-
index-bench
>= "1.4.0"
-
irmin-pack
>= "2.7.0"
- irmin-server
-
mirage-kv-mem
>= "3.2.1"
-
mirage-kv-unix
>= "3.0.0"
- multibase
- octez-internal-libs
- oneffs
- ppx_optint
-
ppx_repr
>= "0.5.0"
-
progress
>= "0.2.0"
-
repr
>= "0.5.0"
-
rfc1951
< "1.0.0" | >= "1.3.0"
-
tar-mirage
>= "2.3.0"
- uring
- wu-manber-fuzzy-search
Conflicts
None