Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Deepcopy/OCaml/deepcopy-1.ocaml
Normal file
16
Task/Deepcopy/OCaml/deepcopy-1.ocaml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
let rec copy t =
|
||||
if Obj.is_int t then t else
|
||||
let tag = Obj.tag t in
|
||||
if tag = Obj.double_tag then t else
|
||||
if tag = Obj.closure_tag then t else
|
||||
if tag = Obj.string_tag then Obj.repr (String.copy (Obj.obj t)) else
|
||||
if tag = 0 || tag = Obj.double_array_tag then begin
|
||||
let size = Obj.size t in
|
||||
let r = Obj.new_block tag size in
|
||||
for i = 0 to pred size do
|
||||
Obj.set_field r i (copy (Obj.field t i))
|
||||
done;
|
||||
r
|
||||
end else failwith "copy" ;;
|
||||
|
||||
let copy (v : 'a) : 'a = Obj.obj (copy (Obj.repr v))
|
||||
3
Task/Deepcopy/OCaml/deepcopy-2.ocaml
Normal file
3
Task/Deepcopy/OCaml/deepcopy-2.ocaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
let copy h =
|
||||
{ size = h.size;
|
||||
data = Array.copy h.data }
|
||||
Loading…
Add table
Add a link
Reference in a new issue