package daypack-lib

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

Source file map_utils_j.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
(* Auto-generated from "map_utils.atd" *)
[@@@ocaml.warning "-27-32-33-35-39"]

type ('k, 'v) diff_bucketed = ('k, 'v) Map_utils_t.diff_bucketed = {
  added: ('k * 'v list) list;
  removed: ('k * 'v list) list
}

type ('k, 'v) diff = ('k, 'v) Map_utils_t.diff = {
  added: ('k * 'v) list;
  removed: ('k * 'v) list
}

let write__a_list write__a = (
  Atdgen_runtime.Oj_run.write_list (
    write__a
  )
)
let string_of__a_list write__a ?(len = 1024) x =
  let ob = Buffer.create len in
  write__a_list write__a ob x;
  Buffer.contents ob
let read__a_list read__a = (
  Atdgen_runtime.Oj_run.read_list (
    read__a
  )
)
let _a_list_of_string read__a s =
  read__a_list read__a (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
let write__a_b_a_list_list write__a write__b = (
  Atdgen_runtime.Oj_run.write_list (
    fun ob x ->
      Buffer.add_char ob '[';
      (let x, _ = x in
      (
        write__a
      ) ob x
      );
      Buffer.add_char ob ',';
      (let _, x = x in
      (
        write__a_list write__b
      ) ob x
      );
      Buffer.add_char ob ']';
  )
)
let string_of__a_b_a_list_list write__a write__b ?(len = 1024) x =
  let ob = Buffer.create len in
  write__a_b_a_list_list write__a write__b ob x;
  Buffer.contents ob
let read__a_b_a_list_list read__a read__b = (
  Atdgen_runtime.Oj_run.read_list (
    fun p lb ->
      Yojson.Safe.read_space p lb;
      Atdgen_runtime.Yojson_extra.start_any_tuple p lb;
      let len = ref 0 in
      let end_of_tuple = ref false in
      (try
        let x0 =
          let x =
            (
              read__a
            ) p lb
          in
          incr len;
          Yojson.Safe.read_space p lb;
          Atdgen_runtime.Yojson_extra.read_tuple_sep2 p lb;
          x
        in
        let x1 =
          let x =
            (
              read__a_list read__b
            ) p lb
          in
          incr len;
          (try
            Yojson.Safe.read_space p lb;
            Atdgen_runtime.Yojson_extra.read_tuple_sep2 p lb;
          with Atdgen_runtime.Yojson_extra.End_of_tuple -> end_of_tuple := true);
          x
        in
        if not !end_of_tuple then (
          try
            while true do
              Yojson.Safe.skip_json p lb;
              Yojson.Safe.read_space p lb;
              Atdgen_runtime.Yojson_extra.read_tuple_sep2 p lb;
            done
          with Atdgen_runtime.Yojson_extra.End_of_tuple -> ()
        );
        (x0, x1)
      with Atdgen_runtime.Yojson_extra.End_of_tuple ->
        Atdgen_runtime.Oj_run.missing_tuple_fields p !len [ 0; 1 ]);
  )
)
let _a_b_a_list_list_of_string read__a read__b s =
  read__a_b_a_list_list read__a read__b (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
let write_diff_bucketed write__k write__v : _ -> ('k, 'v) diff_bucketed -> _ = (
  fun ob (x : ('k, 'v) diff_bucketed) ->
    Buffer.add_char ob '{';
    let is_first = ref true in
    if !is_first then
      is_first := false
    else
      Buffer.add_char ob ',';
      Buffer.add_string ob "\"added\":";
    (
      write__a_b_a_list_list write__k write__v
    )
      ob x.added;
    if !is_first then
      is_first := false
    else
      Buffer.add_char ob ',';
      Buffer.add_string ob "\"removed\":";
    (
      write__a_b_a_list_list write__k write__v
    )
      ob x.removed;
    Buffer.add_char ob '}';
)
let string_of_diff_bucketed write__k write__v ?(len = 1024) x =
  let ob = Buffer.create len in
  write_diff_bucketed write__k write__v ob x;
  Buffer.contents ob
let read_diff_bucketed read__k read__v = (
  fun p lb ->
    Yojson.Safe.read_space p lb;
    Yojson.Safe.read_lcurl p lb;
    let field_added = ref (None) in
    let field_removed = ref (None) in
    try
      Yojson.Safe.read_space p lb;
      Yojson.Safe.read_object_end lb;
      Yojson.Safe.read_space p lb;
      let f =
        fun s pos len ->
          if pos < 0 || len < 0 || pos + len > String.length s then
            invalid_arg (Printf.sprintf "out-of-bounds substring position or length: string = %S, requested position = %i, requested length = %i" s pos len);
          match len with
            | 5 -> (
                if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'd' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' then (
                  0
                )
                else (
                  -1
                )
              )
            | 7 -> (
                if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'v' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then (
                  1
                )
                else (
                  -1
                )
              )
            | _ -> (
                -1
              )
      in
      let i = Yojson.Safe.map_ident p f lb in
      Atdgen_runtime.Oj_run.read_until_field_value p lb;
      (
        match i with
          | 0 ->
            field_added := (
              Some (
                (
                  read__a_b_a_list_list read__k read__v
                ) p lb
              )
            );
          | 1 ->
            field_removed := (
              Some (
                (
                  read__a_b_a_list_list read__k read__v
                ) p lb
              )
            );
          | _ -> (
              Yojson.Safe.skip_json p lb
            )
      );
      while true do
        Yojson.Safe.read_space p lb;
        Yojson.Safe.read_object_sep p lb;
        Yojson.Safe.read_space p lb;
        let f =
          fun s pos len ->
            if pos < 0 || len < 0 || pos + len > String.length s then
              invalid_arg (Printf.sprintf "out-of-bounds substring position or length: string = %S, requested position = %i, requested length = %i" s pos len);
            match len with
              | 5 -> (
                  if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'd' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' then (
                    0
                  )
                  else (
                    -1
                  )
                )
              | 7 -> (
                  if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'v' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then (
                    1
                  )
                  else (
                    -1
                  )
                )
              | _ -> (
                  -1
                )
        in
        let i = Yojson.Safe.map_ident p f lb in
        Atdgen_runtime.Oj_run.read_until_field_value p lb;
        (
          match i with
            | 0 ->
              field_added := (
                Some (
                  (
                    read__a_b_a_list_list read__k read__v
                  ) p lb
                )
              );
            | 1 ->
              field_removed := (
                Some (
                  (
                    read__a_b_a_list_list read__k read__v
                  ) p lb
                )
              );
            | _ -> (
                Yojson.Safe.skip_json p lb
              )
        );
      done;
      assert false;
    with Yojson.End_of_object -> (
        (
          {
            added = (match !field_added with Some x -> x | None -> Atdgen_runtime.Oj_run.missing_field p "added");
            removed = (match !field_removed with Some x -> x | None -> Atdgen_runtime.Oj_run.missing_field p "removed");
          }
         : ('k, 'v) diff_bucketed)
      )
)
let diff_bucketed_of_string read__k read__v s =
  read_diff_bucketed read__k read__v (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
let write__a_b_list write__a write__b = (
  Atdgen_runtime.Oj_run.write_list (
    fun ob x ->
      Buffer.add_char ob '[';
      (let x, _ = x in
      (
        write__a
      ) ob x
      );
      Buffer.add_char ob ',';
      (let _, x = x in
      (
        write__b
      ) ob x
      );
      Buffer.add_char ob ']';
  )
)
let string_of__a_b_list write__a write__b ?(len = 1024) x =
  let ob = Buffer.create len in
  write__a_b_list write__a write__b ob x;
  Buffer.contents ob
let read__a_b_list read__a read__b = (
  Atdgen_runtime.Oj_run.read_list (
    fun p lb ->
      Yojson.Safe.read_space p lb;
      Atdgen_runtime.Yojson_extra.start_any_tuple p lb;
      let len = ref 0 in
      let end_of_tuple = ref false in
      (try
        let x0 =
          let x =
            (
              read__a
            ) p lb
          in
          incr len;
          Yojson.Safe.read_space p lb;
          Atdgen_runtime.Yojson_extra.read_tuple_sep2 p lb;
          x
        in
        let x1 =
          let x =
            (
              read__b
            ) p lb
          in
          incr len;
          (try
            Yojson.Safe.read_space p lb;
            Atdgen_runtime.Yojson_extra.read_tuple_sep2 p lb;
          with Atdgen_runtime.Yojson_extra.End_of_tuple -> end_of_tuple := true);
          x
        in
        if not !end_of_tuple then (
          try
            while true do
              Yojson.Safe.skip_json p lb;
              Yojson.Safe.read_space p lb;
              Atdgen_runtime.Yojson_extra.read_tuple_sep2 p lb;
            done
          with Atdgen_runtime.Yojson_extra.End_of_tuple -> ()
        );
        (x0, x1)
      with Atdgen_runtime.Yojson_extra.End_of_tuple ->
        Atdgen_runtime.Oj_run.missing_tuple_fields p !len [ 0; 1 ]);
  )
)
let _a_b_list_of_string read__a read__b s =
  read__a_b_list read__a read__b (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
let write_diff write__k write__v : _ -> ('k, 'v) diff -> _ = (
  fun ob (x : ('k, 'v) diff) ->
    Buffer.add_char ob '{';
    let is_first = ref true in
    if !is_first then
      is_first := false
    else
      Buffer.add_char ob ',';
      Buffer.add_string ob "\"added\":";
    (
      write__a_b_list write__k write__v
    )
      ob x.added;
    if !is_first then
      is_first := false
    else
      Buffer.add_char ob ',';
      Buffer.add_string ob "\"removed\":";
    (
      write__a_b_list write__k write__v
    )
      ob x.removed;
    Buffer.add_char ob '}';
)
let string_of_diff write__k write__v ?(len = 1024) x =
  let ob = Buffer.create len in
  write_diff write__k write__v ob x;
  Buffer.contents ob
let read_diff read__k read__v = (
  fun p lb ->
    Yojson.Safe.read_space p lb;
    Yojson.Safe.read_lcurl p lb;
    let field_added = ref (None) in
    let field_removed = ref (None) in
    try
      Yojson.Safe.read_space p lb;
      Yojson.Safe.read_object_end lb;
      Yojson.Safe.read_space p lb;
      let f =
        fun s pos len ->
          if pos < 0 || len < 0 || pos + len > String.length s then
            invalid_arg (Printf.sprintf "out-of-bounds substring position or length: string = %S, requested position = %i, requested length = %i" s pos len);
          match len with
            | 5 -> (
                if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'd' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' then (
                  0
                )
                else (
                  -1
                )
              )
            | 7 -> (
                if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'v' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then (
                  1
                )
                else (
                  -1
                )
              )
            | _ -> (
                -1
              )
      in
      let i = Yojson.Safe.map_ident p f lb in
      Atdgen_runtime.Oj_run.read_until_field_value p lb;
      (
        match i with
          | 0 ->
            field_added := (
              Some (
                (
                  read__a_b_list read__k read__v
                ) p lb
              )
            );
          | 1 ->
            field_removed := (
              Some (
                (
                  read__a_b_list read__k read__v
                ) p lb
              )
            );
          | _ -> (
              Yojson.Safe.skip_json p lb
            )
      );
      while true do
        Yojson.Safe.read_space p lb;
        Yojson.Safe.read_object_sep p lb;
        Yojson.Safe.read_space p lb;
        let f =
          fun s pos len ->
            if pos < 0 || len < 0 || pos + len > String.length s then
              invalid_arg (Printf.sprintf "out-of-bounds substring position or length: string = %S, requested position = %i, requested length = %i" s pos len);
            match len with
              | 5 -> (
                  if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'd' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' then (
                    0
                  )
                  else (
                    -1
                  )
                )
              | 7 -> (
                  if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'v' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then (
                    1
                  )
                  else (
                    -1
                  )
                )
              | _ -> (
                  -1
                )
        in
        let i = Yojson.Safe.map_ident p f lb in
        Atdgen_runtime.Oj_run.read_until_field_value p lb;
        (
          match i with
            | 0 ->
              field_added := (
                Some (
                  (
                    read__a_b_list read__k read__v
                  ) p lb
                )
              );
            | 1 ->
              field_removed := (
                Some (
                  (
                    read__a_b_list read__k read__v
                  ) p lb
                )
              );
            | _ -> (
                Yojson.Safe.skip_json p lb
              )
        );
      done;
      assert false;
    with Yojson.End_of_object -> (
        (
          {
            added = (match !field_added with Some x -> x | None -> Atdgen_runtime.Oj_run.missing_field p "added");
            removed = (match !field_removed with Some x -> x | None -> Atdgen_runtime.Oj_run.missing_field p "removed");
          }
         : ('k, 'v) diff)
      )
)
let diff_of_string read__k read__v s =
  read_diff read__k read__v (Yojson.Safe.init_lexer ()) (Lexing.from_string s)