nchashmap.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include "nclist.h"
  9. /* Define the type of the elements in the hashmap*/
  10. #if defined(_CPLUSPLUS_) || defined(__CPLUSPLUS__)
  11. #define EXTERNC extern "C"
  12. #else
  13. #define EXTERNC extern
  14. #endif
  15. typedef unsigned long nchashid;
  16. EXTERNC int nchashnull(ncelem);
  17. typedef struct NChashmap {
  18. int alloc;
  19. int size; /* # of pairs still in table*/
  20. NClist** table;
  21. } NChashmap;
  22. EXTERNC NChashmap* nchashnew(void);
  23. EXTERNC NChashmap* nchashnew0(int);
  24. EXTERNC int nchashfree(NChashmap*);
  25. /* Insert a (ncnchashid,ncelem) pair into the table*/
  26. /* Fail if already there*/
  27. EXTERNC int nchashinsert(NChashmap*, nchashid nchash, ncelem value);
  28. /* Insert a (nchashid,ncelem) pair into the table*/
  29. /* Overwrite if already there*/
  30. EXTERNC int nchashreplace(NChashmap*, nchashid nchash, ncelem value);
  31. /* lookup a nchashid and return found/notfound*/
  32. EXTERNC int nchashlookup(NChashmap*, nchashid nchash, ncelem* valuep);
  33. /* lookup a nchashid and return 0 or the value*/
  34. EXTERNC ncelem nchashget(NChashmap*, nchashid nchash);
  35. /* remove a nchashid*/
  36. EXTERNC int nchashremove(NChashmap*, nchashid nchash);
  37. /* Return the ith pair; order is completely arbitrary*/
  38. /* Can be expensive*/
  39. EXTERNC int nchashith(NChashmap*, int i, nchashid*, ncelem*);
  40. EXTERNC int nchashkeys(NChashmap* hm, nchashid** keylist);
  41. /* return the # of pairs in table*/
  42. #define nchashsize(hm) ((hm)?(hm)->size:0)
  43. #endif /*NCHASHMAP_H*/