2010-06-03 21:24:43 +08:00
|
|
|
/*********************************************************************
|
|
|
|
* Copyright 1993, UCAR/Unidata
|
|
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
2012-08-20 05:12:35 +08:00
|
|
|
* $Header$
|
2010-06-03 21:24:43 +08:00
|
|
|
*********************************************************************/
|
|
|
|
#ifndef NCHASHMAP_H
|
|
|
|
#define NCHASHMAP_H 1
|
|
|
|
|
|
|
|
#if defined(_CPLUSPLUS_) || defined(__CPLUSPLUS__)
|
2012-08-20 05:12:35 +08:00
|
|
|
#define externC extern "C"
|
2010-06-03 21:24:43 +08:00
|
|
|
#else
|
2012-08-20 05:12:35 +08:00
|
|
|
#define externC extern
|
2010-06-03 21:24:43 +08:00
|
|
|
#endif
|
|
|
|
|
2012-08-20 05:12:35 +08:00
|
|
|
#include "nclist.h"
|
|
|
|
|
|
|
|
/* Define the type of the elements in the hashmap*/
|
2010-06-03 21:24:43 +08:00
|
|
|
typedef unsigned long nchashid;
|
|
|
|
|
2012-08-20 05:12:35 +08:00
|
|
|
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;
|
|
|
|
|
2012-08-20 05:12:35 +08:00
|
|
|
externC NChashmap* nchashnew(void);
|
|
|
|
externC NChashmap* nchashnew0(int);
|
|
|
|
externC int nchashfree(NChashmap*);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2012-08-20 05:12:35 +08:00
|
|
|
/* Insert a (ncnchashid,void*) pair into the table*/
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Fail if already there*/
|
2012-08-20 05:12:35 +08:00
|
|
|
externC int nchashinsert(NChashmap*, nchashid nchash, void* value);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2012-08-20 05:12:35 +08:00
|
|
|
/* Insert a (nchashid,void*) pair into the table*/
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Overwrite if already there*/
|
2012-08-20 05:12:35 +08:00
|
|
|
externC int nchashreplace(NChashmap*, nchashid nchash, void* value);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* lookup a nchashid and return found/notfound*/
|
2012-08-20 05:12:35 +08:00
|
|
|
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*/
|
2012-08-20 05:12:35 +08:00
|
|
|
externC void* nchashget(NChashmap*, nchashid nchash);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* remove a nchashid*/
|
2012-08-20 05:12:35 +08:00
|
|
|
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*/
|
2014-03-10 05:51:45 +08:00
|
|
|
externC int nchashith(NChashmap*, size_t i, nchashid*, void**);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2012-08-20 05:12:35 +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*/
|
|
|
|
|