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

Map strings to pointers. More...

#include "strptrmap.h"
#include "misc.h"
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

Data Structures

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

Macros

#define KEYSIZE   20
 
#define PNT_DIM   32u
 PNT_DIM: dimention of hash table must be a power of 2.
 

Functions

ElEl_new (const char *key, void *ptr)
 Construct a new element with given key and pointer.
 
void El_free (El *e)
 Destroy a linked list of El objects.
 
ElEl_insert (El *self, const char *key, void *ptr, int *status)
 Insert a new key/ptr pair into the linked list. More...
 
StrPtrMapStrPtrMap_new (void)
 StrPtrMap constructor.
 
void StrPtrMap_free (StrPtrMap *self)
 StrPtrMap destructor.
 
void * StrPtrMap_get (StrPtrMap *self, const char *key)
 Get the pointer associated with key. More...
 
int StrPtrMap_insert (StrPtrMap *self, const char *key, void *ptr)
 Insert a pointer into the table. More...
 
unsigned long StrPtrMap_size (StrPtrMap *self)
 Return the number of elements in the StrPtrMap.
 
void StrPtrMap_print (StrPtrMap *self)
 Print a StrPtrMap.
 
void StrPtrMap_ptrArray (StrPtrMap *self, long unsigned n, void *v[n])
 Fill array v with pointers. Abort if v is of wrong size.
 

Detailed Description

Map strings to pointers.

Author
Alan R. Rogers

Function Documentation

◆ El_insert()

El * El_insert ( El self,
const char *  key,
void *  ptr,
int *  status 
)

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

Usage:

El *list=NULL;
int status;
list = El_insert(list, key, ptr, &status);
if(status != 0)
    printf("Error: key is already in list\n");
Parameters
selfcurrent element of list
[in]key,acharacter string
[in]ptrpointer
[out]statuspointer to int, which will be set to 0 on success or 1 if ptr 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 StrPtrMap_insert().

◆ StrPtrMap_get()

void * StrPtrMap_get ( StrPtrMap self,
const char *  key 
)

Get the pointer associated with key.

If no such object exists, return NULL.

References El::next, PNT_DIM, and strhash().

Referenced by parseDerive(), and parseMix().

◆ StrPtrMap_insert()

int StrPtrMap_insert ( StrPtrMap self,
const char *  key,
void *  ptr 
)

Insert a pointer into the table.

Returns
0 on success; 1 if pointers is already in table.

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

Referenced by parseSegment().