Return insertion point in g_array_binary_search
If one wants to create a very simple set (for only few items), then one way to do so is to use a sorted GArray
. That allows fast checking if an item exists using g_array_binary_search
. However, if I want to insert new item if it does not exist yet, then I need to first do g_array_binary_search
, then g_array_append_val
and then a g_array_sort
.
My proposal is to define that g_array_binary_search
returns the insertion point if there is no match. Then one could do g_array_binary_search
followed by a g_array_insert_val
and the result is a sorted set of items.