aboutsummaryrefslogtreecommitdiff
path: root/comparison/OCaml
diff options
context:
space:
mode:
authorShinya Sato <shinnya.sato@gmail.com>2022-05-02 09:50:21 +0900
committerShinya Sato <shinnya.sato@gmail.com>2022-05-02 09:50:21 +0900
commitdf4949f8b08cbe3cfd99933d5bb14a373f47f2dd (patch)
treec516c3c45d79a4843114ddd44a83b9ca87250cb7 /comparison/OCaml
parent7ea48cd96551247ecc763a5e42404ffa3464d0b0 (diff)
parent779860e35f5c67c7fd48ef876784f87afcfdb321 (diff)
downloadinpla-df4949f8b08cbe3cfd99933d5bb14a373f47f2dd.tar.gz
inpla-df4949f8b08cbe3cfd99933d5bb14a373f47f2dd.zip
Merge branch 'develop'
Diffstat (limited to 'comparison/OCaml')
-rw-r--r--comparison/OCaml/Makefile7
-rw-r--r--comparison/OCaml/bsort40000.ml12
-rw-r--r--comparison/OCaml/isort40000.ml4
-rw-r--r--comparison/OCaml/msort260000.ml49
-rw-r--r--comparison/OCaml/qsort260000.ml38
5 files changed, 101 insertions, 9 deletions
diff --git a/comparison/OCaml/Makefile b/comparison/OCaml/Makefile
index 94a4ffb..d300b15 100644
--- a/comparison/OCaml/Makefile
+++ b/comparison/OCaml/Makefile
@@ -1,8 +1,7 @@
CC = ocamlopt
CFLAGS =
BENCHMARK = bash ../tools/sptest_commands.sh
-#TARGET = ack3_11 fib38 bsort40000 isort40000 qsort800000 msort800000
-TARGET = ack3_11 fib38 bsort40000 isort40000
+TARGET = ack3_11 fib38 bsort40000 isort40000 qsort260000 msort260000
LOG = log.txt
@@ -25,10 +24,10 @@ bsort40000: bsort40000.ml
isort40000: isort40000.ml
$(CC) $(CFLAGS) $< -o $@
-qsort800000: qsort-800000.ml
+qsort260000: qsort260000.ml
$(CC) $(CFLAGS) $< -o $@
-msort800000: msort-800000.ml
+msort260000: msort260000.ml
$(CC) $(CFLAGS) $< -o $@
diff --git a/comparison/OCaml/bsort40000.ml b/comparison/OCaml/bsort40000.ml
index 2a06e85..80c222e 100644
--- a/comparison/OCaml/bsort40000.ml
+++ b/comparison/OCaml/bsort40000.ml
@@ -1,3 +1,5 @@
+open Format
+
let rec bs (alist : int list) n =
match alist with
(x::y::ys) ->
@@ -11,9 +13,12 @@ let rec go xs n =
0 -> xs
| n -> go (bs xs n) (n-1);;
-let bsort xs = go xs (List.length(xs) - 1);;
-
+let bsort alist =
+ match alist with
+ [] -> []
+ | xs -> go xs (List.length(xs) - 1);;
+
let rec mkRandList n =
match n with
0 -> []
@@ -31,5 +36,4 @@ let rec validation alist =
| x::xs -> validation_cons x xs;;
-let main = validation (bsort (mkRandList 40000));;
-
+let () = print_bool (validation (bsort (mkRandList 40000)));;
diff --git a/comparison/OCaml/isort40000.ml b/comparison/OCaml/isort40000.ml
index 92e127d..a1d00a5 100644
--- a/comparison/OCaml/isort40000.ml
+++ b/comparison/OCaml/isort40000.ml
@@ -1,3 +1,5 @@
+open Format
+
let rec insert x ylist =
match ylist with
[] -> [x]
@@ -30,5 +32,5 @@ let rec validation alist =
| x::xs -> validation_cons x xs;;
-let main = validation(isort (mkRandList 40000));;
+let () = print_bool (validation (isort (mkRandList 40000)));;
diff --git a/comparison/OCaml/msort260000.ml b/comparison/OCaml/msort260000.ml
new file mode 100644
index 0000000..a44f41a
--- /dev/null
+++ b/comparison/OCaml/msort260000.ml
@@ -0,0 +1,49 @@
+open Format
+
+let rec split (alist : int list) =
+ match alist with
+ [] -> ([], [])
+ | [a] -> ([a], [])
+ | a::b::cs ->
+ let (m,n) = split cs in
+ (a::m, b::m) ;;
+
+let rec merge (alist : int list) (blist : int list) =
+ match alist with
+ [] -> blist
+ | x::xs ->
+ match blist with
+ [] -> x::xs
+ | y::ys ->
+ if x<y then x::(merge xs (y::ys))
+ else y::(merge (x::xs) ys) ;;
+
+
+let rec msort (alist : int list) =
+ match alist with
+ [] -> []
+ | a::[] -> [a]
+ | a::b::[] -> if a<b then [a;b] else [b;a]
+ | xs ->
+ let (m,n) = split xs
+ in merge (msort m) (msort n) ;;
+
+
+
+let rec mkRandList n =
+ match n with
+ 0 -> []
+ | n -> (Random.int 10000)::(mkRandList (n-1)) ;;
+
+let rec validation alist =
+ let rec validation_cons x blist =
+ match blist with
+ [] -> true
+ | y::ys -> if x<=y then (validation_cons y ys) else false
+ in
+ match alist with
+ [] -> true
+ | x::xs -> validation_cons x xs;;
+
+
+let () = print_bool (validation (msort (mkRandList 260000)));;
diff --git a/comparison/OCaml/qsort260000.ml b/comparison/OCaml/qsort260000.ml
new file mode 100644
index 0000000..983ad50
--- /dev/null
+++ b/comparison/OCaml/qsort260000.ml
@@ -0,0 +1,38 @@
+open Format
+
+let rec split pivot (alist : int list) =
+ match alist with
+ [] -> ([], [])
+ | (x::xs) ->
+ let (below, above) = split pivot xs in
+ if x<pivot then (x::below, above)
+ else (below, x::above) ;;
+
+let rec qsort (alist : int list) =
+ match alist with
+ [] -> []
+ | pivot::rest ->
+ let (below, above) = split pivot rest
+ in (qsort below) @ [pivot] @ (qsort above) ;;
+
+
+
+
+let rec mkRandList n =
+ match n with
+ 0 -> []
+ | n -> (Random.int 10000)::(mkRandList (n-1)) ;;
+
+
+let rec validation alist =
+ let rec validation_cons x blist =
+ match blist with
+ [] -> true
+ | y::ys -> if x<=y then (validation_cons y ys) else false
+ in
+ match alist with
+ [] -> true
+ | x::xs -> validation_cons x xs;;
+
+
+let () = print_bool (validation (qsort (mkRandList 260000)));;