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 5856 additions and 2 deletions
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>P4A</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
/p4a/
package p4a;
import java.util.Arrays;
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 p4a;
import java.util.ArrayList;
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 p4a;
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 p4a;
import java.util.LinkedList;
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 p4a;
public class MainArrayListPersoAddDebut {
public static void main(String[] args) {
ArrayListPerso<Integer> arraylistPerso = new ArrayListPerso<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arraylistPerso.ajout(0, 0);
}
}
}
package p4a;
public class MainArrayListPersoAddFin {
public static void main(String[] args) {
ArrayListPerso<Integer> arraylistPerso = new ArrayListPerso<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arraylistPerso.ajout(0, i);
}
}
}
package p4a;
public class MainArrayListStdAddDebut {
public static void main(String[] args) {
ArrayListStd<Integer> arrayListStd = new ArrayListStd<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arrayListStd.ajout(0, 0);
}
}
}
package p4a;
public class MainLinkedListPersoAddDebut {
public static void main(String[] args) {
LinkedListPerso<Integer> linkedListStd = new LinkedListPerso<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
linkedListStd.ajout(0, 0);
}
}
}
package p4a;
public class MainLinkedListStdAddDebut {
public static void main(String[] args) {
LinkedListStd<Integer> linkedListStd = new LinkedListStd<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
linkedListStd.ajout(0, 0);
}
}
}
package p4a;
public interface Structure {
public void ajout(Object element, int position);
public void suppression(int position);
public Object acces(int position);
}
package p4a;
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 p4a;
public class TableauStd implements Structure {
private Object[] tableau;
public TableauStd(Object[] tableau) {
this.tableau = tableau;
}
@Override
public void ajout(Object element, int position) {
if (position > tableau.length) {
throw new UnsupportedOperationException("ajout : operation non supportee (taille depassee)");
}
else tableau[position] = element;
}
@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];
}
}
......@@ -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")
graphiques/LinkedListCPU.png

116 KiB