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.

cmDList.h 3.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef cmDList_h
  2. #define cmDList_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. enum
  7. {
  8. kOkDlRC = cmOkRC,
  9. kDuplicateIndexIdDlRC,
  10. kInvalidIndexDlRC,
  11. kIterNotFoundDlRC,
  12. kDataRecdNotFoundDlRC,
  13. };
  14. typedef unsigned cmDlRC_t;
  15. typedef cmHandle_t cmDListH_t;
  16. typedef cmHandle_t cmDListIterH_t;
  17. extern cmDListH_t cmDListNullHandle;
  18. extern cmDListIterH_t cmDListIterNullHandle;
  19. // Return < 0 if v0 < v1
  20. // == 0 if v0 == v1
  21. // > 0 if v0 > v1
  22. typedef int (*cmDListCmpFunc_t)( void* arg, const void* v0, unsigned v0N, const void* v1, unsigned v1N );
  23. typedef void (*cmDListIndexFreeFunc_t)( unsigned indexId, void* arg );
  24. // If 'cmpFunc' is not NULL then a default index with an indexId==0 will be automatically created.
  25. cmDlRC_t cmDListAlloc( cmCtx_t* ctx, cmDListH_t* hp, cmDListCmpFunc_t cmpFunc, void* funcArg );
  26. cmDlRC_t cmDListFree( cmDListH_t* hp );
  27. bool cmDListIsValid( cmDListH_t h );
  28. // Set resyncFl to automatically update the indexes to reflect the new record, otherwise
  29. // cmDListIndexUpdateAll() should be called to resynchronize the data list to the indexes.
  30. // If many inserts are to be performed with no intervening accesses to the list then it
  31. // is more efficient to defer updating the indexes until all the inserts are completed.
  32. cmDlRC_t cmDListInsert( cmDListH_t h, const void* recd, unsigned recdByteN, bool resyncFl );
  33. // Delete a data record.
  34. // 'recd' should be set to a value returned via one of the iterator accessors.
  35. // If 'resyncFl' is set then the indexes and interators will be
  36. // automatically synchronized with the data list after the deletion.
  37. // If 'resyncFl' is not set then the client must call cmDListIndexUpdateAll()
  38. // to resynchronize the indexes and iterators after the deletion.
  39. // Note that if multiple records are to be deleted without intervening accesses
  40. // to the list then it is more efficient to defer update the indexes until
  41. // all the deletions are completed.
  42. cmDlRC_t cmDListDelete( cmDListH_t h, const void* recd, bool resyncFl );
  43. // Allocate a new index. 'indexId' is used to identify this index and must be unique among all
  44. // previously allocated indexes.
  45. cmDlRC_t cmDListIndexAlloc( cmDListH_t h, unsigned indexId, cmDListCmpFunc_t cmpFunc, void* funcArg );
  46. cmDlRC_t cmDListIndexFree( cmDListH_t h, unsigned indexId );
  47. // Refresh all the indexes. This function should be called after new records are inserted
  48. // via cmDListInsert(..,false).
  49. cmDlRC_t cmDListIndexUpdateAll( cmDListH_t h );
  50. // Set a function to be called when indexes are released.
  51. cmDlRC_t cmDListIndexSetFreeFunc(cmDListH_t h, unsigned indexId, cmDListIndexFreeFunc_t func );
  52. // Allocate an interator. By default the new iterator is pointing to the first record
  53. // in the index identified by 'indexId'.
  54. cmDlRC_t cmDListIterAlloc( cmDListH_t h, cmDListIterH_t* iHp, unsigned indexId );
  55. cmDlRC_t cmDListIterFree( cmDListIterH_t* iHp );
  56. bool cmDListIterIsValid( cmDListIterH_t iH );
  57. // Set the current iteration location to the begin/end of the index it is attached to.
  58. cmDlRC_t cmDListIterSeekBegin( cmDListIterH_t iH );
  59. cmDlRC_t cmDListIterSeekEnd( cmDListIterH_t iH );
  60. // Return the current record this iterator is pointing to.
  61. const void* cmDListIterGet( cmDListIterH_t iH, unsigned* recdByteNRef );
  62. // Return the current record this iterator is pointint to and advance the iterator.
  63. const void* cmDListIterPrev( cmDListIterH_t iH, unsigned* recdByteNRef );
  64. const void* cmDListIterNext( cmDListIterH_t iH, unsigned* recdByteNRef );
  65. // Make the record which matches 'key' the current iterator.
  66. // The match is made by using the compare function which is assigned to the index
  67. // which this iterator is attached to.
  68. const void* cmDListIterFind( cmDListIterH_t iH, const void* key, unsigned keyN, unsigned* recdByteNRef);
  69. #ifdef __cplusplus
  70. }
  71. #endif
  72. #endif