Skip to content

Pool natives

IS4 edited this page Oct 5, 2021 · 4 revisions

Construction and destruction

pool_new

native Pool:pool_new(capacity=-1, bool:ordered=false);

Creates a new pool, optionally with an initial capacity.

pool_delete

native pool_delete(Pool:pool);

Deletes a pool and frees its memory. Required after you're done with the object.

pool_delete_deep

native pool_delete_deep(Pool:pool);

Deletes a pool and frees its memory together with all resources it may contain.

pool_valid

native bool:pool_valid(Pool:pool);

Returns true if the pool pointer is valid.

pool_clear

native pool_clear(Pool:pool);

Removes all elements in the pool.

pool_clear_deep

native pool_clear_deep(Pool:pool);

Removes all elements in the pool and frees all memory owned by them.

pool_clone

native Pool:pool_clone(Pool:pool);

Clones a pool and all the data it contains (deep copy).

pool_set_ordered

native pool_set_ordered(Pool:pool, bool:ordered);

Changes the internal structure of the pool. An ordered pool uses a tree to mark unused ranges of slots, whereas an unordered map uses a linked list.

pool_is_ordered

native bool:pool_is_ordered(Pool:pool);

Returns true if the pool is ordered, or false if the pool is unordered.

Properties

pool_size

native pool_size(Pool:pool);

Returns the number of elements in the pool.

pool_capacity

native pool_capacity(Pool:pool);

Returns the capacity of the pool, i.e. the number of elements that can be added without enlarging the internal buffer and invalidating iterators.

pool_add

native pool_add(Pool:pool, AnyTag:value, TagTag:tag_id=tagof(value));
native pool_add_arr(Pool:pool, const AnyTag:value[], size=sizeof(value), TagTag:tag_id=tagof(value));
native pool_add_str(Pool:pool, const value[]);
native pool_add_str_s(Pool:pool, ConstStringTag:value);
native pool_add_var(Pool:pool, ConstVariantTag:value);

Adds a new elements to a pool, constructed either from a single value, an array, a string, or a variant. Returns the index of the element.

pool_remove

native bool:pool_remove(Pool:pool, index);

Removes an element from the pool at a specific index. A gap will be created at the index. Returns true if the element was removed, or false if there was no element at that index.

pool_remove_deep

native bool:pool_remove_deep(Pool:pool, index);

Removes an element from the pool at a specific index, and frees all resources held by the element. A gap will be created at the index. Returns true if the element was removed, or false if there was no element at that index.

pool_has

native bool:pool_has(Pool:pool, index);

Returns true if the pool contains an element at the specific index, false otherwise.

pool_get

native pool_get(Pool:pool, index, offset=0);
native pool_get_arr(Pool:pool, index, AnyTag:value[], size=sizeof(value));
native pool_get_str(Pool:pool, index, value[], size=sizeof(value)) = pool_get_arr;
native String:pool_get_str_s(Pool:pool, index);
native Variant:pool_get_var(Pool:pool, index);
native bool:pool_get_safe(Pool:pool, index, &AnyTag:value, offset=0, TagTag:tag_id=tagof(value));
native pool_get_arr_safe(Pool:pool, index, AnyTag:value[], size=sizeof(value), TagTag:tag_id=tagof(value));
native pool_get_str_safe(Pool:pool, index, value[], size=sizeof(value));
native String:pool_get_str_safe_s(Pool:pool, index);

Returns the value of an element in a pool at a specific index. The safe versions check the tag of the output. Other semantics same as for variants.

pool_set

native pool_set(Pool:pool, index, AnyTag:value, TagTag:tag_id=tagof(value));
native pool_set_arr(Pool:pool, index, const AnyTag:value[], size=sizeof(value), TagTag:tag_id=tagof(value));
native pool_set_str(Pool:pool, index, const value[]);
native pool_set_str_s(Pool:pool, index, ConstStringTag:value);
native pool_set_var(Pool:pool, index, ConstVariantTag:value);

Replaces a value at a specific position in a pool with a new one. If there is no value at the specific index, the new value is inserted there.

pool_set_cell

native pool_set_cell(Pool:pool, index, offset, AnyTag:value);
native bool:pool_set_cell_safe(Pool:pool, index, offset, AnyTag:value, TagTag:tag_id=tagof(value));

Sets the value of a single cell in an array stored in the pool. The safe version checks if the tags are compatible.

pool_resize

native pool_resize(Pool:pool, newsize);

Changes the capacity of the pool to newsize. Elements at indices starting from newsize will be removed from the pool.

pool_reserve

native pool_reserve(Pool:pool, capacity);

Increases the capacity of the pool.

pool_find

native pool_find(Pool:pool, AnyTag:value, TagTag:tag_id=tagof(value));
native pool_find_arr(Pool:pool, const AnyTag:value[], size=sizeof(value), TagTag:tag_id=tagof(value));
native pool_find_str(Pool:pool, const value[]);
native pool_find_str_s(Pool:pool, ConstStringTag:value);
native pool_find_var(Pool:pool, ConstVariantTag:value);

Finds the first element equal to value in the pool and returns its index. Returns -1 if the element was not found.

pool_find_if

native pool_find_if(Pool:pool, Expression:pred);

Finds the first element that satisfies pred, and returns its index, or -1 if no such element is present in the pool.

pool_count

native pool_count(Pool:pool, AnyTag:value, TagTag:tag_id=tagof(value));
native pool_count_arr(Pool:pool, const AnyTag:value[], size=sizeof(value), TagTag:tag_id=tagof(value));
native pool_count_str(Pool:pool, const value[]);
native pool_count_str_s(Pool:pool, ConstStringTag:value);
native pool_count_var(Pool:pool, ConstVariantTag:value);

Counts the number of occurences of a specific element.

pool_count_if

native pool_count_if(Pool:pool, Expression:pred);

Counts the number of elements in the pool that satisfy pred.

pool_tagof

native pool_tagof(Pool:pool, index);

Returns the tag of an element in the pool.

pool_sizeof

native pool_sizeof(Pool:pool, index);

Returns the size of an element in the pool.

pool_iter

native Iter:pool_iter(Pool:pool, index=0);

Creates a new iterator pointing to an element in the pool.

pool_iter_at

native Iter:pool_iter_at(Pool:pool, index);

Creates a new iterator pointing to a specific element in the pool.

Clone this wiki locally