package bonsai

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file map0.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
open! Core
open! Import
module Incr = Incr0

(* [`Use_assoc] indicates that a function is not recommended in Bonsai because
   its behavior can be implemented by using [Bonsai.assoc] *)
let mapi = `Use_assoc
let map = `Use_assoc
let of_set = Incr.compute ~f:Incr_map.of_set
let filter_mapi m ~f = Incr.compute m ~f:(Incr_map.filter_mapi ~f)
let filter_map m ~f = Incr.compute m ~f:(Incr_map.filter_map ~f)
let partition_mapi m ~f = Incr.compute m ~f:(Incr_map.partition_mapi ~f)

let unordered_fold ?update m ~init ~add ~remove =
  Incr.compute m ~f:(Incr_map.unordered_fold ?update ~init ~add ~remove)
;;

let unordered_fold_with_extra ?update m e ~init ~add ~remove ~extra_changed =
  Incr.compute (Value.both m e) ~f:(fun m_and_e ->
    let%pattern_bind.Ui_incr m, e = m_and_e in
    Incr_map.unordered_fold_with_extra ?update m e ~init ~add ~remove ~extra_changed)
;;

let cutoff m ~equal =
  Incr.compute m ~f:(Incr_map.cutoff ~cutoff:(Ui_incr.Cutoff.of_equal equal))
;;

let mapi_count
      (type k cmp)
      m
      ~comparator:((module M) : (k, cmp) Module_types.comparator)
      ~f
  =
  Incr.compute m ~f:(Incr_map.mapi_count ~comparator:(module M) ~f)
;;

let map_count
      (type k cmp)
      m
      ~comparator:((module M) : (k, cmp) Module_types.comparator)
      ~f
  =
  Incr.compute m ~f:(Incr_map.map_count ~comparator:(module M) ~f)
;;

let mapi_min (type k cmp) m ~comparator:((module M) : (k, cmp) Module_types.comparator) ~f
  =
  Incr.compute m ~f:(Incr_map.mapi_min ~comparator:(module M) ~f)
;;

let mapi_max (type k cmp) m ~comparator:((module M) : (k, cmp) Module_types.comparator) ~f
  =
  Incr.compute m ~f:(Incr_map.mapi_max ~comparator:(module M) ~f)
;;

let map_min (type k cmp) m ~comparator:((module M) : (k, cmp) Module_types.comparator) ~f =
  Incr.compute m ~f:(Incr_map.map_min ~comparator:(module M) ~f)
;;

let map_max (type k cmp) m ~comparator:((module M) : (k, cmp) Module_types.comparator) ~f =
  Incr.compute m ~f:(Incr_map.map_max ~comparator:(module M) ~f)
;;

let min_value (type k cmp) m ~comparator:((module M) : (k, cmp) Module_types.comparator) =
  Incr.compute m ~f:(Incr_map.min_value ~comparator:(module M))
;;

let max_value (type k cmp) m ~comparator:((module M) : (k, cmp) Module_types.comparator) =
  Incr.compute m ~f:(Incr_map.max_value ~comparator:(module M))
;;

let mapi_bounds
      (type k cmp)
      m
      ~comparator:((module M) : (k, cmp) Module_types.comparator)
      ~f
  =
  Incr.compute m ~f:(Incr_map.mapi_bounds ~comparator:(module M) ~f)
;;

let map_bounds
      (type k cmp)
      m
      ~comparator:((module M) : (k, cmp) Module_types.comparator)
      ~f
  =
  Incr.compute m ~f:(Incr_map.map_bounds ~comparator:(module M) ~f)
;;

let value_bounds
      (type k cmp)
      m
      ~comparator:((module M) : (k, cmp) Module_types.comparator)
  =
  Incr.compute m ~f:(Incr_map.value_bounds ~comparator:(module M))
;;

let merge a b ~f =
  Incr.compute (Value.both a b) ~f:(fun a_and_b ->
    let%pattern_bind.Ui_incr a, b = a_and_b in
    Incr_map.merge a b ~f)
;;

let merge_both_some a b ~f =
  Incr.compute (Value.both a b) ~f:(fun a_and_b ->
    let%pattern_bind.Ui_incr a, b = a_and_b in
    Incr_map.merge_both_some a b ~f)
;;

let unzip m =
  Incr.compute m ~f:(fun m ->
    let l, r = Incr_map.unzip m in
    Ui_incr.both l r)
;;

let unzip_mapi m ~f =
  Incr.compute m ~f:(fun m ->
    let l, r = Incr_map.unzip_mapi m ~f in
    Ui_incr.both l r)
;;

let keys = Incr.compute ~f:Incr_map.keys

let rank m k =
  Incr.compute (Value.both m k) ~f:(fun m_and_k ->
    let%pattern_bind.Ui_incr m, k = m_and_k in
    Incr_map.rank m k)
;;

let subrange m bounds =
  Incr.compute (Value.both m bounds) ~f:(fun m_and_bounds ->
    let%pattern_bind.Ui_incr m, bounds = m_and_bounds in
    Incr_map.subrange m bounds)
;;

let subrange_by_rank m bounds =
  Incr.compute (Value.both m bounds) ~f:(fun m_and_bounds ->
    let%pattern_bind.Ui_incr m, bounds = m_and_bounds in
    Incr_map.subrange_by_rank m bounds)
;;

let rekey (type k cmp) m ~comparator:((module M) : (k, cmp) Module_types.comparator) ~f =
  Incr.compute m ~f:(Incr_map.rekey ~comparator:(module M) ~f)
;;

let index_byi
      (type k cmp)
      m
      ~comparator:((module M) : (k, cmp) Module_types.comparator)
      ~index
  =
  Incr.compute m ~f:(Incr_map.index_byi ~comparator:(module M) ~index)
;;

let index_by
      (type k cmp)
      m
      ~comparator:((module M) : (k, cmp) Module_types.comparator)
      ~index
  =
  Incr.compute m ~f:(Incr_map.index_by ~comparator:(module M) ~index)
;;

let unordered_fold_nested_maps ?update m ~init ~add ~remove =
  Incr.compute m ~f:(Incr_map.unordered_fold_nested_maps ?update ~init ~add ~remove)
;;

let transpose (type k cmp) ((module M) : (k, cmp) Module_types.comparator) m =
  Incr.compute m ~f:(Incr_map.transpose (module M))
;;

let collapse (type k cmp) m ~comparator:((module M) : (k, cmp) Module_types.comparator) =
  Incr.compute m ~f:(Incr_map.collapse ~comparator:(module M))
;;

let collapse_by
      (type k cmp)
      m
      ~merge_keys
      ~comparator:((module M) : (k, cmp) Module_types.comparator)
  =
  Incr.compute m ~f:(Incr_map.collapse_by ~comparator:(module M) ~merge_keys)
;;

let expand
      (type k k2 cmp cmp2)
      m
      ~outer_comparator:((module M_outer) : (k, cmp) Module_types.comparator)
      ~inner_comparator:((module M_inner) : (k2, cmp2) Module_types.comparator)
  =
  Incr.compute
    m
    ~f:
      (Incr_map.expand
         ~inner_comparator:(module M_inner)
         ~outer_comparator:(module M_outer))
;;

let counti m ~f = Incr.compute m ~f:(Incr_map.counti ~f)
let count m ~f = Incr.compute m ~f:(Incr_map.count ~f)
let for_alli m ~f = Incr.compute m ~f:(Incr_map.for_alli ~f)
let for_all m ~f = Incr.compute m ~f:(Incr_map.for_all ~f)
let existsi m ~f = Incr.compute m ~f:(Incr_map.existsi ~f)
let exists m ~f = Incr.compute m ~f:(Incr_map.exists ~f)
let sum m algebra ~f = Incr.compute m ~f:(fun m -> Incr_map.sum m algebra ~f)