Commit 9a0c2915 authored by Alix Danvy's avatar Alix Danvy
Browse files

truc

parent e3deb1ac
Loading
Loading
Loading
Loading

src/bignum.c

deleted100644 → 0
+0 −96
Changes for src/bignum.c: 0 added lines, 96 removed lines.
Original line number Diff line number Diff line
#include <stdlib.h>
#include <gmp.h>

typedef mpz_t* bignum_t;

bignum_t bignum_zero(){
  bignum_t x = (bignum_t) malloc(sizeof(mpz_t));
  mpz_init(*x);
  return x;
}

bignum_t bignum_from_int(int n){
  bignum_t x = (bignum_t) malloc(sizeof(mpz_t));
  mpz_init_set_si(*x, (signed long int) n);
  return x;
}

bignum_t bignum_copy(bignum_t x){
  bignum_t y = bignum_zero();
  mpz_set(*y, *x);
  return y;
}

void bignum_destroy(bignum_t x){
  mpz_clear(*x);
  free(x);
}

int bignum_eq(bignum_t a, bignum_t b){
  return mpz_cmp(*a, *b) == 0;
}

int bignum_lte(bignum_t a, bignum_t b){
  return mpz_cmp(*a, *b) <= 0;
}


int bignum_lt(bignum_t a, bignum_t b){
  return mpz_cmp(*a, *b) < 0;
}


int bignum_gt(bignum_t a, bignum_t b){
  return mpz_cmp(*a, *b) > 0;
}

int bignum_gte(bignum_t a, bignum_t b){
  return mpz_cmp(*a, *b) >= 0;
}

bignum_t bignum_add(bignum_t a, bignum_t b){
  bignum_t x = bignum_zero();
  mpz_add(*x, *a, *b);
  return x;
}
  
bignum_t bignum_sub(bignum_t a, bignum_t b){
  bignum_t x = bignum_zero();
  mpz_sub(*x, *a, *b);
  return x;
}

bignum_t bignum_mul(bignum_t a, bignum_t b){
  bignum_t x = bignum_zero();
  mpz_mul(*x, *a, *b);
  return x;
}

bignum_t bignum_div(bignum_t a, bignum_t b){
  bignum_t x = bignum_zero();
  mpz_div(*x, *a, *b);
  return x;
}

bignum_t bignum_mod(bignum_t a, bignum_t b){
  bignum_t x = bignum_zero();
  mpz_mod(*x, *a, *b);
  return x;
}

bignum_t bignum_powm(bignum_t x, bignum_t n, bignum_t m){
  bignum_t z = bignum_zero();
  mpz_powm(*z, *x, *n, *m);
  return z;
}

bignum_t bignum_pow(bignum_t x, bignum_t exp){
  bignum_t z = bignum_zero();
  unsigned long int e = mpz_get_ui(*exp);
  mpz_pow_ui(*z, *x, e);
  return z;
}

char* bignum_to_str(bignum_t x){
  return mpz_get_str(NULL, 10, *x);
}

src/bignum.h

deleted100644 → 0
+0 −28
Changes for src/bignum.h: 0 added lines, 28 removed lines.
Original line number Diff line number Diff line
#ifndef __BIGNUM__
#define __BIGNUM__
#include  <gmp.h>


typedef mpz_t* bignum_t;

bignum_t bignum_zero();
bignum_t bignum_from_int(int);
bignum_t bignum_copy(bignum_t);
void bignum_destroy(bignum_t);

int bignum_eq(bignum_t, bignum_t);
int bignum_lt(bignum_t, bignum_t);
int bignum_lte(bignum_t, bignum_t);
int bignum_gt(bignum_t, bignum_t);
int bignum_gte(bignum_t, bignum_t);

bignum_t bignum_add(bignum_t, bignum_t);
bignum_t bignum_sub(bignum_t, bignum_t);
bignum_t bignum_mul(bignum_t, bignum_t);
bignum_t bignum_div(bignum_t, bignum_t);
bignum_t bignum_mod(bignum_t, bignum_t);
bignum_t bignum_powm(bignum_t, bignum_t, bignum_t);
bignum_t bignum_pow(bignum_t, bignum_t);

char* bignum_to_str(bignum_t);
#endif

src/bignum.o

0 → 100644
+9.69 KiB

File added.

No diff preview for this file type.

src/bst.o

0 → 100644
+4.66 KiB

File added.

No diff preview for this file type.

src/hash_tbl.c

deleted100644 → 0
+0 −31
Changes for src/hash_tbl.c: 0 added lines, 31 removed lines.
Original line number Diff line number Diff line
#include <stddef.h>
#include "list.h"
#include "hash_tbl.h"

#define ARRAY_CAPACITY 1 << 16

// struct hash_tbl {
//   size_t (*h)(void*);
//   int (*eq)(void*, void*);
//   void (*free)(void*);
//   unsigned long int size;
//   size_t capacity; // array length
//   list_t* array;
// };

typedef struct hash_tbl* hash_tbl;

hash_tbl htbl_empty(size_t (*h)(void*),
                    int (*eq)(void*, void*),
                    void (*free)(void*)){
}

int htbl_add(hash_tbl htbl, void* x){
}

int htbl_in(hash_tbl htbl, void* x){
}

void htbl_destroy(hash_tbl htbl){
}
  
Loading