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 4.2KB

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