From 471b18a7f4e9cbdfb510f304260ec5e6baeee697 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sun, 7 Mar 2010 14:39:14 +0100 Subject: [PATCH] Simplified misc.h and misc.cc. --- misc.cc | 65 --------------------------------------------------------- misc.h | 12 +++++++++++ 2 files changed, 12 insertions(+), 65 deletions(-) diff --git a/misc.cc b/misc.cc index ddcaf6d..3affb33 100644 --- a/misc.cc +++ b/misc.cc @@ -27,68 +27,3 @@ using namespace std; #include "misc.h" - -char *next_word(char *buffer, char *r, int buffer_size) { - char *s; - s = buffer; - - if(r != 0) { - while((*r == ' ') || (*r == '\t') || (*r == ',')) r++; - if(*r == '"') { - r++; - while((*r != '"') && (*r != '\0') && - (s 0) { - s += n[k] * log(scalar_t(n[k])); - t += n[k]; - } - return (log(t) - s/scalar_t(t))/log(2.0); -} - -void random_permutation(int *val, int nb) { - for(int k = 0; k < nb; k++) val[k] = k; - int i, t; - for(int k = 0; k < nb - 1; k++) { - i = int(drand48() * (nb - k)) + k; - t = val[i]; - val[i] = val[k]; - val[k] = t; - } -} - -void tag_subset(bool *val, int nb_total, int nb_to_tag) { - ASSERT(nb_to_tag <= nb_total); - int index[nb_total]; - random_permutation(index, nb_total); - for(int n = 0; n < nb_total; n++) val[n] = false; - for(int n = 0; n < nb_to_tag; n++) val[index[n]] = true; -} - -int compare_couple(const void *a, const void *b) { - if(((Couple *) a)->value < ((Couple *) b)->value) return -1; - else if(((Couple *) a)->value > ((Couple *) b)->value) return 1; - else return 0; -} diff --git a/misc.h b/misc.h index e3dbab2..e101861 100644 --- a/misc.h +++ b/misc.h @@ -82,4 +82,16 @@ inline scalar_t log2(scalar_t x) { return log(x)/log(2.0); } +template +void grow(int *nb_max, int nb, T** current, int factor) { + ASSERT(*nb_max > 0); + if(nb == *nb_max) { + T *tmp = new T[*nb_max * factor]; + memcpy(tmp, *current, *nb_max * sizeof(T)); + delete[] *current; + *current = tmp; + *nb_max *= factor; + } +} + #endif -- 2.39.5