biomcmc-lib  0.1
low level library for phylogenetic analysis
Macros | Functions
lowlevel.c File Reference

Lowest level basic functions, that should be available to all other modules. More...

#include "lowlevel.h"
Include dependency graph for lowlevel.c:

Macros

#define MIN_CHUNK   128
 

Functions

void hungarian_solve_integer (hungarian p, int this_size)
 
void hungarian_solve_double (hungarian p, int this_size)
 
void * biomcmc_malloc (size_t size)
 Memory-safe malloc() function. More...
 
void * biomcmc_realloc (void *ptr, size_t size)
 Memory-safe realloc() function. More...
 
FILE * biomcmc_fopen (const char *path, const char *mode)
 Memory-safe fopen() function. More...
 
void biomcmc_error (const char *template,...)
 Prints error message and quits program. More...
 
int compare_int_increasing (const void *a, const void *b)
 Comparison between integers, doubles, etc. used by qsort()
 
int compare_int_decreasing (const void *a, const void *b)
 
int compare_uint64_increasing (const void *a, const void *b)
 
int compare_uint64_decreasing (const void *a, const void *b)
 
int compare_double_increasing (const void *a, const void *b)
 
int compare_double_decreasing (const void *a, const void *b)
 
int biomcmc_getline (char **lineptr, size_t *n, FILE *stream)
 read file line-by-line (like homonymous function from GNU C library) More...
 
uint32_t biomcmc_levenshtein_distance (const char *s1, uint32_t n1, const char *s2, uint32_t n2, uint32_t cost_sub, uint32_t cost_indel, bool skip_borders)
 edit distance between two sequences (slow), with option to allow one of sequences to terminate soon (o.w. global cost from end to end)
 
void hungarian_reset (hungarian p)
 
hungarian new_hungarian (int size, bool is_double)
 
void hungarian_update_cost (hungarian p, int row, int col, void *cost)
 
void del_hungarian (hungarian p)
 
void hungarian_solve (hungarian p, int this_size)
 

Detailed Description

Lowest level basic functions, that should be available to all other modules.

Function Documentation

◆ biomcmc_malloc()

void* biomcmc_malloc ( size_t  size)

Memory-safe malloc() function.

Allocates size bytes and returns a pointer to the allocated memory. An error message is thrown in case of failure.

Parameters
[in]sizeallocated size, in bytes
Returns
pointer to newly allocated memory

◆ biomcmc_realloc()

void* biomcmc_realloc ( void *  ptr,
size_t  size 
)

Memory-safe realloc() function.

Changes the size of the memory block pointed to by ptr to size bytes. An error message is thrown in case of failure.

Parameters
[in]sizeallocated size, in bytes
[in,out]ptrpointer to previously allocated memory
Returns
pointer to newly allocated memory

◆ biomcmc_fopen()

FILE* biomcmc_fopen ( const char *  path,
const char *  mode 
)

Memory-safe fopen() function.

Opens the file whose name is the string pointed to by path and associates a stream with it. An error message is thrown in case of failure.

Parameters
[in]pathfile name
[in]modeopening mode ("r" for reading, "w" for writing, etc)
Returns
pointer to file stream

◆ biomcmc_error()

void biomcmc_error ( const char *  template,
  ... 
)

Prints error message and quits program.

similar to fprintf (stderr, ...), but exits after printing the message

Parameters
[in]templateva_list following same format as printf()
Returns
exits program

◆ biomcmc_getline()

int biomcmc_getline ( char **  lineptr,
size_t *  n,
FILE *  stream 
)

read file line-by-line (like homonymous function from GNU C library)

This implementation is originally from the CvsGui project (http://www.wincvs.org/). The explanation from the original file adapted to our system follows:

Read up to (and including) a newline ("\n") from STREAM into *LINEPTR and null-terminate it. *LINEPTR is a pointer 
returned from malloc (or NULL), pointing to *N characters of space.  It is realloc'd as necessary.  Return the 
number of characters read (not including the null terminator), or -1 on error or EOF.