From 0a2df4c9d3313a86689878cffd152f1f69b77df0 Mon Sep 17 00:00:00 2001 From: Arkitu Date: Tue, 13 Jan 2026 15:00:39 +0100 Subject: [PATCH] tp5 exo2 --- tp7/ocaml/dune-project | 26 +++++++++++++++++++++++++ tp7/ocaml/exo2/dune | 3 +++ tp7/ocaml/exo2/exo2.ml | 43 ++++++++++++++++++++++++++++++++++++++++++ tp7/ocaml/test/dune | 4 ++++ tp7/ocaml/test/test.ml | 1 + tp7/ocaml/tp7.opam | 32 +++++++++++++++++++++++++++++++ 6 files changed, 109 insertions(+) create mode 100644 tp7/ocaml/dune-project create mode 100644 tp7/ocaml/exo2/dune create mode 100644 tp7/ocaml/exo2/exo2.ml create mode 100644 tp7/ocaml/test/dune create mode 100644 tp7/ocaml/test/test.ml create mode 100644 tp7/ocaml/tp7.opam diff --git a/tp7/ocaml/dune-project b/tp7/ocaml/dune-project new file mode 100644 index 0000000..3345a78 --- /dev/null +++ b/tp7/ocaml/dune-project @@ -0,0 +1,26 @@ +(lang dune 3.20) + +(name tp7) + +(generate_opam_files true) + +(source + (github username/reponame)) + +(authors "Author Name ") + +(maintainers "Maintainer Name ") + +(license LICENSE) + +(documentation https://url/to/documentation) + +(package + (name tp7) + (synopsis "A short synopsis") + (description "A longer description") + (depends ocaml) + (tags + ("add topics" "to describe" your project))) + +; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html diff --git a/tp7/ocaml/exo2/dune b/tp7/ocaml/exo2/dune new file mode 100644 index 0000000..0643996 --- /dev/null +++ b/tp7/ocaml/exo2/dune @@ -0,0 +1,3 @@ +(library + (name exo2) + (public_name tp7)) diff --git a/tp7/ocaml/exo2/exo2.ml b/tp7/ocaml/exo2/exo2.ml new file mode 100644 index 0000000..2bfe6c0 --- /dev/null +++ b/tp7/ocaml/exo2/exo2.ml @@ -0,0 +1,43 @@ +type 'a tr = { + mutable taille : int; + mutable donnees : 'a array +};; + +let creer_tr capacity init_value = { + taille = 0; + donnees = Array.make (max capacity 1) init_value +};; + +let taille_tr tr = tr.taille;; + +let acces_tr tr i = + if i >= tr.taille then + invalid_arg "Index bigger than tr size" + else + tr.donnees.(i);; + +let modif_tr tr i value = + if i >= tr.taille then + invalid_arg "Index bigger than tr size" + else + tr.donnees.(i) <- value;; + +let append_tr tr value = + let n = Array.length tr.donnees in + + if tr.taille >= n then + tr.donnees <- Array.init + (n*2) + (fun i -> tr.donnees.(i mod n)); + + tr.donnees.(tr.taille) <- value; + tr.taille <- tr.taille + 1 +;; + +let pop_tr tr = + if tr.taille <= 0 then + invalid_arg "Empty tr" + else + tr.taille <- tr.taille - 1; + tr.donnees.(tr.taille) +;; diff --git a/tp7/ocaml/test/dune b/tp7/ocaml/test/dune new file mode 100644 index 0000000..d061247 --- /dev/null +++ b/tp7/ocaml/test/dune @@ -0,0 +1,4 @@ +(executable + (name test) + (public_name test) + (libraries exo2)) diff --git a/tp7/ocaml/test/test.ml b/tp7/ocaml/test/test.ml new file mode 100644 index 0000000..1c37e0b --- /dev/null +++ b/tp7/ocaml/test/test.ml @@ -0,0 +1 @@ +open Exo2;; diff --git a/tp7/ocaml/tp7.opam b/tp7/ocaml/tp7.opam new file mode 100644 index 0000000..a43bbcb --- /dev/null +++ b/tp7/ocaml/tp7.opam @@ -0,0 +1,32 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "A short synopsis" +description: "A longer description" +maintainer: ["Maintainer Name "] +authors: ["Author Name "] +license: "LICENSE" +tags: ["add topics" "to describe" "your" "project"] +homepage: "https://github.com/username/reponame" +doc: "https://url/to/documentation" +bug-reports: "https://github.com/username/reponame/issues" +depends: [ + "dune" {>= "3.20"} + "ocaml" + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/username/reponame.git" +x-maintenance-intent: ["(latest)"]