Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Nadi Tomeh
SDA
Commits
800a5a01
Commit
800a5a01
authored
Nov 18, 2021
by
ALICHERIF_YACINE
Browse files
Exercice 3 : Tas binaire dynamique
parent
29c007e6
Pipeline
#4628
failed with stage
in 7 seconds
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
C/arraylist.c
View file @
800a5a01
#include "arraylist.h"
#include <math.h>
#include<stdio.h>
#include<stdlib.h>
arraylist_t
*
arraylist_create
(){
arraylist_t
*
res
=
(
arraylist_t
*
)
malloc
(
sizeof
(
arraylist_t
)
);
if
(
!
res
)
return
NULL
;
res
->
data
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
4
);
res
->
capacity
=
4
;
res
->
size
=
0
;
res
->
countSwap
=
0
;
return
res
;
}
...
...
@@ -18,26 +22,83 @@ void arraylist_destroy(arraylist_t * a){
}
}
int
arraylist_pere
(
int
clef
)
{
return
(
int
)
floor
(
clef
/
2
);
}
int
arraylist_diminuerClef
(
arraylist_t
*
a
,
int
clef
,
int
val
)
{
a
->
data
[
clef
]
=
val
;
int
countSwap
=
0
;
while
(
clef
>
0
&&
a
->
data
[
arraylist_pere
(
clef
)]
>
a
->
data
[
clef
])
{
int
tmp
=
a
->
data
[
arraylist_pere
(
clef
)];
a
->
data
[
arraylist_pere
(
clef
)]
=
a
->
data
[
clef
];
a
->
data
[
clef
]
=
tmp
;
countSwap
++
;
clef
=
arraylist_pere
(
clef
);
}
return
countSwap
;
}
char
arraylist_append
(
arraylist_t
*
a
,
int
x
){
char
memory_allocation
=
FALSE
;
char
memory_allocation
=
FALSE
;
if
(
a
!=
NULL
){
if
(
arraylist_do_we_need_to_enlarge_capacity
(
a
)
){
memory_allocation
=
TRUE
;
arraylist_enlarge_capacity
(
a
);
}
a
->
data
[
a
->
size
++
]
=
x
;
a
->
countSwap
=
arraylist_diminuerClef
(
a
,
a
->
size
,
x
);
a
->
size
++
;
}
return
memory_allocation
;
}
int
entasser
(
arraylist_t
*
a
)
{
/*On se trouve à la racine*/
int
clef
=
0
;
int
countSwap
=
0
;
int
g
=
2
*
clef
+
1
;
int
d
=
2
*
clef
+
2
;
int
tmp
=
0
;
while
((
clef
<
(
arraylist_size
(
a
)
-
1
))
&&
(
g
<
arraylist_size
(
a
)
&&
d
<
arraylist_size
(
a
))
&&
(
a
->
data
[
clef
]
>
a
->
data
[
g
]
||
a
->
data
[
clef
]
>
a
->
data
[
d
]))
{
if
(
a
->
data
[
g
]
>
a
->
data
[
d
])
{
tmp
=
a
->
data
[
clef
];
a
->
data
[
clef
]
=
a
->
data
[
d
];
a
->
data
[
d
]
=
tmp
;
clef
=
d
;
}
else
{
tmp
=
a
->
data
[
clef
];
a
->
data
[
clef
]
=
a
->
data
[
g
];
a
->
data
[
g
]
=
tmp
;
clef
=
g
;
}
countSwap
++
;
g
=
2
*
clef
+
1
;
d
=
2
*
clef
+
2
;
}
return
countSwap
;
}
char
arraylist_pop_back
(
arraylist_t
*
a
){
char
memory_reduction
=
FALSE
;
char
memory_reduction
=
FALSE
;
if
(
a
!=
NULL
&&
a
->
size
>
0
){
if
(
arraylist_do_we_need_to_reduce_capacity
(
a
)
){
memory_reduction
=
TRUE
;
arraylist_reduce_capacity
(
a
);
}
a
->
size
--
;
if
(
arraylist_do_we_need_to_reduce_capacity
(
a
)
){
memory_reduction
=
TRUE
;
arraylist_reduce_capacity
(
a
);
}
a
->
data
[
0
]
=
a
->
data
[
arraylist_size
(
a
)
-
1
];
a
->
size
--
;
a
->
countSwap
=
entasser
(
a
);
}
return
memory_reduction
;
}
...
...
@@ -59,6 +120,11 @@ size_t arraylist_capacity(arraylist_t * a){
return
(
a
!=
NULL
)
?
a
->
capacity
:
-
1
;
}
int
getCountSwap
(
arraylist_t
*
a
)
{
if
(
a
!=
NULL
)
return
a
->
countSwap
;
}
char
arraylist_do_we_need_to_enlarge_capacity
(
arraylist_t
*
a
){
return
a
->
size
==
a
->
capacity
?
TRUE
:
FALSE
;
}
...
...
C/arraylist.h
View file @
800a5a01
...
...
@@ -17,6 +17,8 @@ typedef struct arraylist_s{
size_t
capacity
;
// Nombre d'éléments stockés dans le tableau.
size_t
size
;
//Nombre de swap effectué.
int
countSwap
;
}
arraylist_t
;
/**
...
...
@@ -33,6 +35,16 @@ arraylist_t * arraylist_create();
*/
void
arraylist_destroy
(
arraylist_t
*
a
);
/**
Retourne la position du père pour le noeud de position clef.
*/
int
arraylist_pere
(
int
clef
);
/**
Attribue la valeur val au noeud de position clef et trie le tas.
*/
int
arraylist_diminuerClef
(
arraylist_t
*
a
,
int
clef
,
int
val
);
/**
Ajoute une valeur dans le tableau.
Complexité en temps/espace, pire cas : O(size)
...
...
@@ -44,6 +56,11 @@ void arraylist_destroy(arraylist_t * a);
*/
char
arraylist_append
(
arraylist_t
*
a
,
int
x
);
/**
Entasse le tas depuis la racine.
*/
int
entasser
(
arraylist_t
*
a
);
/**
Supprime la dernière valeur du tableau.
Complexité en temps, pire cas : O(size)
...
...
@@ -80,6 +97,11 @@ size_t arraylist_size(arraylist_t * a);
*/
size_t
arraylist_capacity
(
arraylist_t
*
a
);
/**
Renvoie le nombre d'échanges effectués.
*/
int
getCountSwap
(
arraylist_t
*
a
);
/**
Cette fonction détermine la règle selon laquelle un espace mémoire plus grand sera alloué ou non.
@param a est un pointeur vers un tableau.
...
...
@@ -108,5 +130,3 @@ void arraylist_reduce_capacity(arraylist_t * a);
#endif
C/dynamic_extract_arraylist.c
0 → 100644
View file @
800a5a01
#include "arraylist.h"
#include <math.h>
#include<stdio.h>
#include<stdlib.h>
arraylist_t
*
arraylist_create
(){
arraylist_t
*
res
=
(
arraylist_t
*
)
malloc
(
sizeof
(
arraylist_t
)
);
if
(
!
res
)
return
NULL
;
res
->
data
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
4
);
res
->
capacity
=
4
;
res
->
size
=
0
;
res
->
countSwap
=
0
;
return
res
;
}
void
arraylist_destroy
(
arraylist_t
*
a
){
if
(
a
!=
NULL
){
if
(
a
->
data
!=
NULL
)
free
(
a
->
data
);
free
(
a
);
}
}
int
arraylist_pere
(
int
clef
)
{
return
(
int
)
floor
(
clef
/
2
);
}
int
arraylist_diminuerClef
(
arraylist_t
*
a
,
int
clef
,
int
val
)
{
a
->
data
[
clef
]
=
val
;
int
countSwap
=
0
;
while
(
clef
>
0
&&
a
->
data
[
arraylist_pere
(
clef
)]
>
a
->
data
[
clef
])
{
int
tmp
=
a
->
data
[
arraylist_pere
(
clef
)];
a
->
data
[
arraylist_pere
(
clef
)]
=
a
->
data
[
clef
];
a
->
data
[
clef
]
=
tmp
;
countSwap
++
;
clef
=
arraylist_pere
(
clef
);
}
return
countSwap
;
}
char
arraylist_append
(
arraylist_t
*
a
,
int
x
){
char
memory_allocation
=
FALSE
;
if
(
a
!=
NULL
){
if
(
arraylist_do_we_need_to_enlarge_capacity
(
a
)
){
memory_allocation
=
TRUE
;
arraylist_enlarge_capacity
(
a
);
}
a
->
countSwap
=
arraylist_diminuerClef
(
a
,
a
->
size
,
x
);
a
->
size
++
;
}
return
memory_allocation
;
}
int
entasser
(
arraylist_t
*
a
)
{
/*On se trouve à la racine*/
int
clef
=
0
;
int
countSwap
=
0
;
int
g
=
2
*
clef
+
1
;
int
d
=
2
*
clef
+
2
;
int
tmp
=
0
;
while
((
clef
<
(
arraylist_size
(
a
)
-
1
))
&&
(
g
<
arraylist_size
(
a
)
&&
d
<
arraylist_size
(
a
))
&&
(
a
->
data
[
clef
]
>
a
->
data
[
g
]
||
a
->
data
[
clef
]
>
a
->
data
[
d
]))
{
if
(
a
->
data
[
g
]
>
a
->
data
[
d
])
{
tmp
=
a
->
data
[
clef
];
a
->
data
[
clef
]
=
a
->
data
[
d
];
a
->
data
[
d
]
=
tmp
;
clef
=
d
;
}
else
{
tmp
=
a
->
data
[
clef
];
a
->
data
[
clef
]
=
a
->
data
[
g
];
a
->
data
[
g
]
=
tmp
;
clef
=
g
;
}
countSwap
++
;
g
=
2
*
clef
+
1
;
d
=
2
*
clef
+
2
;
}
return
countSwap
;
}
char
arraylist_pop_back
(
arraylist_t
*
a
){
char
memory_reduction
=
FALSE
;
if
(
a
!=
NULL
&&
a
->
size
>
0
){
if
(
arraylist_do_we_need_to_reduce_capacity
(
a
)
){
memory_reduction
=
TRUE
;
arraylist_reduce_capacity
(
a
);
}
a
->
data
[
0
]
=
a
->
data
[
arraylist_size
(
a
)
-
1
];
a
->
size
--
;
a
->
countSwap
=
entasser
(
a
);
}
return
memory_reduction
;
}
int
arraylist_get
(
arraylist_t
*
a
,
int
pos
){
if
(
a
!=
NULL
&&
pos
>
0
&&
pos
<
a
->
size
){
return
a
->
data
[
pos
];
}
printf
(
"Wrong parameter pos=%d or NULL list"
,
pos
);
return
-
1
;
}
size_t
arraylist_size
(
arraylist_t
*
a
){
return
(
a
!=
NULL
)
?
a
->
size
:
-
1
;
}
size_t
arraylist_capacity
(
arraylist_t
*
a
){
return
(
a
!=
NULL
)
?
a
->
capacity
:
-
1
;
}
int
getCountSwap
(
arraylist_t
*
a
)
{
if
(
a
!=
NULL
)
return
a
->
countSwap
;
}
char
arraylist_do_we_need_to_enlarge_capacity
(
arraylist_t
*
a
){
return
a
->
size
==
a
->
capacity
?
TRUE
:
FALSE
;
}
void
arraylist_enlarge_capacity
(
arraylist_t
*
a
){
a
->
capacity
*=
2
;
a
->
data
=
(
int
*
)
realloc
(
a
->
data
,
sizeof
(
int
)
*
a
->
capacity
);
}
char
arraylist_do_we_need_to_reduce_capacity
(
arraylist_t
*
a
){
return
(
a
->
size
<=
a
->
capacity
/
4
&&
a
->
size
>
4
)
?
TRUE
:
FALSE
;
}
void
arraylist_reduce_capacity
(
arraylist_t
*
a
){
a
->
capacity
/=
2
;
a
->
data
=
(
int
*
)
realloc
(
a
->
data
,
sizeof
(
int
)
*
a
->
capacity
);
}
C/dynamic_extract_arraylist.h
0 → 100644
View file @
800a5a01
#ifndef __ARRAYLIST_H
#define __ARRAYLIST_H
#define FALSE 0
#define TRUE 1
#include <stddef.h>
/**
Tableau dynamique d'entiers.
*/
typedef
struct
arraylist_s
{
// Pointeur vers la zone de mémoire où les entiers seront stockées.
int
*
data
;
// Taille réelle, ou capacité de stockage, du tableau.
size_t
capacity
;
// Nombre d'éléments stockés dans le tableau.
size_t
size
;
//Nombre de swap effectué.
int
countSwap
;
}
arraylist_t
;
/**
Fonction d'initialisation d'un tableau dynamique.
Complexité en temps/espace, pire et meilleur cas : O(1)
@return Un pointeur sur un tableau dynamique nouvellement alloué.
*/
arraylist_t
*
arraylist_create
();
/**
Fonction de libération de la mémoire occupée par un tableau dynamique.
Complexité en temps/espace, pire et meilleur cas : O(1)
@param a est un pointeur vers l'espace mémoire que la fonction va libérer.
*/
void
arraylist_destroy
(
arraylist_t
*
a
);
/**
Retourne la position du père pour le noeud de position clef.
*/
int
arraylist_pere
(
int
clef
);
/**
Attribue la valeur val au noeud de position clef et trie le tas.
*/
int
arraylist_diminuerClef
(
arraylist_t
*
a
,
int
clef
,
int
val
);
/**
Ajoute une valeur dans le tableau.
Complexité en temps/espace, pire cas : O(size)
Complexité en temps/espace, meilleur cas : O(1)
Complexité amortie : O(1)
@param a est le tableau auquel on souhaite ajouter une valeur.
@param x est la valeur que l'on souhaite ajouter.
@returns VRAI si le tableau a été agrandit, FAUX sinon
*/
char
arraylist_append
(
arraylist_t
*
a
,
int
x
);
/**
Entasse le tas depuis la racine.
*/
int
entasser
(
arraylist_t
*
a
);
/**
Supprime la dernière valeur du tableau.
Complexité en temps, pire cas : O(size)
Complexité en temps, meilleur cas : O(1)
Complexité amortie : O(1)
@param a est le tableau auquel on souhaite ajouter une valeur.
@returns VRAI si le tableau a été réduit, FAUX sinon
*/
char
arraylist_pop_back
(
arraylist_t
*
a
);
/**
Renvoie la valeur située à la position donnée par l'utilisateur.
Complexité en temps/espace, pire cas : O(1)
@param a est un pointeur vers un tableau.
@param pos est la l'indice de la case on l'utilisateur veut connaître la valeur.
@returns la valeur située à la position donnée par l'utilisateur.
*/
int
arraylist_get
(
arraylist_t
*
a
,
int
pos
);
/**
Renvoie le nombre d'éléments stockés dans le tableau.
Complexité en temps/espace, pire cas : O(1)
@param a est un pointeur vers un tableau.
@returns le nombre d'éléments stockés dans le tableau.
*/
size_t
arraylist_size
(
arraylist_t
*
a
);
/**
Renvoie la capacité de stockage du tableau.
Complexité en temps/espace, pire cas : O(1)
@param a est un pointeur vers un tableau.
@returns la capacité de stockage du tableau.
*/
size_t
arraylist_capacity
(
arraylist_t
*
a
);
/**
Renvoie le nombre d'échanges effectués.
*/
int
getCountSwap
(
arraylist_t
*
a
);
/**
Cette fonction détermine la règle selon laquelle un espace mémoire plus grand sera alloué ou non.
@param a est un pointeur vers un tableau.
@returns VRAI si le tableau doit être agrandi, FAUX sinon.
*/
char
arraylist_do_we_need_to_enlarge_capacity
(
arraylist_t
*
a
);
/**
Cette fonction augmente la capacité du tableau.
@param a est un pointeur vers un tableau.
*/
void
arraylist_enlarge_capacity
(
arraylist_t
*
a
);
/**
Cette fonction détermine la règle selon laquelle un espace mémoire plus petit sera alloué ou non.
@param a est un pointeur vers un tableau.
@returns VRAI si le tableau doit être réduit, FAUX sinon.
*/
char
arraylist_do_we_need_to_reduce_capacity
(
arraylist_t
*
a
);
/**
Cette fonction réduit la capacité du tableau.
@param a est un pointeur vers un tableau.
*/
void
arraylist_reduce_capacity
(
arraylist_t
*
a
);
#endif
C/dynamic_extract_main.c
0 → 100644
View file @
800a5a01
#include<stdio.h>
#include <time.h>
#include<stdlib.h>
#include "arraylist.h"
#include "analyzer.h"
int
main
(
int
argc
,
char
**
argv
){
int
i
;
// Tableau dynamique.
arraylist_t
*
a
=
arraylist_create
();
// Analyse du temps pris par les opérations.
analyzer_t
*
time_analysis
=
analyzer_create
();
// Analyse du nombre de copies faites par les opérations.
analyzer_t
*
copy_analysis
=
analyzer_create
();
// Analyse du nombre d'echange pour chaque insertion.
analyzer_t
*
swap_analysis
=
analyzer_create
();
// Analyse de l'espace mémoire inutilisé.
analyzer_t
*
memory_analysis
=
analyzer_create
();
// Mesure de la durée d'une opération.
struct
timespec
before
,
after
;
clockid_t
clk_id
=
CLOCK_REALTIME
;
// utilisé comme booléen pour savoir si une allocation a été effectuée.
//char memory_allocation;
srand
(
time
(
NULL
));
// Probabilité d'insertion p = 0.7.
float
prob
=
0
.
7
;
// variable aleatoire.
float
val
;
// Le nombre à inserer dans le tas.
int
insertIntoTas
;
char
memory_allocation
;
for
(
i
=
0
;
i
<
1000000
;
i
++
){
val
=
(
float
)
rand
()
/
(
float
)
RAND_MAX
;
insertIntoTas
=
rand
()
%
1000000
;
if
(
val
<=
prob
)
{
// Ajout d'un élément et mesure du temps pris par l'opération.
clock_gettime
(
clk_id
,
&
before
);
memory_allocation
=
arraylist_append
(
a
,
insertIntoTas
);
clock_gettime
(
clk_id
,
&
after
);
// Enregistrement du temps pris par l'opération
analyzer_append
(
time_analysis
,
after
.
tv_nsec
-
before
.
tv_nsec
);
// Enregistrement du nombre de copies efféctuées par l'opération.
// S'il y a eu réallocation de mémoire, il a fallu recopier tout le tableau.
analyzer_append
(
copy_analysis
,
(
memory_allocation
)
?
i
:
1
);
// Enregistrement de l'espace mémoire non-utilisé.
analyzer_append
(
memory_analysis
,
arraylist_capacity
(
a
)
-
arraylist_size
(
a
));
// Enregistrement du nombre d'echange effectué.
analyzer_append
(
swap_analysis
,
getCountSwap
(
a
));
}
else
{
// Ajout d'un élément et mesure du temps pris par l'opération.
clock_gettime
(
clk_id
,
&
before
);
memory_allocation
=
arraylist_pop_back
(
a
);
clock_gettime
(
clk_id
,
&
after
);
// Enregistrement du temps pris par l'opération
analyzer_append
(
time_analysis
,
after
.
tv_nsec
-
before
.
tv_nsec
);
// Enregistrement du nombre de copies efféctuées par l'opération.
// S'il y a eu réallocation de mémoire, il a fallu recopier tout le tableau.
analyzer_append
(
copy_analysis
,
(
memory_allocation
)
?
i
:
1
);
// Enregistrement de l'espace mémoire non-utilisé.
analyzer_append
(
memory_analysis
,
arraylist_capacity
(
a
)
-
arraylist_size
(
a
));
// Enregistrement du nombre d'echange effectué.
analyzer_append
(
swap_analysis
,
getCountSwap
(
a
));
}
}
// Affichage de quelques statistiques sur l'expérience.
fprintf
(
stderr
,
"Total cost: %Lf
\n
"
,
get_total_cost
(
time_analysis
));
fprintf
(
stderr
,
"Average cost: %Lf
\n
"
,
get_average_cost
(
time_analysis
));
fprintf
(
stderr
,
"Variance: %Lf
\n
"
,
get_variance
(
time_analysis
));
fprintf
(
stderr
,
"Standard deviation: %Lf
\n
"
,
get_standard_deviation
(
time_analysis
));
// Sauvegarde les données de l'expérience.
save_values
(
time_analysis
,
"../plots/dynamic_array_time_c.plot"
);
save_values
(
copy_analysis
,
"../plots/dynamic_array_copy_c.plot"
);
save_values
(
memory_analysis
,
"../plots/dynamic_array_memory_c.plot"
);
save_values
(
swap_analysis
,
"../plots/dynamic_array_swap_c.plot"
);
// Nettoyage de la mémoire avant la sortie du programme
arraylist_destroy
(
a
);
analyzer_destroy
(
time_analysis
);
analyzer_destroy
(
copy_analysis
);
analyzer_destroy
(
memory_analysis
);
analyzer_destroy
(
swap_analysis
);
return
EXIT_SUCCESS
;
}
C/main.c
View file @
800a5a01
...
...
@@ -13,28 +13,60 @@ int main(int argc, char ** argv){
analyzer_t
*
time_analysis
=
analyzer_create
();
// Analyse du nombre de copies faites par les opérations.
analyzer_t
*
copy_analysis
=
analyzer_create
();
// Analyse du nombre d'echange pour chaque insertion.
analyzer_t
*
swap_analysis
=
analyzer_create
();
// Analyse de l'espace mémoire inutilisé.
analyzer_t
*
memory_analysis
=
analyzer_create
();
// Mesure de la durée d'une opération.
struct
timespec
before
,
after
;
clockid_t
clk_id
=
CLOCK_REALTIME
;
// utilisé comme booléen pour savoir si une allocation a été effectuée.
char
memory_allocation
;
//
char memory_allocation;
srand
(
time
(
NULL
));
// Probabilité d'insertion p = 0.7.
float
prob
=
0
.
7
;
// variable aleatoire.
float
val
;
// Le nombre à inserer dans le tas.
int
insertIntoTas
;
char
memory_allocation
;
for
(
i
=
0
;
i
<
1000000
;
i
++
){
// Ajout d'un élément et mesure du temps pris par l'opération.
clock_gettime
(
clk_id
,
&
before
);
memory_allocation
=
arraylist_append
(
a
,
i
);
clock_gettime
(
clk_id
,
&
after
);
// Enregistrement du temps pris par l'opération
analyzer_append
(
time_analysis
,
after
.
tv_nsec
-
before
.
tv_nsec
);
// Enregistrement du nombre de copies efféctuées par l'opération.
// S'il y a eu réallocation de mémoire, il a fallu recopier tout le tableau.
analyzer_append
(
copy_analysis
,
(
memory_allocation
)
?
i
:
1
);
// Enregistrement de l'espace mémoire non-utilisé.
analyzer_append
(
memory_analysis
,
arraylist_capacity
(
a
)
-
arraylist_size
(
a
));
val
=
(
float
)
rand
()
/
(
float
)
RAND_MAX
;
insertIntoTas
=
rand
()
%
1000000
;
if
(
val
<=
prob
)
{
// Ajout d'un élément et mesure du temps pris par l'opération.
clock_gettime
(
clk_id
,
&
before
);
memory_allocation
=
arraylist_append
(
a
,
insertIntoTas
);
clock_gettime
(
clk_id
,
&
after
);
// Enregistrement du temps pris par l'opération
analyzer_append
(
time_analysis
,
after
.
tv_nsec
-
before
.
tv_nsec
);
// Enregistrement du nombre de copies efféctuées par l'opération.
// S'il y a eu réallocation de mémoire, il a fallu recopier tout le tableau.
analyzer_append
(
copy_analysis
,
(
memory_allocation
)
?
i
:
1
);
// Enregistrement de l'espace mémoire non-utilisé.
analyzer_append
(
memory_analysis
,
arraylist_capacity
(
a
)
-
arraylist_size
(
a
));
// Enregistrement du nombre d'echange effectué.
analyzer_append
(
swap_analysis
,
getCountSwap
(
a
));
}
else
{
// Ajout d'un élément et mesure du temps pris par l'opération.
clock_gettime
(
clk_id
,
&
before
);
memory_allocation
=
arraylist_pop_back
(
a
);
clock_gettime
(
clk_id
,
&
after
);
// Enregistrement du temps pris par l'opération
analyzer_append
(
time_analysis
,
after
.
tv_nsec
-
before
.
tv_nsec
);
// Enregistrement du nombre de copies efféctuées par l'opération.
// S'il y a eu réallocation de mémoire, il a fallu recopier tout le tableau.
analyzer_append
(
copy_analysis
,
(
memory_allocation
)
?
i
:
1
);
// Enregistrement de l'espace mémoire non-utilisé.
analyzer_append
(
memory_analysis
,
arraylist_capacity
(
a
)
-
arraylist_size
(
a
));
// Enregistrement du nombre d'echange effectué.
analyzer_append
(
swap_analysis
,
getCountSwap
(
a
));
}
}
// Affichage de quelques statistiques sur l'expérience.
...
...
@@ -47,11 +79,13 @@ int main(int argc, char ** argv){
save_values
(
time_analysis
,
"../plots/dynamic_array_time_c.plot"
);
save_values
(
copy_analysis
,
"../plots/dynamic_array_copy_c.plot"
);
save_values
(
memory_analysis
,
"../plots/dynamic_array_memory_c.plot"
);
save_values
(
swap_analysis
,
"../plots/dynamic_array_swap_c.plot"
);