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

Associate character strings with integers. More...

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

Data Structures

struct  SILink
 A single element of a linked list. More...
 
struct  StrInt
 Hash table. More...
 

Macros

#define STRINT_DIM   64u
 STRINT_DIM must be a power of 2.
 
#define MAXKEY   200
 

Functions

SILinkSILink_new (const char *key, int value, SILink *next)
 SILink constructor.
 
void SILink_free (SILink *self)
 Free linked list of SILink objects.
 
SILinkSILink_insert (SILink *self, const char *key, int value)
 Insert a new key-value pair. Set errno=EDOM if key already exists.
 
int SILink_get (SILink *self, const char *key)
 Get index corresponding to key. More...
 
int SILink_exists (SILink *self, const char *key)
 Return 1 if key is present in list, 0 otherwise.
 
void SILink_print (const SILink *self, FILE *fp)
 Print linked list of SILink objects.
 
unsigned SILink_size (SILink *self)
 Return number of links in list.
 
StrIntStrInt_new (void)
 StrInt constructor.
 
void StrInt_free (StrInt *self)
 StrInt destructor.
 
void StrInt_insert (StrInt *self, const char *key, int value)
 Insert a key-value pair into the hash table. More...
 
int StrInt_get (StrInt *self, const char *key)
 Return value corresponding to key. More...
 
int StrInt_exists (StrInt *self, const char *key)
 Return 1 if key exists in hash map; 0 otherwise.
 
void StrInt_print (const StrInt *self, FILE *fp)
 Print a StrInt object.
 
unsigned StrInt_size (const StrInt *self)
 Number of items stored in hash table.
 

Detailed Description

Associate character strings with integers.

Author
Alan R. Rogers

Function Documentation

◆ SILink_get()

int SILink_get ( SILink self,
const char *  key 
)

Get index corresponding to key.

If key is not in table, return -1 and set errno = EDOM.

References SILink_get().

Referenced by SILink_get(), and StrInt_get().

◆ StrInt_get()

int StrInt_get ( StrInt self,
const char *  key 
)

Return value corresponding to key.

If key is not in table, return -1 and set errno = EDOM.

References SILink_get(), strhash(), and STRINT_DIM.

◆ StrInt_insert()

void StrInt_insert ( StrInt self,
const char *  key,
int  value 
)

Insert a key-value pair into the hash table.

Set errno=EDOM if pair already exists.

References SILink_insert(), strhash(), and STRINT_DIM.