[409] | 1 | /********************************************************************* |
---|
| 2 | * Copyright 1993, UCAR/Unidata |
---|
| 3 | * See netcdf/COPYRIGHT file for copying and redistribution conditions. |
---|
| 4 | * $Header: /upc/share/CVS/netcdf-3/libncdap3/nchashmap.h,v 1.4 2009/09/23 22:26:08 dmh Exp $ |
---|
| 5 | *********************************************************************/ |
---|
| 6 | #ifndef NCHASHMAP_H |
---|
| 7 | #define NCHASHMAP_H 1 |
---|
| 8 | |
---|
| 9 | #include "nclist.h" |
---|
| 10 | |
---|
| 11 | /* Define the type of the elements in the hashmap*/ |
---|
| 12 | |
---|
| 13 | #if defined(_CPLUSPLUS_) || defined(__CPLUSPLUS__) |
---|
| 14 | #define EXTERNC extern "C" |
---|
| 15 | #else |
---|
| 16 | #define EXTERNC extern |
---|
| 17 | #endif |
---|
| 18 | |
---|
| 19 | typedef unsigned long nchashid; |
---|
| 20 | |
---|
| 21 | EXTERNC int nchashnull(ncelem); |
---|
| 22 | |
---|
| 23 | typedef struct NChashmap { |
---|
| 24 | int alloc; |
---|
| 25 | int size; /* # of pairs still in table*/ |
---|
| 26 | NClist** table; |
---|
| 27 | } NChashmap; |
---|
| 28 | |
---|
| 29 | EXTERNC NChashmap* nchashnew(void); |
---|
| 30 | EXTERNC NChashmap* nchashnew0(int); |
---|
| 31 | EXTERNC int nchashfree(NChashmap*); |
---|
| 32 | |
---|
| 33 | /* Insert a (ncnchashid,ncelem) pair into the table*/ |
---|
| 34 | /* Fail if already there*/ |
---|
| 35 | EXTERNC int nchashinsert(NChashmap*, nchashid nchash, ncelem value); |
---|
| 36 | |
---|
| 37 | /* Insert a (nchashid,ncelem) pair into the table*/ |
---|
| 38 | /* Overwrite if already there*/ |
---|
| 39 | EXTERNC int nchashreplace(NChashmap*, nchashid nchash, ncelem value); |
---|
| 40 | |
---|
| 41 | /* lookup a nchashid and return found/notfound*/ |
---|
| 42 | EXTERNC int nchashlookup(NChashmap*, nchashid nchash, ncelem* valuep); |
---|
| 43 | |
---|
| 44 | /* lookup a nchashid and return 0 or the value*/ |
---|
| 45 | EXTERNC ncelem nchashget(NChashmap*, nchashid nchash); |
---|
| 46 | |
---|
| 47 | /* remove a nchashid*/ |
---|
| 48 | EXTERNC int nchashremove(NChashmap*, nchashid nchash); |
---|
| 49 | |
---|
| 50 | /* Return the ith pair; order is completely arbitrary*/ |
---|
| 51 | /* Can be expensive*/ |
---|
| 52 | EXTERNC int nchashith(NChashmap*, int i, nchashid*, ncelem*); |
---|
| 53 | |
---|
| 54 | EXTERNC int nchashkeys(NChashmap* hm, nchashid** keylist); |
---|
| 55 | |
---|
| 56 | /* return the # of pairs in table*/ |
---|
| 57 | #define nchashsize(hm) ((hm)?(hm)->size:0) |
---|
| 58 | |
---|
| 59 | #endif /*NCHASHMAP_H*/ |
---|
| 60 | |
---|