AmendHub

Download:

jcs

/

subtext

/

amendments

/

327

bile: Add bile_ids_by_type, make bile_sorted_ids_by_type use it

Sometimes there's no point in sorting the results

jcs made amendment 327 about 1 year ago
--- bile.c Thu Feb 23 22:48:26 2023 +++ bile.c Mon Feb 27 16:21:48 2023 @@ -304,11 +304,10 @@ bile_count_by_type(struct bile *bile, const OSType typ } size_t -bile_sorted_ids_by_type(struct bile *bile, const OSType type, - unsigned long **ret) +bile_ids_by_type(struct bile *bile, const OSType type, unsigned long **ret) { struct bile_object *o; - size_t count, size = 0, n, j, t; + size_t count, size = 0, n; unsigned long *ids = NULL; count = 0; @@ -325,7 +324,20 @@ bile_sorted_ids_by_type(struct bile *bile, const OSTyp 10 * sizeof(size_t)); ids[count++] = o->id; } + + *ret = ids; + return count; +} + +size_t +bile_sorted_ids_by_type(struct bile *bile, const OSType type, + unsigned long **ret) +{ + size_t count, n, j, t; + unsigned long *ids = NULL; + count = bile_ids_by_type(bile, type, &ids); + for (n = 0; n < count; n++) { for (j = 0; j < count - n - 1; j++) { if (ids[j] > ids[j + 1]) { --- bile.h Thu Feb 23 21:42:35 2023 +++ bile.h Mon Feb 27 16:22:03 2023 @@ -118,6 +118,8 @@ struct bile_object * bile_find(struct bile *bile, cons const unsigned long id); size_t bile_count_by_type(struct bile *bile, const OSType type); +size_t bile_ids_by_type(struct bile *bile, + const OSType type, unsigned long **ret); size_t bile_sorted_ids_by_type(struct bile *bile, const OSType type, unsigned long **ret); struct bile_object * bile_get_nth_of_type(struct bile *bile,