libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmHashTbl.h 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //| Copyright: (C) 2009-2020 Kevin Larke <contact AT larke DOT org>
  2. //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
  3. #ifndef cmHashTbl_h
  4. #define cmHashTbl_h
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. //( { file_desc:"Hash table for storing arbitary data blobs." kw:[container]}
  9. enum
  10. {
  11. kOkHtRC,
  12. kLHeapFailHtRC,
  13. kHashFaultHtRC,
  14. kInvalidIdHtRC
  15. };
  16. typedef cmRC_t cmHtRC_t;
  17. typedef cmHandle_t cmHashTblH_t;
  18. extern cmHashTblH_t cmHashTblNullHandle;
  19. cmHtRC_t cmHashTblCreate( cmCtx_t* ctx, cmHashTblH_t* hp, unsigned bucketCnt );
  20. cmHtRC_t cmHashTblDestroy( cmHashTblH_t* hp );
  21. bool cmHashTblIsValid( cmHashTblH_t h );
  22. // cmhashTblStoreBase() is the canonical store function.
  23. // Set 'staticFl' to true if the value does not need to be reallocated
  24. // and copied into the internal storage space.
  25. // Returns a value which uniquely identifies the value. If a unique
  26. // identifier cannot be generated then the function returns cmInvalidId
  27. // and sets the hash table error code to kHashFaultRC.
  28. unsigned cmHashTblStoreBase( cmHashTblH_t h, void* v, unsigned byteCnt, bool staticFl );
  29. unsigned cmHashTblStore( cmHashTblH_t h, void* v, unsigned byteCnt );
  30. unsigned cmHashTblStoreStatic( cmHashTblH_t h, void* v, unsigned byteCnt );
  31. unsigned cmHashTblStoreStr( cmHashTblH_t h, const cmChar_t* s );
  32. unsigned cmhashTblStoreStaticStr( cmHashTblH_t h, const cmChar_t* s );
  33. unsigned cmHashTblStoreV( cmHashTblH_t h, const cmChar_t* fmt, va_list vl );
  34. unsigned cmHashTblStoreF( cmHashTblH_t h, const cmChar_t* fmt, ... );
  35. // Given a value find an id.
  36. unsigned cmHashTblId( cmHashTblH_t h, const void* value, unsigned byteCnt );
  37. unsigned cmHashTblStrToId( cmHashTblH_t h, const cmChar_t* str );
  38. // Returns NULL if no value is associated with 'id'.
  39. // 'byteCntRef' is optional.
  40. const void* cmHashTblValue( cmHashTblH_t h, unsigned id, unsigned* byteCntRef );
  41. // Wrapper around cmHashTblValue() which assumes that the stored value is a
  42. // zero terminated string.
  43. const cmChar_t* cmHashTblStr( cmHashTblH_t h, unsigned id );
  44. // Remove a value.
  45. cmHtRC_t cmHashTblRemove( cmHashTblH_t h, unsigned id );
  46. // Return the last error id generated by the cmHashTbl object.
  47. cmHtRC_t cmHashTblLastRC( cmHashTblH_t h );
  48. void cmHashTblReport( cmHashTblH_t h, cmRpt_t* rpt );
  49. cmHtRC_t cmHashTblTest( cmCtx_t* ctx );
  50. //)
  51. #ifdef __cplusplus
  52. }
  53. #endif
  54. #endif