From 3568412f8f230774d0d11d7ed1c897424f95d3ef Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 11 Nov 2021 21:37:34 +0100 Subject: Rewritten from scratch. Welocme nissy 2.0! --- src/utils.h | 99 +++++++++++++++++++++++++------------------------------------ 1 file changed, 41 insertions(+), 58 deletions(-) (limited to 'src/utils.h') diff --git a/src/utils.h b/src/utils.h index 45a6302..80c33ae 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,58 +1,41 @@ -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#define abs(a) (((a) > 0) ? (a) : (-(a))) - -/* Some useful constants */ -#define pow2to11 2048 -#define pow2to12 4096 -#define pow3to7 2187 -#define pow3to8 6561 -#define pow12to4 20736 -#define factorial4 24 -#define factorial6 720 -#define factorial8 40320 -#define factorial12 479001600 -#define binom12on4 495 -#define binom8on4 70 - -void swap(int *a, int *b); - -/* Hardcoded factorial of small numbers (n<=12). */ -extern int factorial[13]; - -/* Converts the integer a to its representation in base b (first n digits - * only) and saves the result in r. */ -void int_to_digit_array(int a, int b, int n, int *r); - -/* Converts the array of n digits a to a integer using base b. */ -int digit_array_to_int(int *a, int n, int b); - -/* Converts a permutation on [0..(n-1)] into the integer i which is the index - * of the permutation in the sorted list of all n! such permutations. - * Only works for n<=12. */ -int perm_to_index(int *a, int n); - -/* Converts a permutation index to the actual permutation as an array - * (see perm_to_index) and saves the result to r. */ -void index_to_perm(int p, int n, int *r); - -/* Determine the sign of a permutation, either in integer or array format. */ -int perm_sign_array(int a[], int n); -int perm_sign_int(int p, int n); - -/* Converts a k-element subset of a set with an element from an array of n - * elements, of which k are 1 and n-k are 0, to its index in the sorted list - * of all such subsets. - * Works only for n <= 12. */ -int subset_to_index(int *a, int n, int k); - -/* Inverse of the above */ -void index_to_subset(int s, int n, int k, int *r); - -/* Converts the first n-1 digits of a number to an array a of digits in base b; - * then adds one element to the array, so that the sum of the elements of a is - * zero modulo b. - * This is used for determing the edge orientation from an 11-bits integer or - * the corner orientation from a 7-trits integer. */ -void int_to_sum_zero_array(int x, int b, int n, int *a); - +#ifndef UTILS_H +#define UTILS_H + +#include +#include +#include + +#define POW2TO6 64ULL +#define POW2TO11 2048ULL +#define POW2TO12 4096ULL +#define POW3TO7 2187ULL +#define POW3TO8 6561ULL +#define FACTORIAL4 24ULL +#define FACTORIAL6 720ULL +#define FACTORIAL7 5040ULL +#define FACTORIAL8 40320ULL +#define FACTORIAL12 479001600ULL +#define BINOM12ON4 495ULL +#define BINOM8ON4 70ULL +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) + +void apply_permutation(int *perm, int *set, int n); +int binomial(int n, int k); +int digit_array_to_int(int *a, int n, int b); +int factorial(int n); +void index_to_perm(int p, int n, int *r); +void index_to_subset(int s, int n, int k, int *r); +void int_to_digit_array(int a, int b, int n, int *r); +void int_to_sum_zero_array(int x, int b, int n, int *a); +int invert_digits(int a, int b, int n); +bool is_perm(int *a, int n); +bool is_subset(int *a, int n, int k); +int perm_sign(int *a, int n); +int perm_to_index(int *a, int n); +int powint(int a, int b); +int subset_to_index(int *a, int n, int k); +void sum_arrays_mod(int *src, int *dst, int n, int m); +void swap(int *a, int *b); + +#endif -- cgit v1.3