Created
May 4, 2020 12:52
-
-
Save stedolan/f0cb0f5ab24f283d398e48763db1ae62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Int64Array : sig | |
module Array : sig | |
type t | |
val create_uninitialised : int -> t | |
val get : t -> int -> int64 | |
val set : t -> int -> int64 -> unit | |
val unsafe_get : t -> int -> int64 | |
val unsafe_set : t -> int -> int64 -> unit | |
end | |
end = struct | |
module Array = struct | |
type t = Bytes.t | |
let create_uninitialised sz = Bytes.create (sz * 8) | |
external set_raw_64 : Bytes.t -> int -> int64 -> unit = "%caml_bytes_set64" | |
external get_raw_64 : Bytes.t -> int -> int64 = "%caml_bytes_get64" | |
external unsafe_set_raw_64 : Bytes.t -> int -> int64 -> unit = "%caml_bytes_set64u" | |
external unsafe_get_raw_64 : Bytes.t -> int -> int64 = "%caml_bytes_get64u" | |
let get arr i = get_raw_64 arr (i * 8) | |
let set arr i x = set_raw_64 arr (i * 8) x | |
let unsafe_get arr i = unsafe_get_raw_64 arr (i * 8) | |
let unsafe_set arr i x = unsafe_set_raw_64 arr (i * 8) x | |
end | |
end | |
module IntArray : sig | |
module Array : sig | |
type t | |
val create_uninitialised : int -> t | |
val get : t -> int -> int | |
val set : t -> int -> int -> unit | |
val unsafe_get : t -> int -> int | |
val unsafe_set : t -> int -> int -> unit | |
end | |
end = struct | |
module Array = struct | |
type t = Int64Array.Array.t | |
let create_uninitialised = Int64Array.Array.create_uninitialised | |
let get arr i = Int64.to_int (Int64Array.Array.get arr i) | |
let set arr i x = Int64Array.Array.set arr i (Int64.of_int x) | |
let unsafe_get arr i = Int64.to_int (Int64Array.Array.unsafe_get arr i) | |
let unsafe_set arr i x = Int64Array.Array.unsafe_set arr i (Int64.of_int x) | |
end | |
end | |
let () = | |
let open IntArray in | |
let a = Array.create_uninitialised 3 in | |
a.(0) <- 42; | |
a.(1) <- 100; | |
Printf.printf "%d %d %d\n" a.(0) a.(1) a.(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment