CAFE
Computational Analysis of gene Family Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
chooseln_cache.h
Go to the documentation of this file.
1 #ifndef CHOOSELN_CACHE_H_2C3C614A_C14D_477A_B8A0_30AE50238D9E
2 #define CHOOSELN_CACHE_H_2C3C614A_C14D_477A_B8A0_30AE50238D9E
3 
11 #include <assert.h>
12 
13 #include <mathfunc.h>
14 #include <memalloc.h>
15 
17  double** values;
18  int size;
19 };
20 
23 void chooseln_cache_init2(struct chooseln_cache *cache, int size);
24 void chooseln_cache_resize2(struct chooseln_cache *cache, int resize);
26 
27 static inline double chooseln_get2(struct chooseln_cache *cache, int n, int x)
28 {
29  assert(n < cache->size * 2);
30  assert(x <= cache->size);
31  if (cache->values[n] && cache->values[n][x] >= 0) return cache->values[n][x];
32  if (cache->values[n] == NULL)
33  {
34  int i;
35  cache->values[n] = (double*)memory_new(cache->size + 1, sizeof(double));
36  for (i = 0; i <= cache->size; i++)
37  cache->values[n][i] = -1.0;
38  }
39  cache->values[n][x] = chooseln(n, x);
40  return cache->values[n][x];
41 }
42 
43 #endif
double ** values
Definition: chooseln_cache.h:17
int size
Definition: chooseln_cache.h:18
int get_chooseln_cache_size2(struct chooseln_cache *cache)
Definition: chooseln_cache.c:10
void * memory_new(size_t count, size_t size)
Definition: memalloc.c:4
void chooseln_cache_resize2(struct chooseln_cache *cache, int resize)
Definition: chooseln_cache.c:36
struct chooseln_cache cache
A cache of values of chooseln.
Definition: birthdeath.c:32
int chooseln_is_init2(struct chooseln_cache *cache)
Definition: chooseln_cache.c:5
double chooseln(double n, double r)
Definition: mathfunc.c:224
A cache of values of chooseln.
Definition: chooseln_cache.h:16
void chooseln_cache_init2(struct chooseln_cache *cache, int size)
Definition: chooseln_cache.c:58
void chooseln_cache_free2(struct chooseln_cache *cache)
Definition: chooseln_cache.c:70