netcdf-c/include/nchashmap.h

60 lines
1.7 KiB
C
Raw Normal View History

2010-06-03 21:24:43 +08:00
/*********************************************************************
* Copyright 1993, UCAR/Unidata
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
* $Header$
2010-06-03 21:24:43 +08:00
*********************************************************************/
#ifndef NCHASHMAP_H
#define NCHASHMAP_H 1
#if defined(_CPLUSPLUS_) || defined(__CPLUSPLUS__)
#define externC extern "C"
2010-06-03 21:24:43 +08:00
#else
#define externC extern
2010-06-03 21:24:43 +08:00
#endif
#include "nclist.h"
/* Define the type of the elements in the hashmap*/
2010-06-03 21:24:43 +08:00
typedef unsigned long nchashid;
externC int nchashnull(void*);
2010-06-03 21:24:43 +08:00
typedef struct NChashmap {
int alloc;
int size; /* # of pairs still in table*/
NClist** table;
} NChashmap;
externC NChashmap* nchashnew(void);
externC NChashmap* nchashnew0(int);
externC int nchashfree(NChashmap*);
2010-06-03 21:24:43 +08:00
/* Insert a (ncnchashid,void*) pair into the table*/
2010-06-03 21:24:43 +08:00
/* Fail if already there*/
externC int nchashinsert(NChashmap*, nchashid nchash, void* value);
2010-06-03 21:24:43 +08:00
/* Insert a (nchashid,void*) pair into the table*/
2010-06-03 21:24:43 +08:00
/* Overwrite if already there*/
externC int nchashreplace(NChashmap*, nchashid nchash, void* value);
2010-06-03 21:24:43 +08:00
/* lookup a nchashid and return found/notfound*/
externC int nchashlookup(NChashmap*, nchashid nchash, void** valuep);
2010-06-03 21:24:43 +08:00
/* lookup a nchashid and return 0 or the value*/
externC void* nchashget(NChashmap*, nchashid nchash);
2010-06-03 21:24:43 +08:00
/* remove a nchashid*/
externC int nchashremove(NChashmap*, nchashid nchash);
2010-06-03 21:24:43 +08:00
/* Return the ith pair; order is completely arbitrary*/
/* Can be expensive*/
externC int nchashith(NChashmap*, size_t i, nchashid*, void**);
2010-06-03 21:24:43 +08:00
externC int nchashkeys(NChashmap* hm, nchashid** keylist);
2010-06-03 21:24:43 +08:00
/* return the # of pairs in table*/
#define nchashsize(hm) ((hm)?(hm)->size:0)
#endif /*NCHASHMAP_H*/