summaryrefslogtreecommitdiff
path: root/graphs/java/mySet
diff options
context:
space:
mode:
Diffstat (limited to 'graphs/java/mySet')
-rw-r--r--graphs/java/mySet/.gitignore38
-rw-r--r--graphs/java/mySet/pom.xml133
-rw-r--r--graphs/java/mySet/src/main/java/fr/epita/assistants/myset/GenericSet.java83
-rw-r--r--graphs/java/mySet/src/main/java/fr/epita/assistants/myset/IntegerSet.java83
4 files changed, 337 insertions, 0 deletions
diff --git a/graphs/java/mySet/.gitignore b/graphs/java/mySet/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/graphs/java/mySet/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store \ No newline at end of file
diff --git a/graphs/java/mySet/pom.xml b/graphs/java/mySet/pom.xml
new file mode 100644
index 0000000..c20e039
--- /dev/null
+++ b/graphs/java/mySet/pom.xml
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>fr.epita.assistants</groupId>
+ <artifactId>mySet</artifactId>
+ <version>1.0</version>
+
+ <properties>
+ <versions.java>21</versions.java>
+ <versions.junit>5.9.1</versions.junit>
+ <versions.maven-compiler-plugin>3.13.0</versions.maven-compiler-plugin>
+ <versions.maven-surefire-plugin>3.5.0</versions.maven-surefire-plugin>
+ <versions.maven-jar-plugin>3.1.1</versions.maven-jar-plugin>
+ <versions.maven-install-plugin>3.1.0</versions.maven-install-plugin>
+
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <surefire.reportsDirectory>${project.build.directory}/surefire-reports</surefire.reportsDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <version>${versions.junit}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-junit-platform</artifactId>
+ <version>${versions.maven-surefire-plugin}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-compat</artifactId>
+ <version>3.9.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>3.9.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-monitor</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>3.0.24</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-filtering</artifactId>
+ <version>3.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-interpolation</artifactId>
+ <version>1.13</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-profile</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact-manager</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-registry</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-repository-metadata</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>classworlds</groupId>
+ <artifactId>classworlds</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-commons</artifactId>
+ <version>1.9.3</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${versions.maven-compiler-plugin}</version>
+ <configuration>
+ <source>${versions.java}</source>
+ <target>${versions.java}</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>${versions.maven-install-plugin}</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${versions.maven-surefire-plugin}</version>
+ <configuration>
+ <reportsDirectory>${surefire.reportsDirectory}</reportsDirectory>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/graphs/java/mySet/src/main/java/fr/epita/assistants/myset/GenericSet.java b/graphs/java/mySet/src/main/java/fr/epita/assistants/myset/GenericSet.java
new file mode 100644
index 0000000..590751f
--- /dev/null
+++ b/graphs/java/mySet/src/main/java/fr/epita/assistants/myset/GenericSet.java
@@ -0,0 +1,83 @@
+package fr.epita.assistants.myset;
+
+import java.util.ArrayList;
+
+public class GenericSet<T extends Comparable<T>> {
+ ArrayList<T> base_;
+
+ public GenericSet() {
+ base_ = new ArrayList<>();
+ }
+
+ private static <T extends Comparable<T>> void insertionSort(ArrayList<T> array) {
+ if (array.isEmpty()) {
+ return;
+ }
+ for (int i = 1; i < array.size(); i++) {
+ for (int j = i; j > 0 && array.get(j - 1).compareTo(array.get(j)) > 0; j--) {
+ T tmp = array.get(j);
+ array.set(j, array.get(j - 1));
+ array.set(j - 1, tmp);
+ }
+ }
+ }
+ public void insert(T i) {
+ if (!this.has(i)) {
+ this.base_.add(i);
+ insertionSort(base_);
+ }
+ }
+
+ public void remove(T i) {
+ this.base_.remove(i);
+ }
+
+ public boolean has(T i) {
+ return this.base_.contains(i);
+ }
+
+ public boolean isEmpty() {
+ return this.base_.isEmpty();
+ }
+
+ public T min() {
+ T min = base_.getFirst();
+ for (T t : base_) {
+ if (t.compareTo(min) < 0)
+ min = t;
+ }
+ return min;
+ }
+
+ public T max() {
+ T max = base_.getFirst();
+ for (T t : base_) {
+ if (t.compareTo(max) > 0)
+ max = t;
+ }
+ return max;
+ }
+
+ public int size() {
+ return base_.size();
+ }
+
+ public static <T extends Comparable<T>> GenericSet<T> intersection(GenericSet<T> a, GenericSet<T> b) {
+ GenericSet<T> res = new GenericSet<T>();
+ for (int i = 0; i < a.size(); i++) {
+ if (b.has(a.base_.get(i)))
+ res.insert(a.base_.get(i));
+ }
+ return res;
+ }
+
+ public static <T extends Comparable<T>> GenericSet<T> union(GenericSet<T> a, GenericSet<T> b) {
+ GenericSet<T> res = new GenericSet<>();
+ for (T i : a.base_)
+ res.insert(i);
+ for (T i : b.base_)
+ res.insert(i);
+
+ return res;
+ }
+}
diff --git a/graphs/java/mySet/src/main/java/fr/epita/assistants/myset/IntegerSet.java b/graphs/java/mySet/src/main/java/fr/epita/assistants/myset/IntegerSet.java
new file mode 100644
index 0000000..25dcfdc
--- /dev/null
+++ b/graphs/java/mySet/src/main/java/fr/epita/assistants/myset/IntegerSet.java
@@ -0,0 +1,83 @@
+package fr.epita.assistants.myset;
+
+import java.util.ArrayList;
+
+public class IntegerSet {
+ ArrayList<Integer> base_;
+
+ public IntegerSet() {
+ base_ = new ArrayList<Integer>();
+ }
+
+ private static void insertionSort(ArrayList<Integer> array) {
+ if (array.isEmpty()) {
+ return;
+ }
+ for (int i = 1; i < array.size(); i++) {
+ for (int j = i; j > 0 && array.get(j - 1).compareTo(array.get(j)) > 0; j--) {
+ Integer tmp = array.get(j);
+ array.set(j, array.get(j - 1));
+ array.set(j - 1, tmp);
+ }
+ }
+ }
+ public void insert(Integer i) {
+ if (!this.has(i)) {
+ this.base_.add(i);
+ insertionSort(base_);
+ }
+ }
+
+ public void remove(Integer i) {
+ this.base_.remove(i);
+ }
+
+ public boolean has(Integer i) {
+ return this.base_.contains(i);
+ }
+
+ public boolean isEmpty() {
+ return this.base_.isEmpty();
+ }
+
+ public Integer min() {
+ Integer min = base_.getFirst();
+ for (Integer integer : base_) {
+ if (integer < min)
+ min = integer;
+ }
+ return min;
+ }
+
+ public Integer max() {
+ Integer max = base_.getFirst();
+ for (Integer integer : base_) {
+ if (integer > max)
+ max = integer;
+ }
+ return max;
+ }
+
+ public int size() {
+ return base_.size();
+ }
+
+ public static IntegerSet intersection(IntegerSet a, IntegerSet b) {
+ IntegerSet res = new IntegerSet();
+ for (int i = 0; i < a.size(); i++) {
+ if (b.has(a.base_.get(i)))
+ res.insert(a.base_.get(i));
+ }
+ return res;
+ }
+
+ public static IntegerSet union(IntegerSet a, IntegerSet b) {
+ IntegerSet res = new IntegerSet();
+ for (Integer i : a.base_)
+ res.insert(i);
+ for (Integer i : b.base_)
+ res.insert(i);
+
+ return res;
+ }
+}