Skip to content

Commit cc5bbca

Browse files
committed
add copy for all mutable data structures, address comments
1 parent d8e7e00 commit cc5bbca

12 files changed

+38
-13
lines changed

jscomp/others/bs_HashMap.mli

+2-9
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,13 @@ val remove:
5757
('a, 'b, 'id) t
5858

5959
val forEach: ('a, 'b, 'id) t -> ('a -> 'b -> unit [@bs]) -> unit
60-
(** [Hashtbl.iter f tbl] applies [f] to all bindings in table [tbl].
60+
(** [forEach tbl f] applies [f] to all bindings in table [tbl].
6161
[f] receives the key as first argument, and the associated value
6262
as second argument. Each binding is presented exactly once to [f].
6363
64-
The order in which the bindings are passed to [f] is unspecified.
65-
However, if the table contains several bindings for the same key,
66-
they are passed to [f] in reverse order of introduction, that is,
67-
the most recent binding is passed first.
68-
6964
If the hash table was created in non-randomized mode, the order
7065
in which the bindings are enumerated is reproducible between
71-
successive runs of the program, and even between minor versions
72-
of OCaml. For randomized hash tables, the order of enumeration
73-
is entirely random. *)
66+
successive runs of the program. *)
7467

7568

7669
val reduce: ('a, 'b, 'id) t -> 'c -> ('c -> 'a -> 'b -> 'c [@bs]) -> 'c

jscomp/others/bs_SetIntM.ml

+2
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,5 @@ let union (dataa : t) (datab : t) : t =
336336
t ~data:(N.ofSortedArrayAux tmp2 0 k)
337337

338338
let has d x = I.mem (data d) x
339+
340+
let copy d = t ~data:(N.copy (data d))

jscomp/others/bs_SetIntM.mli

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ type t
3131
val empty: unit -> t
3232
val singleton: elt -> t
3333
val ofArray: elt array -> t
34-
val ofSortedArrayUnsafe: elt array -> t
34+
val ofSortedArrayUnsafe: elt array -> t
35+
val copy: t -> t
3536
val isEmpty: t -> bool
3637
val has: t -> elt -> bool
3738

jscomp/others/bs_SetM.ml

+1
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,4 @@ let union (type elt) (type id) (a : (elt,id) t) b =
353353
let k = S.union tmp 0 sizea tmp sizea sizeb tmp2 0 p in
354354
B.bag ~data:(N.ofSortedArrayAux tmp2 0 k) ~dict
355355

356+
let copy d = B.bag ~data:(N.copy (B.data d)) ~dict:(B.dict d)

jscomp/others/bs_SetM.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ val empty: dict:('elt, 'id) Bs_Cmp.t -> ('elt, 'id) t
3030
val singleton: 'elt -> dict:('elt,'id) Bs_Cmp.t -> ('elt, 'id) t
3131
val ofArray: 'k array -> dict:('k, 'id) Bs_Cmp.t -> ('k, 'id) t
3232
val ofSortedArrayUnsafe: 'elt array -> dict:('elt, 'id) Bs_Cmp.t -> ('elt,'id) t
33-
33+
val copy: ('k, 'id) t -> ('k, 'id) t
3434
val isEmpty: _ t -> bool
3535
val has: ('elt, _) t -> 'elt -> bool
3636

jscomp/others/bs_SetStringM.ml

+2
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,5 @@ let union (dataa : t) (datab : t) : t =
336336
t ~data:(N.ofSortedArrayAux tmp2 0 k)
337337

338338
let has d x = I.mem (data d) x
339+
340+
let copy d = t ~data:(N.copy (data d))

jscomp/others/bs_SetStringM.mli

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ type t
3131
val empty: unit -> t
3232
val singleton: elt -> t
3333
val ofArray: elt array -> t
34-
val ofSortedArrayUnsafe: elt array -> t
34+
val ofSortedArrayUnsafe: elt array -> t
35+
val copy: t -> t
3536
val isEmpty: t -> bool
3637
val has: t -> elt -> bool
3738

jscomp/others/setm.cppo.ml

+2
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,5 @@ let union (dataa : t) (datab : t) : t =
341341
t ~data:(N.ofSortedArrayAux tmp2 0 k)
342342

343343
let has d x = I.mem (data d) x
344+
345+
let copy d = t ~data:(N.copy (data d))

jscomp/others/setm.cppo.mli

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ type t
3434
val empty: unit -> t
3535
val singleton: elt -> t
3636
val ofArray: elt array -> t
37-
val ofSortedArrayUnsafe: elt array -> t
37+
val ofSortedArrayUnsafe: elt array -> t
38+
val copy: t -> t
3839
val isEmpty: t -> bool
3940
val has: t -> elt -> bool
4041

lib/js/bs_SetIntM.js

+7
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,17 @@ function has(d, x) {
490490
return Bs_internalSetInt.mem(d.data, x);
491491
}
492492

493+
function copy(d) {
494+
return {
495+
data: Bs_internalAVLset.copy(d.data)
496+
};
497+
}
498+
493499
exports.empty = empty;
494500
exports.singleton = singleton;
495501
exports.ofArray = ofArray;
496502
exports.ofSortedArrayUnsafe = ofSortedArrayUnsafe;
503+
exports.copy = copy;
497504
exports.isEmpty = isEmpty;
498505
exports.has = has;
499506
exports.addDone = addDone;

lib/js/bs_SetM.js

+8
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,18 @@ function union(a, b) {
535535
}
536536
}
537537

538+
function copy(d) {
539+
return {
540+
dict: d.dict,
541+
data: Bs_internalAVLset.copy(d.data)
542+
};
543+
}
544+
538545
exports.empty = empty;
539546
exports.singleton = singleton;
540547
exports.ofArray = ofArray;
541548
exports.ofSortedArrayUnsafe = ofSortedArrayUnsafe;
549+
exports.copy = copy;
542550
exports.isEmpty = isEmpty;
543551
exports.has = has;
544552
exports.addDone = addDone;

lib/js/bs_SetStringM.js

+7
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,17 @@ function has(d, x) {
490490
return Bs_internalSetString.mem(d.data, x);
491491
}
492492

493+
function copy(d) {
494+
return {
495+
data: Bs_internalAVLset.copy(d.data)
496+
};
497+
}
498+
493499
exports.empty = empty;
494500
exports.singleton = singleton;
495501
exports.ofArray = ofArray;
496502
exports.ofSortedArrayUnsafe = ofSortedArrayUnsafe;
503+
exports.copy = copy;
497504
exports.isEmpty = isEmpty;
498505
exports.has = has;
499506
exports.addDone = addDone;

0 commit comments

Comments
 (0)