jcs
/subtext
/amendments
/84
bile: Add bile_sorted_ids_by_type
jcs made amendment 84 over 2 years ago
--- bile.c Tue Mar 1 13:59:51 2022
+++ bile.c Thu Mar 3 16:13:09 2022
@@ -285,6 +285,37 @@ bile_count_by_type(struct bile *bile, const OSType typ
return count;
}
+size_t
+bile_sorted_ids_by_type(struct bile *bile, const OSType type, size_t **ret)
+{
+ struct bile_object *o;
+ size_t count = 0, size = 0, n, j, t;
+ size_t *ids;
+
+ for (n = 0; n < bile->nobjects; n++) {
+ o = &bile->map[n - 1];
+ if (o->type != type)
+ continue;
+
+ EXPAND_TO_FIT(ids, size, count * sizeof(size_t), sizeof(size_t),
+ 10 * sizeof(size_t));
+ ids[count++] = o->id;
+ }
+
+ for (n = 0; n < count; n++) {
+ for (j = 0; j < count - n - 1; j++) {
+ if (ids[j] > ids[j + 1]) {
+ t = ids[j];
+ ids[j] = ids[j + 1];
+ ids[j + 1] = t;
+ }
+ }
+ }
+
+ *ret = ids;
+ return count;
+}
+
struct bile_object *
bile_get_nth_of_type(struct bile *bile, const size_t index,
const OSType type)
@@ -332,7 +363,6 @@ bile_next_id(struct bile *bile, const OSType type)
return id;
}
-
short
bile_delete(struct bile *bile, const OSType type, const unsigned long id)
--- bile.h Sat Jan 29 13:13:31 2022
+++ bile.h Thu Mar 3 15:34:04 2022
@@ -105,6 +105,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_sorted_ids_by_type(struct bile *bile,
+ const OSType type, size_t **ret);
struct bile_object * bile_get_nth_of_type(struct bile *bile,
const size_t index, const OSType type);
size_t bile_next_id(struct bile *bile, const OSType type);