Skip to content

ArrayList

I am auto-resizing array-backed list structure. Elements are always 64-bit values with pass by value semantics. ArrayList__new_owned can if the elements are pointers to owned objects.

The push, peek, and pop "methods" offer graceful use as a stack.

ArrayList

pub struct ArrayList

Type of ArrayLists.

Iter

pub struct Iter

Type of ArrayList's iterator.

ArrayList__new

pub fn ArrayList__new(int capacity)

I create a new list with the specified capacity.

ArrayList__new_owned

pub fn ArrayList__new_owned(int capacity, void* drop_el)

I create a new list with the specified capacity, and function pointer for dropping elements.

ArrayList_drop

pub fn ArrayList_drop(ArrayList* self)

I drop the list, along with its elements (if they are owned).

ArrayList_get

pub fn ArrayList_get(ArrayList* self, int i)

I return the ith element in the list. If i < 0 or i >= size, panic.

ArrayList_into_array

pub fn ArrayList_into_array(ArrayList* self)

I consume the list and return a null-terminated array of its elements. The array may have unfreed capacity beyond the terminating null. There's no way to differentiate the terminating null from a null element in the list. If that matters, try ArrayList_iter.

ArrayList_iter

pub fn ArrayList_iter(ArrayList* self)

I create a new Iter over this list. Its behavior is undefined if the list is modified during iteration.

ArrayList_peek

pub fn ArrayList_peek(ArrayList* self)

I return the last element on the stack (in the list), without removing it, panicking if the stack is empty.

ArrayList_pop

pub fn ArrayList_pop(ArrayList* self)

I remove and return the last element on the stack (in the list), panicking if the stack is empty.

ArrayList_push

pub fn ArrayList_push(ArrayList* self, void el)

I add the passed element to the end of the list, extending it if needed.

ArrayList_push_all

pub fn ArrayList_push_all(ArrayList* self, void* els)

I add every element in the null-terminated els array to the end of the list, extending it if needed.

ArrayList_reserve

pub fn ArrayList_reserve(ArrayList* self, int min_capacity)

I reserve the given minimum capacity in the list, guaranteeing that no allocations will be required to if elements are added up to this size. Note that removing elements may reduce the list's capacity, reserved or not.

ArrayList_set

pub fn ArrayList_set(ArrayList* self, int i, void el)

I set the ith element in the list, returning the prior value there. If i < 0 or i >= size, panic.

ArrayList_size

pub fn ArrayList_size(ArrayList* self)

I return the number of elements current in the list.

ArrayList_sort

pub fn ArrayList_sort(ArrayList* self, void* cmp)

I sort the list, in place, using the passed comparator function to define total order over the elements.

ArrayList_to_string

pub fn ArrayList_to_string(ArrayList* self, void* el_to_string)

I render the list to a null-terminated byte string, using the passed function to convert each element in turn. If null is passed, the elements are assumed to be NTBSs, to be included in the final string directly. The returned string must be free-ed by the client. The list is not consumed.

Iter_drop

pub fn Iter_drop(Iter* self)

I drop the iterator.

Iter_next

pub fn Iter_next(Iter* self)

I return a pointer to the next element, or null if exhausted.