Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Showing
with 5853 additions and 2 deletions
/struct/
/p4a/
/test/
/main/
/classPerso/
/standard/
/perso/
/structure/
package main;
import perso.ArrayListPerso;
public class MainArrayListPerso {
public static void main(String[] args) {
ArrayListPerso<Integer> arraylistPerso = new ArrayListPerso<Integer>();
for (int i = 0; i < 100000; i++) {
arraylistPerso.ajout(i, 0);
}
}
}
package main;
import standard.ArrayListStd;
public class MainArrayListStd {
public static void main(String[] args) {
ArrayListStd<Integer> arrayListStd = new ArrayListStd<Integer>();
int taille = Integer.parseInt(args[0]);
for (int i = 0; i < taille; i++) {
arrayListStd.ajout(i, 0);
}
}
}
package main;
import perso.LinkedListPerso;
public class MainLinkedListPerso {
public static void main(String[] args) {
LinkedListPerso<Integer> linkedListStd = new LinkedListPerso<Integer>();
int taille = Integer.parseInt(args[0]);
for (int i = 0; i < taille; i++) {
linkedListStd.ajout(i, 0);
}
}
}
package main;
import standard.LinkedListStd;
public class MainLinkedListStd {
public static void main(String[] args) {
LinkedListStd<Integer> linkedListStd = new LinkedListStd<Integer>();
int taille = Integer.parseInt(args[0]);
for (int i = 0; i < taille; i++) {
linkedListStd.ajout(i, 0);
}
}
}
*.class
package perso;
import java.util.Arrays;
import structure.Structure;
public class ArrayListPerso<E> implements Structure{
private E[] tableau;
private int nbElements;
private final static int taille_par_defaut = 10000;
private final static int incr_par_defaut = 2500;
public ArrayListPerso() {
tableau = (E[]) new Object[taille_par_defaut];
}
@Override
public void ajout(Object element, int position) {
E[] tab;
if (position < 0 || position > nbElements) {
throw new IndexOutOfBoundsException("ajout : mauvais index " + position);
}
if (nbElements >= tableau.length) {
tab = Arrays.copyOf(tableau, tableau.length + incr_par_defaut);
}
else {
tab = tableau;
}
for (int i = nbElements; i > position; i--) {
tab[i] = tab[i - 1];
}
tab[position] = (E) element;
tableau = tab;
nbElements++;
}
@Override
public void suppression(int position) {
if (position < 0 || position >= nbElements) {
throw new IndexOutOfBoundsException("suppression : position incorrecte " + position);
}
for (int i = position + 1; i < nbElements; i++) {
tableau[i - 1] = tableau[i];
}
nbElements--;
}
@Override
public Object acces(int position) {
if (position > tableau.length || position < 0) {
throw new IllegalArgumentException("acces : position incorecte");
}
return tableau[position];
}
}
package perso;
import structure.Structure;
public class LinkedListPerso<T> implements Structure
{
private static class Maillon<T>
{
private T val; // valeur du maillon
private Maillon<T> suivant; // reference au maillon suivant
private Maillon() // pour creer la sentinelle
{
val = null;
suivant = this;
}
private Maillon(T x, Maillon<T> succ)
{
val = x;
suivant = succ;
}
} // class Maillon
private class Curseur
{
private int pos; // position courante dans la liste
private Maillon<T> maillon; // maillon courant pointe
private Curseur()
{
pos = -1;
maillon = LinkedListPerso.this.sentinelle;
}
private void positionner(int pos)
{
if (!( pos >= -1 && pos <= longueur()))
throw new IllegalStateException(
"mauvaise position pos = " + pos + " ");
if (pos < this.pos)
{
this.pos = -1;
maillon = sentinelle;
}
while (this.pos < pos)
{
this.pos++;
maillon = maillon.suivant;
}
}
} // class Curseur
private Maillon<T> sentinelle;
private Curseur curs; // curseur specifique a ListeChainee
private int nbVal;
public LinkedListPerso()
{
sentinelle = new Maillon<T>() ;
curs = this.new Curseur();
nbVal = 0;
}
public int longueur()
{
return nbVal;
}
public boolean estVide()
{
return nbVal == 0;
}
@Override
public T acces(int pos)
{
if (!(pos >= 0 && pos < nbVal))
throw new IndexOutOfBoundsException(
String.valueOf(pos));
curs.positionner(pos);
return curs.maillon.val;
}
public void remplacer(int pos, T x)
{
if (!(pos >= 0 && pos < nbVal))
throw new IndexOutOfBoundsException(
String.valueOf(pos));
curs.positionner(pos) ;
curs.maillon.val = x;
}
@Override
public void ajout(Object element, int position)
{
if (!(position >= 0 && position <= nbVal))
throw new IndexOutOfBoundsException(
String.valueOf(position));
curs.positionner(position - 1) ;
Maillon<T> pred = curs.maillon;
Maillon<T> succ = pred.suivant;
Maillon<T> nouveau = new Maillon<T>((T)element, succ);
pred.suivant = nouveau ;
nbVal++;
}
@Override
public void suppression(int pos)
{
if (!(pos >= 0 && pos < nbVal))
throw new IndexOutOfBoundsException(
String.valueOf(pos));
curs.positionner(pos - 1);
Maillon<T> pred = curs.maillon;
Maillon<T> aEnlever = pred.suivant;
Maillon<T> succ = aEnlever.suivant;
pred.suivant = succ;
nbVal--;
}
} // class ListeChainee
\ No newline at end of file
package perso;
import structure.Structure;
public class TableauPerso implements Structure{
private Object[] tableau;
private int nbElements;
public TableauPerso(int taille) {
if (taille < 0) {
throw new IllegalArgumentException("TableauPerso : taille negative " + taille);
}
this.tableau = new Object[taille];
nbElements = 0;
}
@Override
public void ajout(Object element, int position) {
if (position < 0 || position > nbElements) {
throw new IndexOutOfBoundsException("ajout : mauvais index " + position);
}
if (nbElements >= tableau.length) {
throw new IllegalStateException("ajout : tableau plein");
}
for (int i = nbElements; i > position; i--) {
tableau[i] = tableau[i - 1];
}
tableau[position] = element;
nbElements++;
}
@Override
public void suppression(int position) {
if (position < 0 || position >= nbElements) {
throw new IndexOutOfBoundsException("suppression : position incorrecte " + position);
}
for (int i = position + 1; i < nbElements; i++) {
tableau[i - 1] = tableau[i];
}
nbElements--;
}
@Override
public Object acces(int position) {
if (position > tableau.length || position < 0) {
throw new IllegalArgumentException("acces : position incorecte");
}
return tableau[position];
}
}
package standard;
import java.util.ArrayList;
import structure.Structure;
public class ArrayListStd<E> extends ArrayList<E> implements Structure{
private ArrayList<E> liste;
public ArrayListStd()
{
liste = new ArrayList<E>();
}
@Override
public void ajout(Object element, int position) {
liste.add(position, (E) element);
}
@Override
public void suppression(int position) {
liste.remove(position);
}
@Override
public Object acces(int position) {
return liste.get(position);
}
}
package standard;
import java.util.LinkedList;
import structure.Structure;
public class LinkedListStd<E> extends LinkedList<E> implements Structure {
private LinkedList<E> liste;
public LinkedListStd()
{
liste = new LinkedList<E>();
}
@Override
public void ajout(Object element, int position) {
liste.add(position, (E) element);
}
@Override
public void suppression(int position) {
liste.remove(position);
}
@Override
public Object acces(int position) {
return liste.get(position);
}
}
package standard;
import structure.Structure;
public class TableauStd implements Structure {
private Object[] tableau;
public TableauStd(Object[] tableau) {
this.tableau = tableau;
}
@Override
public void ajout(Object element, int position) {
throw new UnsupportedOperationException("ajout : operation non supportee");
}
@Override
public void suppression(int position) {
throw new UnsupportedOperationException("suppression : operation non supportee");
}
@Override
public Object acces(int position) {
if (position > tableau.length || position < 0) {
throw new IllegalArgumentException("acces : position incorecte");
}
return tableau[position];
}
}
package structure;
public interface Structure {
public void ajout(Object element, int position);
public void suppression(int position);
public Object acces(int position);
}
......@@ -4,15 +4,27 @@
## Problème
Description du Problème.
Description du Problème :
Description de tous les paramètres exploratoires du problème
Nous allons implémenter 3 opérations communes à différentes structures de données (tableaux, LinkedList et ArrayList) et comparer leurs performances avec leur implémentation standard.
Nous avons choisi d'utiliser le language objet java.
Proposition d'opérations :
- Ajout d'un élement à une certaine position (n'exite pas pour les tableaux standards, add() pour les LinkedList / ArrayList)
- Suppression d'un élement à une certaine position(n'existe pas pour les tableaux standards, remove() pour les LinkedList / ArrayList)
- Accès d'un élement à une certaine position(tab[position] pour les tableaux, get() pour les LinkedList / ArrayList)
## Dispositif expérimental
### Organisation objet
Description de l'organisation des classes et interfaces, ou diagramme de classes.
![](UML/diagramme.svg)
Toutes les structures de données vont implémenter une Interface *"Struture"* que nous allons créer et qui contiendra les opérations choisies.
Dans le package **Standard**, nous appelerons juste les bonnes méthodes déja présentes dans les libraires standards et dans
le package **Perso** nous réimplementerons par nous même ces opérations.
### Application
......
UML/diagramme.png

183 KiB

This diff is collapsed.
This diff is collapsed.
Compilation :
(dossier avec sources)
javac ./*.java
cd ..
java nomDossier.nomClasseMain
R
perf <- read.csv("perf.csv")
library(ggplot2)
Comparaison LinkedList perso / standard :
CPU : ggplot(perf, aes(x=Taille,y=CPU, color=as.character(Version))) + geom_point() + geom_smooth(aes(group=Version)) + scale_color_discrete(name="Version") + ggtitle("Consommation CPU en fonction de la taille")
Mem : ggplot(perf, aes(x=Taille,y=Mem, color=as.character(Test))) + geom_point() + geom_smooth(aes(group=Test)) + scale_color_discrete(name="Test")
Comparaison LinkedListStd / ArrayListStd :
ggplot(perf, aes(x=Taille,y=CPU, color=as.character(Version))) + geom_point() + geom_smooth(aes(group=Version)) + scale_color_discrete(name="Version") + ggtitle("Consommation CPU en fonction de la taille")
graphique/LinkedListCPU.png

116 KiB

graphique/comparaison_CPU_ajout_LinkedList_ArrayList_Standard.png

96 KiB