Legofit
infers population history from nucleotide site patterns.
Data Structures | Functions
strdblmap.c File Reference

Map char* to double. More...

#include "strdblmap.h"
#include "error.h"
#include "binary.h"
#include "misc.h"
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <sys/errno.h>

Data Structures

struct  El
 A single key-value pair, with a pointer to the next one. More...
 
struct  StrDblMap
 The hash table. More...
 

Functions

static int resize (StrDblMap *self)
 Double the size of the hash map and rehash.
 
static ElEl_new (const char *key, double value)
 Construct a new element with given key and value.
 
static void El_free (El *e)
 Destroy a linked list of El objects.
 
static ElEl_insert (El *self, const char *key, double value, int *status)
 Insert a new key/value pair into the linked list. More...
 
StrDblMapStrDblMap_new (int dim)
 Constructor.
 
void StrDblMap_free (StrDblMap *self)
 Destructor.
 
double StrDblMap_get (StrDblMap *self, const char *key, int *status)
 Get the value associated with key. More...
 
int StrDblMap_hasKey (StrDblMap *self, const char *key)
 Return 1 if key is present in map; 0 otherwise.
 
int StrDblMap_insert (StrDblMap *self, const char *key, double value)
 Insert a value into the table, resizing if necessary. More...
 
unsigned long StrDblMap_size (StrDblMap *self)
 Return the number of elements.
 
int StrDblMap_keys (StrDblMap *self, unsigned size, char *keys[size])
 Put keys into array "keys". More...
 

Detailed Description

Map char* to double.

Author
Alan R. Rogers

Function Documentation

◆ El_insert()

static El * El_insert ( El self,
const char *  key,
double  value,
int *  status 
)
static

Insert a new key/value pair into the linked list.

Usage:

El *list=NULL;
int status;
list = El_insert(list, key, value, &status);
if(status != 0)
    printf("Error: key is already in list\n");
Parameters
selfcurrent element of list
[in]key,apointer
[in]value,anotherpointer
[out]statuspointer to int, which will be set to 0 on success or 1 if value is already in list.
Returns
pointer to self or to a newly-allocated El.

References El_insert(), El_new(), and El::next.

Referenced by El_insert(), and StrDblMap_insert().

◆ StrDblMap_get()

double StrDblMap_get ( StrDblMap self,
const char *  key,
int *  status 
)

Get the value associated with key.

On success, *status is set equal to 0 and the function returns the value associated with the key. If the key is not found, *status is set equal to 1, and the function returns 0.0.

References El::next, and strhash().

◆ StrDblMap_insert()

int StrDblMap_insert ( StrDblMap self,
const char *  key,
double  value 
)

Insert a value into the table, resizing if necessary.

Returns
0 on success; 1 if pointers is already in table; ENOMEM if the function attempts unsuccessfully to resize the hash table.

References El_insert(), resize(), and strhash().

◆ StrDblMap_keys()

int StrDblMap_keys ( StrDblMap self,
unsigned  size,
char *  keys[size] 
)

Put keys into array "keys".

If the array isn't large enough, return BUFFER_OVERFLOW. Otherwise return 0. Allocates memory for each key, so each key should be freed by the calling function.

References El::next.