Stores item in the first free slot and returns its Bucket_Locator and a pointer to the stored copy.
A new bucket is allocated when all are full; its memory is zeroed and nothing else is moved. The pointer stays valid until the element is removed or the array reset.
array: Bucket_Array(int, 2);
a, pa := bucket_array_add(*array, 10);
b, pb := bucket_array_add(*array, 20);
c, pc := bucket_array_add(*array, 30); // starts a second bucket
assert(array.count == 3 && c.bucket_index == 1);
pa.* += 1; // pointers stay valid as the array grows
assert(bucket_array_find(*array, a) == 11);
bucket_array_reset(*array);bucket_array_add :: (
array: *Bucket_Array,
item: array.type
) -> (Bucket_Locator, pointer: *array.type)
Puts item in a free slot and returns where it went and a pointer to it. The pointer stays valid as the array grows; use the locator to find or remove the item later.
Parameters
- array: *Bucket_Array
- item: array.type
- copied into a free slot.
Returns
- pointer: *array.type