biomcmc-lib  0.1
low level library for phylogenetic analysis
Data Structures | Macros | Typedefs | Functions
lowlevel.h File Reference

Lowest level header file. Header file for lowlevel.c. More...

#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdint.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
#include <assert.h>
#include <libgen.h>
Include dependency graph for lowlevel.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  hungarian_struct
 

Macros

#define EXP_1   2.71828182845904523536028747135266 /* Euler's number */
 
#define true   1U
 
#define false   0U
 
#define attribute_FALLTHROUGH   ((void)0);
 
#define MIN(x, y)   (((x)<(y)) ? (x) : (y))
 
#define MAX(x, y)   (((x)>(y)) ? (x) : (y))
 
#define MOD(a)   (((a)>0) ? (a) :(-a))
 

Typedefs

typedef unsigned char bool
 Mnemonic for boolean (char is smaller than int)
 
typedef struct hungarian_structhungarian
 

Functions

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)
 
hungarian new_hungarian (int size, bool is_double)
 
void hungarian_reset (hungarian p)
 
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 header file. Header file for lowlevel.c.

Macro Definition Documentation

◆ true

#define true   1U

Boolean TRUE

◆ false

#define false   0U

Boolean FALSE

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.