-
Notifications
You must be signed in to change notification settings - Fork 0
/
RBT_height_opt.ml
1042 lines (901 loc) · 40.9 KB
/
RBT_height_opt.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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module RBT_height : sig
type nat
val integer_of_nat : nat -> Z.t
type 'a set
val nat_of_integer : Z.t -> nat
val nat_set : nat list -> nat set
val nat_upt : nat -> nat -> nat list
val nat_sset : nat list -> nat set
val un_nat_set : nat set -> nat set -> nat set
val inter_nat_set : nat set -> nat set -> nat set
end = struct
type nat = Nat of Z.t;;
let rec integer_of_nat (Nat x) = x;;
let rec equal_nata m n = Z.equal (integer_of_nat m) (integer_of_nat n);;
type 'a equal = {equal : 'a -> 'a -> bool};;
let equal _A = _A.equal;;
let equal_nat = ({equal = equal_nata} : nat equal);;
let rec less_eq_nat m n = Z.leq (integer_of_nat m) (integer_of_nat n);;
type 'a ord = {less_eq : 'a -> 'a -> bool; less : 'a -> 'a -> bool};;
let less_eq _A = _A.less_eq;;
let less _A = _A.less;;
let rec less_nat m n = Z.lt (integer_of_nat m) (integer_of_nat n);;
let ord_nat = ({less_eq = less_eq_nat; less = less_nat} : nat ord);;
type 'a preorder = {ord_preorder : 'a ord};;
type 'a order = {preorder_order : 'a preorder};;
let preorder_nat = ({ord_preorder = ord_nat} : nat preorder);;
let order_nat = ({preorder_order = preorder_nat} : nat order);;
let ceq_nata : (nat -> nat -> bool) option = Some equal_nata;;
type 'a ceq = {ceq : ('a -> 'a -> bool) option};;
let ceq _A = _A.ceq;;
let ceq_nat = ({ceq = ceq_nata} : nat ceq);;
type ('a, 'b) phantom = Phantom of 'b;;
type set_impla = Set_Choose | Set_Collect | Set_DList | Set_RBT | Set_Monada;;
let set_impl_nata : (nat, set_impla) phantom = Phantom Set_RBT;;
type 'a set_impl = {set_impl : ('a, set_impla) phantom};;
let set_impl _A = _A.set_impl;;
let set_impl_nat = ({set_impl = set_impl_nata} : nat set_impl);;
type 'a linorder = {order_linorder : 'a order};;
let linorder_nat = ({order_linorder = order_nat} : nat linorder);;
type ordera = Eq | Lt | Gt;;
let rec eq _A a b = equal _A a b;;
let rec comparator_of (_A1, _A2)
x y = (if less _A2.order_linorder.preorder_order.ord_preorder x y then Lt
else (if eq _A1 x y then Eq else Gt));;
let rec compare_nat x = comparator_of (equal_nat, linorder_nat) x;;
let ccompare_nata : (nat -> nat -> ordera) option = Some compare_nat;;
type 'a ccompare = {ccompare : ('a -> 'a -> ordera) option};;
let ccompare _A = _A.ccompare;;
let ccompare_nat = ({ccompare = ccompare_nata} : nat ccompare);;
let rec equal_unita u v = true;;
let equal_unit = ({equal = equal_unita} : unit equal);;
let ord_integer = ({less_eq = Z.leq; less = Z.lt} : Z.t ord);;
type num = One | Bit0 of num | Bit1 of num;;
type color = R | B;;
type ('a, 'b) rbt = Empty |
Branch of color * ('a, 'b) rbt * 'a * 'b * ('a, 'b) rbt;;
type ('b, 'a) mapping_rbt = Mapping_RBT of ('b, 'a) rbt;;
type 'a set_dlist = Abs_dlist of 'a list;;
type 'a set = Collect_set of ('a -> bool) | DList_set of 'a set_dlist |
RBT_set of ('a, unit) mapping_rbt | Set_Monad of 'a list |
Complement of 'a set;;
type 'a sdlist = Abs_sdlist of 'a list;;
let rec plus_nat m n = Nat (Z.add (integer_of_nat m) (integer_of_nat n));;
let one_nat : nat = Nat (Z.of_int 1);;
let rec suc n = plus_nat n one_nat;;
let rec comp f g = (fun x -> f (g x));;
let rec upt i j = (if less_nat i j then i :: upt (suc i) j else []);;
let rec fold f x1 s = match f, x1, s with f, x :: xs, s -> fold f xs (f x s)
| f, [], s -> s;;
let rec foldl f a x2 = match f, a, x2 with f, a, [] -> a
| f, a, x :: xs -> foldl f (f a x) xs;;
let rec fun_upd equal f aa b a = (if equal aa a then b else f a);;
let rec balance
x0 s t x3 = match x0, s, t, x3 with
Branch (R, a, w, x, b), s, t, Branch (R, c, y, z, d) ->
Branch (R, Branch (B, a, w, x, b), s, t, Branch (B, c, y, z, d))
| Branch (R, Branch (R, a, w, x, b), s, t, c), y, z, Empty ->
Branch (R, Branch (B, a, w, x, b), s, t, Branch (B, c, y, z, Empty))
| Branch (R, Branch (R, a, w, x, b), s, t, c), y, z,
Branch (B, va, vb, vc, vd)
-> Branch
(R, Branch (B, a, w, x, b), s, t,
Branch (B, c, y, z, Branch (B, va, vb, vc, vd)))
| Branch (R, Empty, w, x, Branch (R, b, s, t, c)), y, z, Empty ->
Branch (R, Branch (B, Empty, w, x, b), s, t, Branch (B, c, y, z, Empty))
| Branch (R, Branch (B, va, vb, vc, vd), w, x, Branch (R, b, s, t, c)), y,
z, Empty
-> Branch
(R, Branch (B, Branch (B, va, vb, vc, vd), w, x, b), s, t,
Branch (B, c, y, z, Empty))
| Branch (R, Empty, w, x, Branch (R, b, s, t, c)), y, z,
Branch (B, va, vb, vc, vd)
-> Branch
(R, Branch (B, Empty, w, x, b), s, t,
Branch (B, c, y, z, Branch (B, va, vb, vc, vd)))
| Branch (R, Branch (B, ve, vf, vg, vh), w, x, Branch (R, b, s, t, c)), y,
z, Branch (B, va, vb, vc, vd)
-> Branch
(R, Branch (B, Branch (B, ve, vf, vg, vh), w, x, b), s, t,
Branch (B, c, y, z, Branch (B, va, vb, vc, vd)))
| Empty, w, x, Branch (R, b, s, t, Branch (R, c, y, z, d)) ->
Branch (R, Branch (B, Empty, w, x, b), s, t, Branch (B, c, y, z, d))
| Branch (B, va, vb, vc, vd), w, x,
Branch (R, b, s, t, Branch (R, c, y, z, d))
-> Branch
(R, Branch (B, Branch (B, va, vb, vc, vd), w, x, b), s, t,
Branch (B, c, y, z, d))
| Empty, w, x, Branch (R, Branch (R, b, s, t, c), y, z, Empty) ->
Branch (R, Branch (B, Empty, w, x, b), s, t, Branch (B, c, y, z, Empty))
| Empty, w, x,
Branch (R, Branch (R, b, s, t, c), y, z, Branch (B, va, vb, vc, vd))
-> Branch
(R, Branch (B, Empty, w, x, b), s, t,
Branch (B, c, y, z, Branch (B, va, vb, vc, vd)))
| Branch (B, va, vb, vc, vd), w, x,
Branch (R, Branch (R, b, s, t, c), y, z, Empty)
-> Branch
(R, Branch (B, Branch (B, va, vb, vc, vd), w, x, b), s, t,
Branch (B, c, y, z, Empty))
| Branch (B, va, vb, vc, vd), w, x,
Branch (R, Branch (R, b, s, t, c), y, z, Branch (B, ve, vf, vg, vh))
-> Branch
(R, Branch (B, Branch (B, va, vb, vc, vd), w, x, b), s, t,
Branch (B, c, y, z, Branch (B, ve, vf, vg, vh)))
| Empty, s, t, Empty -> Branch (B, Empty, s, t, Empty)
| Empty, s, t, Branch (B, va, vb, vc, vd) ->
Branch (B, Empty, s, t, Branch (B, va, vb, vc, vd))
| Empty, s, t, Branch (v, Empty, vb, vc, Empty) ->
Branch (B, Empty, s, t, Branch (v, Empty, vb, vc, Empty))
| Empty, s, t, Branch (v, Branch (B, ve, vf, vg, vh), vb, vc, Empty) ->
Branch
(B, Empty, s, t,
Branch (v, Branch (B, ve, vf, vg, vh), vb, vc, Empty))
| Empty, s, t, Branch (v, Empty, vb, vc, Branch (B, vf, vg, vh, vi)) ->
Branch
(B, Empty, s, t,
Branch (v, Empty, vb, vc, Branch (B, vf, vg, vh, vi)))
| Empty, s, t,
Branch
(v, Branch (B, ve, vj, vk, vl), vb, vc, Branch (B, vf, vg, vh, vi))
-> Branch
(B, Empty, s, t,
Branch
(v, Branch (B, ve, vj, vk, vl), vb, vc,
Branch (B, vf, vg, vh, vi)))
| Branch (B, va, vb, vc, vd), s, t, Empty ->
Branch (B, Branch (B, va, vb, vc, vd), s, t, Empty)
| Branch (B, va, vb, vc, vd), s, t, Branch (B, ve, vf, vg, vh) ->
Branch (B, Branch (B, va, vb, vc, vd), s, t, Branch (B, ve, vf, vg, vh))
| Branch (B, va, vb, vc, vd), s, t, Branch (v, Empty, vf, vg, Empty) ->
Branch
(B, Branch (B, va, vb, vc, vd), s, t,
Branch (v, Empty, vf, vg, Empty))
| Branch (B, va, vb, vc, vd), s, t,
Branch (v, Branch (B, vi, vj, vk, vl), vf, vg, Empty)
-> Branch
(B, Branch (B, va, vb, vc, vd), s, t,
Branch (v, Branch (B, vi, vj, vk, vl), vf, vg, Empty))
| Branch (B, va, vb, vc, vd), s, t,
Branch (v, Empty, vf, vg, Branch (B, vj, vk, vl, vm))
-> Branch
(B, Branch (B, va, vb, vc, vd), s, t,
Branch (v, Empty, vf, vg, Branch (B, vj, vk, vl, vm)))
| Branch (B, va, vb, vc, vd), s, t,
Branch
(v, Branch (B, vi, vn, vo, vp), vf, vg, Branch (B, vj, vk, vl, vm))
-> Branch
(B, Branch (B, va, vb, vc, vd), s, t,
Branch
(v, Branch (B, vi, vn, vo, vp), vf, vg,
Branch (B, vj, vk, vl, vm)))
| Branch (v, Empty, vb, vc, Empty), s, t, Empty ->
Branch (B, Branch (v, Empty, vb, vc, Empty), s, t, Empty)
| Branch (v, Empty, vb, vc, Branch (B, ve, vf, vg, vh)), s, t, Empty ->
Branch
(B, Branch (v, Empty, vb, vc, Branch (B, ve, vf, vg, vh)), s, t,
Empty)
| Branch (v, Branch (B, vf, vg, vh, vi), vb, vc, Empty), s, t, Empty ->
Branch
(B, Branch (v, Branch (B, vf, vg, vh, vi), vb, vc, Empty), s, t,
Empty)
| Branch
(v, Branch (B, vf, vg, vh, vi), vb, vc, Branch (B, ve, vj, vk, vl)),
s, t, Empty
-> Branch
(B, Branch
(v, Branch (B, vf, vg, vh, vi), vb, vc,
Branch (B, ve, vj, vk, vl)),
s, t, Empty)
| Branch (v, Empty, vf, vg, Empty), s, t, Branch (B, va, vb, vc, vd) ->
Branch
(B, Branch (v, Empty, vf, vg, Empty), s, t,
Branch (B, va, vb, vc, vd))
| Branch (v, Empty, vf, vg, Branch (B, vi, vj, vk, vl)), s, t,
Branch (B, va, vb, vc, vd)
-> Branch
(B, Branch (v, Empty, vf, vg, Branch (B, vi, vj, vk, vl)), s, t,
Branch (B, va, vb, vc, vd))
| Branch (v, Branch (B, vj, vk, vl, vm), vf, vg, Empty), s, t,
Branch (B, va, vb, vc, vd)
-> Branch
(B, Branch (v, Branch (B, vj, vk, vl, vm), vf, vg, Empty), s, t,
Branch (B, va, vb, vc, vd))
| Branch
(v, Branch (B, vj, vk, vl, vm), vf, vg, Branch (B, vi, vn, vo, vp)),
s, t, Branch (B, va, vb, vc, vd)
-> Branch
(B, Branch
(v, Branch (B, vj, vk, vl, vm), vf, vg,
Branch (B, vi, vn, vo, vp)),
s, t, Branch (B, va, vb, vc, vd));;
let rec rbt_comp_ins
c f k v x4 = match c, f, k, v, x4 with
c, f, k, v, Empty -> Branch (R, Empty, k, v, Empty)
| c, f, k, v, Branch (B, l, x, y, r) ->
(match c k x with Eq -> Branch (B, l, x, f k y v, r)
| Lt -> balance (rbt_comp_ins c f k v l) x y r
| Gt -> balance l x y (rbt_comp_ins c f k v r))
| c, f, k, v, Branch (R, l, x, y, r) ->
(match c k x with Eq -> Branch (R, l, x, f k y v, r)
| Lt -> Branch (R, rbt_comp_ins c f k v l, x, y, r)
| Gt -> Branch (R, l, x, y, rbt_comp_ins c f k v r));;
let rec paint c x1 = match c, x1 with c, Empty -> Empty
| c, Branch (uu, l, k, v, r) -> Branch (c, l, k, v, r);;
let rec rbt_comp_insert_with_key c f k v t = paint B (rbt_comp_ins c f k v t);;
let rec rbt_comp_insert c = rbt_comp_insert_with_key c (fun _ _ nv -> nv);;
let rec impl_of _B (Mapping_RBT x) = x;;
let rec the (Some x2) = x2;;
let rec insertb _A
xc xd xe =
Mapping_RBT (rbt_comp_insert (the (ccompare _A)) xc xd (impl_of _A xe));;
let rec list_of_dlist _A (Abs_dlist x) = x;;
let rec list_member
equal x1 y = match equal, x1, y with
equal, x :: xs, y -> equal x y || list_member equal xs y
| equal, [], y -> false;;
let rec list_insert
equal x xs = (if list_member equal xs x then xs else x :: xs);;
let rec inserta _A
xb xc = Abs_dlist (list_insert (the (ceq _A)) xb (list_of_dlist _A xc));;
let rec balance_right
a k x xa3 = match a, k, x, xa3 with
a, k, x, Branch (R, b, s, y, c) ->
Branch (R, a, k, x, Branch (B, b, s, y, c))
| Branch (B, a, k, x, b), s, y, Empty ->
balance (Branch (R, a, k, x, b)) s y Empty
| Branch (B, a, k, x, b), s, y, Branch (B, va, vb, vc, vd) ->
balance (Branch (R, a, k, x, b)) s y (Branch (B, va, vb, vc, vd))
| Branch (R, a, k, x, Branch (B, b, s, y, c)), t, z, Empty ->
Branch (R, balance (paint R a) k x b, s, y, Branch (B, c, t, z, Empty))
| Branch (R, a, k, x, Branch (B, b, s, y, c)), t, z,
Branch (B, va, vb, vc, vd)
-> Branch
(R, balance (paint R a) k x b, s, y,
Branch (B, c, t, z, Branch (B, va, vb, vc, vd)))
| Empty, k, x, Empty -> Empty
| Branch (R, va, vb, vc, Empty), k, x, Empty -> Empty
| Branch (R, va, vb, vc, Branch (R, ve, vf, vg, vh)), k, x, Empty -> Empty
| Empty, k, x, Branch (B, va, vb, vc, vd) -> Empty
| Branch (R, ve, vf, vg, Empty), k, x, Branch (B, va, vb, vc, vd) -> Empty
| Branch (R, ve, vf, vg, Branch (R, vi, vj, vk, vl)), k, x,
Branch (B, va, vb, vc, vd)
-> Empty;;
let rec balance_left
x0 s y c = match x0, s, y, c with
Branch (R, a, k, x, b), s, y, c ->
Branch (R, Branch (B, a, k, x, b), s, y, c)
| Empty, k, x, Branch (B, a, s, y, b) ->
balance Empty k x (Branch (R, a, s, y, b))
| Branch (B, va, vb, vc, vd), k, x, Branch (B, a, s, y, b) ->
balance (Branch (B, va, vb, vc, vd)) k x (Branch (R, a, s, y, b))
| Empty, k, x, Branch (R, Branch (B, a, s, y, b), t, z, c) ->
Branch (R, Branch (B, Empty, k, x, a), s, y, balance b t z (paint R c))
| Branch (B, va, vb, vc, vd), k, x,
Branch (R, Branch (B, a, s, y, b), t, z, c)
-> Branch
(R, Branch (B, Branch (B, va, vb, vc, vd), k, x, a), s, y,
balance b t z (paint R c))
| Empty, k, x, Empty -> Empty
| Empty, k, x, Branch (R, Empty, vb, vc, vd) -> Empty
| Empty, k, x, Branch (R, Branch (R, ve, vf, vg, vh), vb, vc, vd) -> Empty
| Branch (B, va, vb, vc, vd), k, x, Empty -> Empty
| Branch (B, va, vb, vc, vd), k, x, Branch (R, Empty, vf, vg, vh) -> Empty
| Branch (B, va, vb, vc, vd), k, x,
Branch (R, Branch (R, vi, vj, vk, vl), vf, vg, vh)
-> Empty;;
let rec combine
xa0 x = match xa0, x with Empty, x -> x
| Branch (v, va, vb, vc, vd), Empty -> Branch (v, va, vb, vc, vd)
| Branch (R, a, k, x, b), Branch (R, c, s, y, d) ->
(match combine b c
with Empty -> Branch (R, a, k, x, Branch (R, Empty, s, y, d))
| Branch (R, b2, t, z, c2) ->
Branch (R, Branch (R, a, k, x, b2), t, z, Branch (R, c2, s, y, d))
| Branch (B, b2, t, z, c2) ->
Branch (R, a, k, x, Branch (R, Branch (B, b2, t, z, c2), s, y, d)))
| Branch (B, a, k, x, b), Branch (B, c, s, y, d) ->
(match combine b c
with Empty -> balance_left a k x (Branch (B, Empty, s, y, d))
| Branch (R, b2, t, z, c2) ->
Branch (R, Branch (B, a, k, x, b2), t, z, Branch (B, c2, s, y, d))
| Branch (B, b2, t, z, c2) ->
balance_left a k x (Branch (B, Branch (B, b2, t, z, c2), s, y, d)))
| Branch (B, va, vb, vc, vd), Branch (R, b, k, x, c) ->
Branch (R, combine (Branch (B, va, vb, vc, vd)) b, k, x, c)
| Branch (R, a, k, x, b), Branch (B, va, vb, vc, vd) ->
Branch (R, a, k, x, combine b (Branch (B, va, vb, vc, vd)));;
let rec rbt_comp_del
c x xa2 = match c, x, xa2 with c, x, Empty -> Empty
| c, x, Branch (uu, a, y, s, b) ->
(match c x y with Eq -> combine a b
| Lt -> rbt_comp_del_from_left c x a y s b
| Gt -> rbt_comp_del_from_right c x a y s b)
and rbt_comp_del_from_left
c x xa2 y s b = match c, x, xa2, y, s, b with
c, x, Branch (B, lt, z, v, rt), y, s, b ->
balance_left (rbt_comp_del c x (Branch (B, lt, z, v, rt))) y s b
| c, x, Empty, y, s, b -> Branch (R, rbt_comp_del c x Empty, y, s, b)
| c, x, Branch (R, va, vb, vc, vd), y, s, b ->
Branch (R, rbt_comp_del c x (Branch (R, va, vb, vc, vd)), y, s, b)
and rbt_comp_del_from_right
c x a y s xa5 = match c, x, a, y, s, xa5 with
c, x, a, y, s, Branch (B, lt, z, v, rt) ->
balance_right a y s (rbt_comp_del c x (Branch (B, lt, z, v, rt)))
| c, x, a, y, s, Empty -> Branch (R, a, y, s, rbt_comp_del c x Empty)
| c, x, a, y, s, Branch (R, va, vb, vc, vd) ->
Branch (R, a, y, s, rbt_comp_del c x (Branch (R, va, vb, vc, vd)));;
let rec rbt_comp_delete c k t = paint B (rbt_comp_del c k t);;
let rec delete _A
xb xc = Mapping_RBT (rbt_comp_delete (the (ccompare _A)) xb (impl_of _A xc));;
let rec list_remove1
equal x xa2 = match equal, x, xa2 with
equal, x, y :: xs ->
(if equal x y then xs else y :: list_remove1 equal x xs)
| equal, x, [] -> [];;
let rec removea _A
xb xc = Abs_dlist (list_remove1 (the (ceq _A)) xb (list_of_dlist _A xc));;
let rec insert (_A1, _A2)
xa x1 = match xa, x1 with
xa, Complement x -> Complement (remove (_A1, _A2) xa x)
| x, RBT_set rbt ->
(match ccompare _A2
with None ->
failwith "insert RBT_set: ccompare = None"
(fun _ -> insert (_A1, _A2) x (RBT_set rbt))
| Some _ -> RBT_set (insertb _A2 x () rbt))
| x, DList_set dxs ->
(match ceq _A1
with None ->
failwith "insert DList_set: ceq = None"
(fun _ -> insert (_A1, _A2) x (DList_set dxs))
| Some _ -> DList_set (inserta _A1 x dxs))
| x, Set_Monad xs -> Set_Monad (x :: xs)
| x, Collect_set a ->
(match ceq _A1
with None ->
failwith "insert Collect_set: ceq = None"
(fun _ -> insert (_A1, _A2) x (Collect_set a))
| Some eq -> Collect_set (fun_upd eq a x true))
and remove (_A1, _A2)
x xa1 = match x, xa1 with
x, Complement a -> Complement (insert (_A1, _A2) x a)
| x, RBT_set rbt ->
(match ccompare _A2
with None ->
failwith "remove RBT_set: ccompare = None"
(fun _ -> remove (_A1, _A2) x (RBT_set rbt))
| Some _ -> RBT_set (delete _A2 x rbt))
| x, DList_set dxs ->
(match ceq _A1
with None ->
failwith "remove DList_set: ceq = None"
(fun _ -> remove (_A1, _A2) x (DList_set dxs))
| Some _ -> DList_set (removea _A1 x dxs))
| x, Collect_set a ->
(match ceq _A1
with None ->
failwith "remove Collect: ceq = None"
(fun _ -> remove (_A1, _A2) x (Collect_set a))
| Some eq -> Collect_set (fun_upd eq a x false));;
let rec memberb _A xa = list_member (the (ceq _A)) (list_of_dlist _A xa);;
let rec equal_option _A x0 x1 = match x0, x1 with None, Some x2 -> false
| Some x2, None -> false
| Some x2, Some y2 -> eq _A x2 y2
| None, None -> true;;
let rec rbt_comp_lookup
c x1 k = match c, x1, k with c, Empty, k -> None
| c, Branch (uu, l, x, y, r), k ->
(match c k x with Eq -> Some y | Lt -> rbt_comp_lookup c l k
| Gt -> rbt_comp_lookup c r k);;
let rec lookup _A xa = rbt_comp_lookup (the (ccompare _A)) (impl_of _A xa);;
let rec membera _A t x = equal_option equal_unit (lookup _A t x) (Some ());;
let rec member (_A1, _A2)
x xa1 = match x, xa1 with
x, Set_Monad xs ->
(match ceq _A1
with None ->
failwith "member Set_Monad: ceq = None"
(fun _ -> member (_A1, _A2) x (Set_Monad xs))
| Some eq -> list_member eq xs x)
| xa, Complement x -> not (member (_A1, _A2) xa x)
| x, RBT_set rbt -> membera _A2 rbt x
| x, DList_set dxs -> memberb _A1 dxs x
| x, Collect_set a -> a x;;
let rec filter
p x1 = match p, x1 with p, [] -> []
| p, x :: xs -> (if p x then x :: filter p xs else filter p xs);;
let rec map f x1 = match f, x1 with f, [] -> []
| f, x21 :: x22 -> f x21 :: map f x22;;
let rec of_phantom (Phantom x) = x;;
let rec emptya _A = Mapping_RBT Empty;;
let rec empty _A = Abs_dlist [];;
let rec set_empty_choose (_A1, _A2)
= (match ccompare _A2
with None ->
(match ceq _A1 with None -> Set_Monad []
| Some _ -> DList_set (empty _A1))
| Some _ -> RBT_set (emptya _A2));;
let rec set_empty (_A1, _A2)
= function Set_Choose -> set_empty_choose (_A1, _A2)
| Set_Monada -> Set_Monad []
| Set_RBT -> RBT_set (emptya _A2)
| Set_DList -> DList_set (empty _A1)
| Set_Collect -> Collect_set (fun _ -> false);;
let rec set_aux (_A1, _A2)
= function Set_Monada -> (fun a -> Set_Monad a)
| Set_Choose ->
(match ccompare _A2
with None ->
(match ceq _A1 with None -> (fun a -> Set_Monad a)
| Some _ ->
foldl (fun s x -> insert (_A1, _A2) x s)
(DList_set (empty _A1)))
| Some _ ->
foldl (fun s x -> insert (_A1, _A2) x s) (RBT_set (emptya _A2)))
| impl ->
foldl (fun s x -> insert (_A1, _A2) x s) (set_empty (_A1, _A2) impl);;
let rec set (_A1, _A2, _A3)
xs = set_aux (_A1, _A2) (of_phantom (set_impl _A3)) xs;;
let rec folda
f xa1 x = match f, xa1, x with
f, Branch (c, lt, k, v, rt), x -> folda f rt (f k v (folda f lt x))
| f, Empty, x -> x;;
let rec foldb _A x xc = fold x (list_of_dlist _A xc);;
let rec is_none = function Some x -> false
| None -> true;;
let rec union _A = foldb _A (inserta _A);;
let rec gen_length n x1 = match n, x1 with n, x :: xs -> gen_length (suc n) xs
| n, [] -> n;;
let rec map_filter
f x1 = match f, x1 with f, [] -> []
| f, x :: xs ->
(match f x with None -> map_filter f xs
| Some y -> y :: map_filter f xs);;
let rec quicksort_acc
less ac x2 = match less, ac, x2 with
less, ac, x :: v :: va -> quicksort_part less ac x [] [] [] (v :: va)
| less, ac, [x] -> x :: ac
| less, ac, [] -> ac
and quicksort_part
less ac x lts eqs gts xa6 = match less, ac, x, lts, eqs, gts, xa6 with
less, ac, x, lts, eqs, gts, z :: zs ->
(if less x z then quicksort_part less ac x lts eqs (z :: gts) zs
else (if less z x then quicksort_part less ac x (z :: lts) eqs gts zs
else quicksort_part less ac x lts (z :: eqs) gts zs))
| less, ac, x, lts, eqs, gts, [] ->
quicksort_acc less (eqs @ x :: quicksort_acc less ac gts) lts;;
let rec quicksort less = quicksort_acc less [];;
let rec lt_of_comp
acomp x y = (match acomp x y with Eq -> false | Lt -> true | Gt -> false);;
let rec remdups_adj _A
= function [] -> []
| [x] -> [x]
| x :: y :: xs ->
(if eq _A x y then remdups_adj _A (x :: xs)
else x :: remdups_adj _A (y :: xs));;
let rec sdlist_of_list (_A1, _A2)
xa = Abs_sdlist
(match ccompare _A1 with None -> []
| Some c -> remdups_adj _A2 (quicksort (lt_of_comp c) xa));;
let rec rep_sdlist _A (Abs_sdlist x) = x;;
let zero_nat : nat = Nat Z.zero;;
let rec size_list x = gen_length zero_nat x;;
let rec fst (x1, x2) = x1;;
let rec max _A a b = (if less_eq _A a b then b else a);;
let rec nat_of_integer k = Nat (max ord_integer Z.zero k);;
let rec apfst f (x, y) = (f x, y);;
let rec map_prod f g (a, b) = (f a, g b);;
let rec divmod_nat
m n = (let k = integer_of_nat m in
let l = integer_of_nat n in
map_prod nat_of_integer nat_of_integer
(if Z.equal k Z.zero then (Z.zero, Z.zero)
else (if Z.equal l Z.zero then (Z.zero, k)
else (fun k l -> if Z.equal Z.zero l then (Z.zero, l) else
Z.div_rem (Z.abs k) (Z.abs l))
k l)));;
let rec rbtreeify_g
n kvs =
(if equal_nata n zero_nat || equal_nata n one_nat then (Empty, kvs)
else (let (na, r) = divmod_nat n (nat_of_integer (Z.of_int 2)) in
(if equal_nata r zero_nat
then (let (t1, (k, v) :: kvsa) = rbtreeify_g na kvs in
apfst (fun a -> Branch (B, t1, k, v, a))
(rbtreeify_g na kvsa))
else (let (t1, (k, v) :: kvsa) = rbtreeify_f na kvs in
apfst (fun a -> Branch (B, t1, k, v, a))
(rbtreeify_g na kvsa)))))
and rbtreeify_f
n kvs =
(if equal_nata n zero_nat then (Empty, kvs)
else (if equal_nata n one_nat
then (let (k, v) :: kvsa = kvs in
(Branch (R, Empty, k, v, Empty), kvsa))
else (let (na, r) = divmod_nat n (nat_of_integer (Z.of_int 2)) in
(if equal_nata r zero_nat
then (let (t1, (k, v) :: kvsa) = rbtreeify_f na kvs in
apfst (fun a -> Branch (B, t1, k, v, a))
(rbtreeify_g na kvsa))
else (let (t1, (k, v) :: kvsa) = rbtreeify_f na kvs in
apfst (fun a -> Branch (B, t1, k, v, a))
(rbtreeify_f na kvsa))))));;
let rec rbtreeify kvs = fst (rbtreeify_g (suc (size_list kvs)) kvs);;
let rec rbt_of_sdlist _A
xa = Mapping_RBT (rbtreeify (map (fun x -> (x, ())) (rep_sdlist _A xa)));;
let rec sset (_A1, _A2)
xs = (match ccompare _A1
with None ->
failwith "sset: ccompare = None" (fun _ -> sset (_A1, _A2) xs)
| Some _ ->
RBT_set (rbt_of_sdlist _A1 (sdlist_of_list (_A1, _A2) xs)));;
let rec filtera _A xb xc = Abs_dlist (filter xb (list_of_dlist _A xc));;
let rec equal_color x0 x1 = match x0, x1 with R, B -> false
| B, R -> false
| B, B -> true
| R, R -> true;;
let rec bheight
= function Empty -> zero_nat
| Branch (c, lt, k, v, rt) ->
(if equal_color c B then suc (bheight lt) else bheight lt);;
let rec gen_entries
kvts x1 = match kvts, x1 with
kvts, Branch (c, l, k, v, r) -> gen_entries (((k, v), r) :: kvts) l
| (kv, t) :: kvts, Empty -> kv :: gen_entries kvts t
| [], Empty -> [];;
let rec entries x = gen_entries [] x;;
let rec color_of = function Empty -> B
| Branch (c, uu, uv, uw, ux) -> c;;
let rec baliL
x0 a b t4 = match x0, a, b, t4 with
Branch (R, Branch (R, t1, ab, bb, t2), aa, ba, t3), a, b, t4 ->
Branch (R, Branch (B, t1, ab, bb, t2), aa, ba, Branch (B, t3, a, b, t4))
| Branch (R, Empty, ab, bb, Branch (R, t2, aa, ba, t3)), a, b, t4 ->
Branch
(R, Branch (B, Empty, ab, bb, t2), aa, ba, Branch (B, t3, a, b, t4))
| Branch
(R, Branch (B, va, vb, vc, vd), ab, bb, Branch (R, t2, aa, ba, t3)),
a, b, t4
-> Branch
(R, Branch (B, Branch (B, va, vb, vc, vd), ab, bb, t2), aa, ba,
Branch (B, t3, a, b, t4))
| Empty, a, b, t2 -> Branch (B, Empty, a, b, t2)
| Branch (B, va, vb, vc, vd), a, b, t2 ->
Branch (B, Branch (B, va, vb, vc, vd), a, b, t2)
| Branch (v, Empty, vb, vc, Empty), a, b, t2 ->
Branch (B, Branch (v, Empty, vb, vc, Empty), a, b, t2)
| Branch (v, Empty, vb, vc, Branch (B, ve, vf, vg, vh)), a, b, t2 ->
Branch
(B, Branch (v, Empty, vb, vc, Branch (B, ve, vf, vg, vh)), a, b, t2)
| Branch (v, Branch (B, vf, vg, vh, vi), vb, vc, Empty), a, b, t2 ->
Branch
(B, Branch (v, Branch (B, vf, vg, vh, vi), vb, vc, Empty), a, b, t2)
| Branch
(v, Branch (B, vf, vg, vh, vi), vb, vc, Branch (B, ve, vj, vk, vl)),
a, b, t2
-> Branch
(B, Branch
(v, Branch (B, vf, vg, vh, vi), vb, vc,
Branch (B, ve, vj, vk, vl)),
a, b, t2);;
let rec baliR
t1 ab bb x3 = match t1, ab, bb, x3 with
t1, ab, bb, Branch (R, t2, aa, ba, Branch (R, t3, a, b, t4)) ->
Branch (R, Branch (B, t1, ab, bb, t2), aa, ba, Branch (B, t3, a, b, t4))
| t1, ab, bb, Branch (R, Branch (R, t2, aa, ba, t3), a, b, Empty) ->
Branch
(R, Branch (B, t1, ab, bb, t2), aa, ba, Branch (B, t3, a, b, Empty))
| t1, ab, bb,
Branch (R, Branch (R, t2, aa, ba, t3), a, b, Branch (B, va, vb, vc, vd))
-> Branch
(R, Branch (B, t1, ab, bb, t2), aa, ba,
Branch (B, t3, a, b, Branch (B, va, vb, vc, vd)))
| t1, a, b, Empty -> Branch (B, t1, a, b, Empty)
| t1, a, b, Branch (B, va, vb, vc, vd) ->
Branch (B, t1, a, b, Branch (B, va, vb, vc, vd))
| t1, a, b, Branch (v, Empty, vb, vc, Empty) ->
Branch (B, t1, a, b, Branch (v, Empty, vb, vc, Empty))
| t1, a, b, Branch (v, Branch (B, ve, vf, vg, vh), vb, vc, Empty) ->
Branch
(B, t1, a, b, Branch (v, Branch (B, ve, vf, vg, vh), vb, vc, Empty))
| t1, a, b, Branch (v, Empty, vb, vc, Branch (B, vf, vg, vh, vi)) ->
Branch
(B, t1, a, b, Branch (v, Empty, vb, vc, Branch (B, vf, vg, vh, vi)))
| t1, a, b,
Branch
(v, Branch (B, ve, vj, vk, vl), vb, vc, Branch (B, vf, vg, vh, vi))
-> Branch
(B, t1, a, b,
Branch
(v, Branch (B, ve, vj, vk, vl), vb, vc,
Branch (B, vf, vg, vh, vi)));;
let rec painta c x1 = match c, x1 with c, Empty -> Empty
| c, Branch (uu, l, a, b, r) -> Branch (c, l, a, b, r);;
let rec nat_set x = set (ceq_nat, ccompare_nat, set_impl_nat) x;;
let rec nat_upt i j = upt i j;;
let rec filterb _A
xb xc = Mapping_RBT (rbtreeify (filter xb (entries (impl_of _A xc))));;
let rec inter_list _A
xb xc =
Mapping_RBT
(fold (fun k -> rbt_comp_insert (the (ccompare _A)) k ())
(filter
(fun x ->
not (is_none
(rbt_comp_lookup (the (ccompare _A)) (impl_of _A xb) x)))
xc)
Empty);;
let rec nat_sset x = sset (ccompare_nat, equal_nat) x;;
let rec flip_rbt t1 t2 = less_nat (bheight t2) (bheight t1);;
let rec is_empty
t = (match t with Empty -> true | Branch (_, _, _, _, _) -> false);;
let rec rbt_joinR
l a b r =
(if less_eq_nat (bheight l) (bheight r) then Branch (R, l, a, b, r)
else (match l
with Branch (R, la, ab, ba, ra) ->
Branch (R, la, ab, ba, rbt_joinR ra a b r)
| Branch (B, la, ab, ba, ra) ->
baliR la ab ba (rbt_joinR ra a b r)));;
let rec rbt_joinL
l a b r =
(if less_eq_nat (bheight r) (bheight l) then Branch (R, l, a, b, r)
else (match r
with Branch (R, la, ab, ba, ra) ->
Branch (R, rbt_joinL l a b la, ab, ba, ra)
| Branch (B, la, ab, ba, ra) ->
baliL (rbt_joinL l a b la) ab ba ra));;
let rec rbt_join
l a b r =
(if less_nat (bheight r) (bheight l) then painta B (rbt_joinR l a b r)
else (if less_nat (bheight l) (bheight r)
then painta B (rbt_joinL l a b r) else Branch (B, l, a, b, r)));;
let rec rbt_recolor
= function
Branch (R, t1, k, v, t2) ->
(if equal_color (color_of t1) B && equal_color (color_of t2) B
then Branch (B, t1, k, v, t2) else Branch (R, t1, k, v, t2))
| Empty -> Empty
| Branch (B, va, vb, vc, vd) -> Branch (B, va, vb, vc, vd);;
let rec split_comp
comp x1 k = match comp, x1, k with comp, Empty, k -> (Empty, (None, Empty))
| comp, Branch (uu, l, a, b, r), x ->
(match comp x a with Eq -> (l, (Some b, r))
| Lt ->
(let (l1, (beta, l2)) = split_comp comp l x in
(l1, (beta, rbt_join l2 a b r)))
| Gt ->
(let (r1, (beta, r2)) = split_comp comp r x in
(rbt_join l a b r1, (beta, r2))));;
let rec small_rbt t = less_nat (bheight t) (nat_of_integer (Z.of_int 6));;
let rec union_comp
comp f t1 t2 =
(let (fa, (t1a, t2a)) =
(if flip_rbt t1 t2 then ((fun k v va -> f k va v), (t2, t1))
else (f, (t1, t2)))
in
(if small_rbt t1a then folda (rbt_comp_insert_with_key comp fa) t1a t2a
else (match t2a with Empty -> t1a
| Branch (_, l2, a, b, r2) ->
(let (l1, (beta, r1)) = split_comp comp t1a a in
rbt_join (union_comp comp fa l1 l2) a
(match beta with None -> b | Some c -> fa a b c)
(union_comp comp fa r1 r2)))));;
let rec rbt_union_rbt_join2 _A
xb xc =
Mapping_RBT
(rbt_recolor
(union_comp (the (ccompare _A)) (fun _ _ _ -> ()) (impl_of _A xb)
(impl_of _A xc)));;
let rec uminus_set = function Complement b -> b
| Collect_set p -> Collect_set (fun x -> not (p x))
| a -> Complement a;;
let rec split_min
= function Empty -> failwith "undefined"
| Branch (uu, l, a, b, r) ->
(if is_empty l then (a, (b, r))
else (let (aa, (ba, la)) = split_min l in
(aa, (ba, rbt_join la a b r))));;
let rec rbt_join2
l r = (if is_empty r then l
else (let a = split_min r in
let (aa, b) = a in
let (ba, c) = b in
rbt_join l aa ba c));;
let rec inter_comp
comp f t1 t2 =
(let (fa, (t1a, t2a)) =
(if flip_rbt t1 t2 then ((fun k v va -> f k va v), (t2, t1))
else (f, (t1, t2)))
in
(if small_rbt t1a
then rbtreeify
(map_filter
(fun (k, v) ->
(match rbt_comp_lookup comp t2a k with None -> None
| Some va -> Some (k, fa k v va)))
(entries t1a))
else (match t2a with Empty -> Empty
| Branch (_, l2, a, b, r2) ->
(let (l1, (beta, r1)) = split_comp comp t1a a in
let l = inter_comp comp fa l1 l2 in
let r = inter_comp comp fa r1 r2 in
(match beta with None -> rbt_join2 l r
| Some ba -> rbt_join l a (fa a b ba) r)))));;
let rec rbt_inter_rbt_join2 _A
xb xc =
Mapping_RBT
(rbt_recolor
(inter_comp (the (ccompare _A)) (fun _ _ _ -> ()) (impl_of _A xb)
(impl_of _A xc)));;
let rec sup_set (_A1, _A2)
ba b = match ba, b with
RBT_set t1, RBT_set t2 ->
(match ccompare _A2
with None ->
failwith "union RBT_set RBT_set: ccompare = None"
(fun _ -> sup_set (_A1, _A2) (RBT_set t1) (RBT_set t2))
| Some _ -> RBT_set (rbt_union_rbt_join2 _A2 t1 t2))
| ba, Complement b -> Complement (inf_set (_A1, _A2) (uminus_set ba) b)
| Complement ba, b -> Complement (inf_set (_A1, _A2) ba (uminus_set b))
| b, Collect_set a -> Collect_set (fun x -> a x || member (_A1, _A2) x b)
| Collect_set a, b -> Collect_set (fun x -> a x || member (_A1, _A2) x b)
| Set_Monad xs, Set_Monad ys -> Set_Monad (xs @ ys)
| DList_set dxs1, Set_Monad ws ->
(match ceq _A1
with None ->
failwith "union DList_set Set_Monad: ceq = None"
(fun _ -> sup_set (_A1, _A2) (DList_set dxs1) (Set_Monad ws))
| Some _ -> DList_set (fold (inserta _A1) ws dxs1))
| Set_Monad ws, DList_set dxs2 ->
(match ceq _A1
with None ->
failwith "union Set_Monad DList_set: ceq = None"
(fun _ -> sup_set (_A1, _A2) (Set_Monad ws) (DList_set dxs2))
| Some _ -> DList_set (fold (inserta _A1) ws dxs2))
| RBT_set rbt1, Set_Monad zs ->
(match ccompare _A2
with None ->
failwith "union RBT_set Set_Monad: ccompare = None"
(fun _ -> sup_set (_A1, _A2) (RBT_set rbt1) (Set_Monad zs))
| Some _ -> RBT_set (fold (fun k -> insertb _A2 k ()) zs rbt1))
| Set_Monad zs, RBT_set rbt2 ->
(match ccompare _A2
with None ->
failwith "union Set_Monad RBT_set: ccompare = None"
(fun _ -> sup_set (_A1, _A2) (Set_Monad zs) (RBT_set rbt2))
| Some _ -> RBT_set (fold (fun k -> insertb _A2 k ()) zs rbt2))
| DList_set dxs1, DList_set dxs2 ->
(match ceq _A1
with None ->
failwith "union DList_set DList_set: ceq = None"
(fun _ -> sup_set (_A1, _A2) (DList_set dxs1) (DList_set dxs2))
| Some _ -> DList_set (union _A1 dxs1 dxs2))
| DList_set dxs, RBT_set rbt ->
(match ccompare _A2
with None ->
failwith "union DList_set RBT_set: ccompare = None"
(fun _ -> sup_set (_A1, _A2) (RBT_set rbt) (DList_set dxs))
| Some _ ->
(match ceq _A1
with None ->
failwith "union DList_set RBT_set: ceq = None"
(fun _ -> sup_set (_A1, _A2) (RBT_set rbt) (DList_set dxs))
| Some _ ->
RBT_set (foldb _A1 (fun k -> insertb _A2 k ()) dxs rbt)))
| RBT_set rbt, DList_set dxs ->
(match ccompare _A2
with None ->
failwith "union RBT_set DList_set: ccompare = None"
(fun _ -> sup_set (_A1, _A2) (RBT_set rbt) (DList_set dxs))
| Some _ ->
(match ceq _A1
with None ->
failwith "union RBT_set DList_set: ceq = None"
(fun _ -> sup_set (_A1, _A2) (RBT_set rbt) (DList_set dxs))
| Some _ ->
RBT_set (foldb _A1 (fun k -> insertb _A2 k ()) dxs rbt)))
and inf_set (_A1, _A2)
g ga = match g, ga with
RBT_set t1, RBT_set t2 ->
(match ccompare _A2
with None ->
failwith "inter RBT_set RBT_set: ccompare = None"
(fun _ -> inf_set (_A1, _A2) (RBT_set t1) (RBT_set t2))
| Some _ -> RBT_set (rbt_inter_rbt_join2 _A2 t1 t2))
| RBT_set rbt1, Set_Monad xs ->
(match ccompare _A2
with None ->
failwith "inter RBT_set Set_Monad: ccompare = None"
(fun _ -> inf_set (_A1, _A2) (RBT_set rbt1) (Set_Monad xs))
| Some _ -> RBT_set (inter_list _A2 rbt1 xs))
| RBT_set rbt, DList_set dxs ->
(match ccompare _A2
with None ->
failwith "inter RBT_set DList_set: ccompare = None"
(fun _ -> inf_set (_A1, _A2) (RBT_set rbt) (DList_set dxs))
| Some _ ->
(match ceq _A1
with None ->
failwith "inter RBT_set DList_set: ceq = None"
(fun _ -> inf_set (_A1, _A2) (RBT_set rbt) (DList_set dxs))
| Some _ -> RBT_set (inter_list _A2 rbt (list_of_dlist _A1 dxs))))
| DList_set dxs1, Set_Monad xs ->
(match ceq _A1
with None ->
failwith "inter DList_set Set_Monad: ceq = None"
(fun _ -> inf_set (_A1, _A2) (DList_set dxs1) (Set_Monad xs))
| Some eq -> DList_set (filtera _A1 (list_member eq xs) dxs1))
| DList_set dxs1, DList_set dxs2 ->
(match ceq _A1
with None ->
failwith "inter DList_set DList_set: ceq = None"
(fun _ -> inf_set (_A1, _A2) (DList_set dxs1) (DList_set dxs2))
| Some _ -> DList_set (filtera _A1 (memberb _A1 dxs2) dxs1))
| DList_set dxs, RBT_set rbt ->
(match ccompare _A2
with None ->
failwith "inter DList_set RBT_set: ccompare = None"
(fun _ -> inf_set (_A1, _A2) (DList_set dxs) (RBT_set rbt))
| Some _ ->
(match ceq _A1
with None ->
failwith "inter DList_set RBT_set: ceq = None"
(fun _ -> inf_set (_A1, _A2) (DList_set dxs) (RBT_set rbt))
| Some _ -> RBT_set (inter_list _A2 rbt (list_of_dlist _A1 dxs))))
| Set_Monad xs1, Set_Monad xs2 ->
(match ceq _A1
with None ->
failwith "inter Set_Monad Set_Monad: ceq = None"
(fun _ -> inf_set (_A1, _A2) (Set_Monad xs1) (Set_Monad xs2))
| Some eq -> Set_Monad (filter (list_member eq xs2) xs1))
| Set_Monad xs, DList_set dxs2 ->
(match ceq _A1
with None ->
failwith "inter Set_Monad DList_set: ceq = None"
(fun _ -> inf_set (_A1, _A2) (Set_Monad xs) (DList_set dxs2))
| Some eq -> DList_set (filtera _A1 (list_member eq xs) dxs2))
| Set_Monad xs, RBT_set rbt1 ->
(match ccompare _A2
with None ->
failwith "inter Set_Monad RBT_set: ccompare = None"
(fun _ -> inf_set (_A1, _A2) (RBT_set rbt1) (Set_Monad xs))