package core_kernel

  1. Overview
  2. Docs
Industrial strength alternative to OCaml's standard library

Install

Dune Dependency

Authors

Maintainers

Sources

core_kernel-v0.15.0.tar.gz
sha256=34a0288f16027c6b90e4ad16cb5cc677d7063d310faf918748ce70f1745116c0

doc/src/core_kernel.weak_array/weak_array.ml.html

Source file weak_array.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
29
30
31
32
33
34
open! Core

module Weak = Caml.Weak

type 'a t = 'a Heap_block.t Weak.t

let create ~len = Weak.create len
let length t = Weak.length t
let set = Weak.set

let set_exn t i x = set t i (Option.map x ~f:Heap_block.create_exn)

let get = Weak.get
let is_some t i = Weak.check t i
let is_none t i = not (is_some t i)
let to_array t = Array.init (length t) ~f:(fun i -> get t i)
let sexp_of_t sexp_of_a t = [%sexp_of: a Heap_block.t option array] (to_array t)

let iter t ~f =
  for i = 0 to length t - 1 do
    match get t i with
    | None -> ()
    | Some v -> f (Heap_block.value v)
  done

let iteri t ~f =
  for i = 0 to length t - 1 do
    match get t i with
    | None -> ()
    | Some v -> f i (Heap_block.value v)
  done

let blit ~src ~src_pos ~dst ~dst_pos ~len =
  Weak.blit src src_pos dst dst_pos len
OCaml

Innovation. Community. Security.