Blender V4.3
array_utils.c File Reference

Generic array manipulation API. More...

#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_alloca.h"
#include "BLI_math_base.h"
#include "BLI_sys_types.h"
#include "BLI_utildefines.h"
#include "BLI_array_utils.h"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Functions

void _bli_array_reverse (void *arr_v, uint arr_len, size_t arr_stride)
 
void _bli_array_wrap (void *arr_v, uint arr_len, size_t arr_stride, int dir)
 
void _bli_array_permute (void *arr, const uint arr_len, const size_t arr_stride, const uint *order, void *arr_temp)
 
uint _bli_array_deduplicate_ordered (void *arr, uint arr_len, size_t arr_stride)
 
int _bli_array_findindex (const void *arr, uint arr_len, size_t arr_stride, const void *p)
 
int _bli_array_rfindindex (const void *arr, uint arr_len, size_t arr_stride, const void *p)
 
void _bli_array_binary_and (void *arr, const void *arr_a, const void *arr_b, uint arr_len, size_t arr_stride)
 
void _bli_array_binary_or (void *arr, const void *arr_a, const void *arr_b, uint arr_len, size_t arr_stride)
 
bool _bli_array_iter_span (const void *arr, uint arr_len, size_t arr_stride, bool use_wrap, bool use_delimit_bounds, bool(*test_fn)(const void *arr_item, void *user_data), void *user_data, uint span_step[2], uint *r_span_len)
 
bool _bli_array_is_zeroed (const void *arr_v, uint arr_len, size_t arr_stride)
 
bool _bli_array_iter_spiral_square (const void *arr_v, const int arr_shape[2], size_t elem_size, const int center[2], bool(*test_fn)(const void *arr_item, void *user_data), void *user_data)
 

Detailed Description

Generic array manipulation API.

Warning
Some array operations here are inherently inefficient, and only included for the cases where the performance is acceptable. Use with care.

Definition in file array_utils.c.

Function Documentation

◆ _bli_array_binary_and()

void _bli_array_binary_and ( void * arr,
const void * arr_a,
const void * arr_b,
uint arr_len,
size_t arr_stride )

Definition at line 139 of file array_utils.c.

◆ _bli_array_binary_or()

void _bli_array_binary_or ( void * arr,
const void * arr_a,
const void * arr_b,
uint arr_len,
size_t arr_stride )

Definition at line 152 of file array_utils.c.

◆ _bli_array_deduplicate_ordered()

uint _bli_array_deduplicate_ordered ( void * arr,
uint arr_len,
size_t arr_stride )

In-place array de-duplication of an ordered array.

Returns
The new length of the array.

Access via BLI_array_deduplicate_ordered

Definition at line 93 of file array_utils.c.

References POINTER_OFFSET, and UNLIKELY.

◆ _bli_array_findindex()

int _bli_array_findindex ( const void * arr,
uint arr_len,
size_t arr_stride,
const void * p )

Find the first index of an item in an array.

Access via BLI_array_findindex

Note
Not efficient, use for error checks/asserts.

Definition at line 116 of file array_utils.c.

◆ _bli_array_is_zeroed()

bool _bli_array_is_zeroed ( const void * arr_v,
uint arr_len,
size_t arr_stride )

Simple utility to check memory is zeroed.

Definition at line 275 of file array_utils.c.

◆ _bli_array_iter_span()

bool _bli_array_iter_span ( const void * arr,
uint arr_len,
size_t arr_stride,
bool use_wrap,
bool use_delimit_bounds,
bool(* test_fn )(const void *arr_item, void *user_data),
void * user_data,
uint span_step[2],
uint * r_span_len )

Utility function to iterate over contiguous items in an array.

Parameters
use_wrapDetect contiguous ranges across the first/last points. In this case the second index of span_step may be lower than the first, which indicates the values are wrapped.
use_delimit_boundsWhen false, ranges that defined by the start/end indices are excluded. This option has no effect when use_wrap is enabled.
test_fnFunction to test if the item should be included in the range.
user_dataUser data for test_fn.
span_stepIndices to iterate over, initialize both values to the array length to initialize iteration.
r_span_lenThe length of the span, useful when use_wrap is enabled, where calculating the length isn't a simple subtraction.

Definition at line 165 of file array_utils.c.

References BLI_assert, NULL, POINTER_OFFSET, and UNLIKELY.

◆ _bli_array_iter_spiral_square()

bool _bli_array_iter_spiral_square ( const void * arr_v,
const int arr_shape[2],
size_t elem_size,
const int center[2],
bool(* test_fn )(const void *arr_item, void *user_data),
void * user_data )

Smart function to sample a rectangle spiraling outside. Nice for selection ID.

Parameters
arr_shapedimensions [w, h].
centercoordinates [x, y] indicating where to start traversing.

Definition at line 287 of file array_utils.c.

References BLI_assert, CLAMP, int, max_iiii(), min_iiii(), and steps.

◆ _bli_array_permute()

void _bli_array_permute ( void * arr,
uint arr_len,
size_t arr_stride,
const uint * order,
void * arr_temp )

In-place array permute. (re-arrange elements based on an array of indices).

Access via BLI_array_wrap

Definition at line 64 of file array_utils.c.

References BLI_assert, len, MEM_freeN(), MEM_mallocN, NULL, and POINTER_OFFSET.

◆ _bli_array_reverse()

void _bli_array_reverse ( void * arr_v,
uint arr_len,
size_t arr_stride )

In-place array reverse.

Access via BLI_array_reverse

Definition at line 27 of file array_utils.c.

References BLI_array_alloca.

◆ _bli_array_rfindindex()

int _bli_array_rfindindex ( const void * arr,
uint arr_len,
size_t arr_stride,
const void * p )

A version of BLI_array_findindex that searches from the end of the list.

Definition at line 127 of file array_utils.c.

◆ _bli_array_wrap()

void _bli_array_wrap ( void * arr_v,
uint arr_len,
size_t arr_stride,
int dir )

In-place array wrap. (rotate the array one step forward or backwards).

Access via BLI_array_wrap

Definition at line 44 of file array_utils.c.

References BLI_array_alloca, and BLI_assert_unreachable.

Referenced by testbuffer_list_state_random_data().