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
83 86 77 15 93 35 86 92 49 21 62 27 90 59 63 26 40 26 72 36 11 68 67 29 82 30 62 23 67 35 29 2 22 58 69 67 93 56 11 42 29 73 21 19 84 37 98 24 15 70 13 26 91 80 56 73 62 70 96 81 5 25 84 27 36 5 46 29 13 57 24 95 82 45 14 67 34 64 43 50 87 8 76 78 88 84 3 51 54 99 32 60 76 68 39 12 26 86 94 39 .
#include "triFusion.h"
void sousTriFusion(long * A, size_t p, size_t r){
if(p<(r-1)){
size_t q = (size_t)((p+r)/2);
sousTriFusion(A, p, q);
sousTriFusion(A, q, r);
fusion(A, p, q, r);
}
}
void fusion(long * A, size_t p, size_t q, size_t r){
size_t n1 = q-p;
size_t n2 = r-q;
long Ad[n2];
memset(Ad, 0, n2);
int j =0;
for(size_t i = q; i<r; i++){
Ad[j] = A[i];
j++;
}
long Ag[n1];
memset(Ag, 0, n1);
j =0;
for(size_t i = p; i<q; i++){
Ag[j] = A[i];
j++;
}
size_t indg = 0;
size_t indd = 0;
size_t i = p;
while (i < r){
if(indg == n1){
A[i] = Ad[indd];
indd++;
}
else if(indd == n2){
A[i] == Ag[indg];
indg++;
}
else if(Ag[indg] < Ad[indd]){
A[i] = Ag[indg];
indg++;
}
else{
A[i] = Ad[indd];
indd++;
}
i++;
}
}
void triFusion(long * A, size_t n){
sousTriFusion(A, 0, n);
}
// --------------------------------------------------------
void sousTriFusionVerbose(long * A, size_t p, size_t r, struct data* d){
if(p<(r-1)){
d->comparison++;
size_t q = (size_t)((p+r)/2);
d->write++;
sousTriFusionVerbose(A, p, q,d);
sousTriFusionVerbose(A, q, r, d);
fusionVerbose(A, p, q, r, d);
}
}
void fusionVerbose(long * A, size_t p, size_t q, size_t r, struct data* d){
size_t n1 = q-p;
d->write++;
size_t n2 = r-q;
d->write++;
long Ad[n2];
memset(Ad, 0, n2);
d->write+=n2;
int j = 0;
for(size_t i = q; i<r; i++){
Ad[j] = A[i];
d->write++;
j++;
d->write++;
}
long Ag[n1];
memset(Ag, 0, n1);
d->write+=n1;
j = 0;
for(size_t i = p; i<q; i++){
Ag[j] = A[i];
d->write++;
j++;
d->write++;
}
size_t indg = 0;
size_t indd = 0;
size_t i = p;
d->write++;
while (i < r){
d->comparison++;
if(indg == n1){
d->comparison++;
A[i] = Ad[indd];
d->write++;
indd++;
d->write++;
}
else if(indd == n2){
d->comparison+=2;
A[i] == Ag[indg];
d->write++;
indg++;
d->write++;
}
else if(Ag[indg] < Ad[indd]){
d->comparison+=3;
A[i] = Ag[indg];
d->write++;
indg++;
d->write++;
}
else{
d->comparison+=4;
A[i] = Ad[indd];
d->write++;
indd++;
d->write++;
}
i++;
d->write++;
}
}
void triFusionVerbose(long * A, size_t n, struct data* d){
sousTriFusionVerbose(A, 0, n, d);
}
\ No newline at end of file
#ifndef triFusion_h
#define triFusion_h
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include "utils.h"
void sousTriFusion(long * A, size_t p, size_t r);
void fusion(long * A, size_t p, size_t q, size_t r);
void triFusion(long * A, size_t n);
void sousTriFusionVerbose(long * A, size_t p, size_t r, struct data* d);
void fusionVerbose(long * A, size_t p, size_t q, size_t r, struct data* d);
void triFusionVerbose(long * A, size_t n, struct data* d);
#endif
\ No newline at end of file
File added
#include "triInsertion.h"
void triInsertion(long* A, size_t n){
long cle = 0;
size_t max = 0; max--;
for(size_t i = 1; i<n; i++){
cle=A[i];
size_t j = i - 1;
while (j != max && A[j] > cle ){
A[j+1] = A[j];
j = j-1;
}
A[j+1] = cle;
}
}
// --------------------------------------------------------
void triInsertionVerbose(long* A, size_t n, struct data* d){
long cle = 0;
size_t max = 0; max--;
d->write++;
for(size_t i = 1; i<n; i++){
cle=A[i];
d->write++;
size_t j = i - 1;
d->write++;
while (j != max && A[j] > cle ){
d->comparison+=2;
A[j+1] = A[j];
d->write++;
j = j-1;
d->write++;
}
A[j+1] = cle;
d->write++;
}
}
\ No newline at end of file
#ifndef triInsertion_h
#define triInsertion_h
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include "utils.h"
void triInsertion(long* A, size_t n);
void triInsertionVerbose(long* A, size_t n, struct data* d);
#endif
\ No newline at end of file
File added
#include "triRapide.h"
void sousTriRapide(long* A, size_t p, size_t r) {
size_t max = 0; max--;
if(r-1 != max){
if (p<(r-1)) {
size_t q = partition(A, p, r);
sousTriRapide(A, p, q);
sousTriRapide(A, q+1, r);
}
}
}
size_t partition(long* A, size_t p, size_t r) {
long pivot = A[r-1];
size_t i = p;
for (size_t j = p; j <= r-2; j++) {
if (A[j] <= pivot) {
long temp = A[i];
A[i] = A[j];
A[j] = temp;
i++;
}
}
long temp = A[i];
A[i] = A[r-1];
A[r-1] = temp;
return i;
}
void triRapide(long* A, size_t n) {
sousTriRapide(A, 0, n);
}
// --------------------------------------------------------
void sousTriRapideVerbose(long* A, size_t p, size_t r, struct data* d) {
size_t max = 0; max--;
d->write++;
if(r-1 != max){
d->comparison++;
if (p<(r-1)) {
d->comparison++;
size_t q = partitionVerbose(A, p, r, d);
d->write++;
sousTriRapideVerbose(A, p, q, d);
sousTriRapideVerbose(A, q+1, r, d);
}
}
}
size_t partitionVerbose(long* A, size_t p, size_t r, struct data* d) {
long pivot = A[r-1];
d->write++;
size_t i = p;
d->write++;
for (size_t j = p; j <= r-2; j++) {
if (A[j] <= pivot) {
d->comparison++;
long temp = A[i];
d->write++;
A[i] = A[j];
d->write++;
A[j] = temp;
d->write++;
i++;
d->write++;
}
}
long temp = A[i];
d->write++;
A[i] = A[r-1];
d->write++;
A[r-1] = temp;
d->write++;
return i;
}
void triRapideVerbose(long* A, size_t n, struct data* d) {
sousTriRapideVerbose(A, 0, n, d);
}
\ No newline at end of file
#ifndef triRapide_h
#define triRapide_h
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include "utils.h"
void triRapide(long* A, size_t n);
size_t partition(long* A, size_t p, size_t r);
void sousTriRapide(long* A, size_t p, size_t r);
void triRapideVerbose(long* A, size_t n, struct data* d);
size_t partitionVerbose(long* A, size_t p, size_t r, struct data* d);
void sousTriRapideVerbose(long* A, size_t p, size_t r, struct data* d);
#endif
\ No newline at end of file
File added
#include "utils.h"
int readToTab(long* tab, char* file){
int n = 0;
int fd = open(file, O_RDONLY);
if(fd == -1){
perror("open");
exit(1);
}
size_t j = 0, x=0, count = 1, sizet = 1000, nb_size = 1;
char* tmp = malloc(sizeof(char)*sizet);
memset(tmp, 0, 1000);
char temp;
read(fd,&temp,sizeof(char));
while(temp != '.'){
// printf("n:%d j:%d nb_size:%d\n", n,j,nb_size);
if(temp != ' '){
tmp[x] = temp;
x++;
}
else if(temp == ' '){
long t = atol(tmp);
tab[j] = t;
//printf("char:%c long:%d n:%d j:%d nb_size:%d, size:%d\n",temp,tab[j], n,j,nb_size, sizet);
printf("%s\n", tmp);
memset(tmp, 0, sizet*nb_size);
j++;
count++;
x=0;
n++;
}
read(fd,&temp,sizeof(char));
if(n==sizet*nb_size){
nb_size+=1;
//printf("size:%d nb_size:%d, sizef:%d\n", sizet, nb_size, sizeof(char)*(sizet*nb_size));
tmp = realloc(tmp, sizeof(char)*(sizet*nb_size));
}
}
return n-1;
}
void initData(struct data* d){
d->time = 0;
d->comparison = 0;
d->ct_fusion = 0;
d->ct_parse = 0;
d->write = 0;
}
long* generate_tab(size_t max, size_t length){
if(length==0){
return 0;
}
long* tab = malloc(sizeof(long)*length);
memset(tab, 0, sizeof(long)*length);
size_t index = 0;
for(index = 0; index<length; index++){
long p = (long)(rand()%max);
tab[index] = p;
}
return tab;
}
void printData(struct data d){
printf("Time passed : %ld\n", d.time);
printf("Number of comparison : %ld\n", d.comparison);
printf("Number of write : %ld\n", d.write);
printf("Call of fusion : %ld\n", d.ct_fusion);
printf("Call of parsing : %ld\n", d.ct_parse);
}
\ No newline at end of file
#ifndef utils_h
#define utils_h
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
struct data {
long time;
unsigned int write;
unsigned int comparison;
unsigned int ct_fusion;
unsigned int ct_parse;
};
int readToTab(long* tab, char* file);
void initData(struct data* d);
long* generate_tab(size_t max, size_t length);
void printData(struct data d);
#endif
File added
#!/usr/bin/python
from sys import argv
from math import *
def Helloworld1(n):
count = 0
for i in range(0,n):
for j in range(0, n):
print("Helloworld")
count += 1
return count
def Helloworld2(n):
count = 0
for i in range(0,n):
for j in range(i, n):
print("Helloworld")
count +=1
return count
def Helloworld3(n):
count = 0
if(n>1):
Helloworld3(n/2)
Helloworld3(n-(n/2))
count+=1
print("Helloworld")
return count
def version(i, n):
if(i==1):
l = Helloworld1(n)
print(l)
elif(i==2):
l=Helloworld2(n)
print(l)
elif(i==3):
l=Helloworld3(n)
# print(l)
else:
print("non")
res = log(n)
print("log count : ", res)
print("nb : ", n*res)
if(len(argv[1:])):
versio = int(argv[1])
nb = int(argv[2])
version(versio,nb)
\ No newline at end of file
op = [10, 100, 1000, 10000, 100000, 1000000]
aps = 1000
for i in op:
print("--------------", i, "---------")
print("n : ", i/aps , "s")
print("ln(n) : ", log10(i)/aps , "s")
print("n.log(n) : ", (i*(log10(i)))/aps , "s")
print("nRacine(n) : ", sqrt(i)/aps , "s")
print("n² : ", (pow(i,2))/aps , "s")
print("n³ : ", (pow(i,3))/aps/3600/24 , "jours")
if(i < 10000):
print("2^n : ", (((((pow(2,i))/aps)/3600)/24)/365)/1000000000000000000 , "Quatrillion années")
if(i <1000):
print("fact(n) : ", (((((factorial(i)/aps)/3600)/24)/365)/1000000000000000000) , "Quatrillion années" )