Blender  V3.3
Classes | Macros | Functions
stack.c File Reference
#include <stdlib.h>
#include <string.h>
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"
#include "BLI_stack.h"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Classes

struct  StackChunk
 
struct  BLI_Stack
 

Macros

#define USE_TOTELEM
 
#define CHUNK_EMPTY   ((size_t)-1)
 
#define CHUNK_SIZE_DEFAULT   (1 << 16)
 
#define CHUNK_ELEM_MIN   32
 

Functions

static voidstack_get_last_elem (BLI_Stack *stack)
 
static size_t stack_chunk_elem_max_calc (const size_t elem_size, size_t chunk_size)
 
BLI_StackBLI_stack_new_ex (const size_t elem_size, const char *description, const size_t chunk_size)
 
BLI_StackBLI_stack_new (const size_t elem_size, const char *description)
 
static void stack_free_chunks (struct StackChunk *data)
 
void BLI_stack_free (BLI_Stack *stack)
 
voidBLI_stack_push_r (BLI_Stack *stack)
 
void BLI_stack_push (BLI_Stack *stack, const void *src)
 
void BLI_stack_pop (BLI_Stack *stack, void *dst)
 
void BLI_stack_pop_n (BLI_Stack *stack, void *dst, unsigned int n)
 
void BLI_stack_pop_n_reverse (BLI_Stack *stack, void *dst, unsigned int n)
 
voidBLI_stack_peek (BLI_Stack *stack)
 
void BLI_stack_discard (BLI_Stack *stack)
 
void BLI_stack_clear (BLI_Stack *stack)
 
size_t BLI_stack_count (const BLI_Stack *stack)
 
bool BLI_stack_is_empty (const BLI_Stack *stack)
 

Macro Definition Documentation

◆ CHUNK_ELEM_MIN

#define CHUNK_ELEM_MIN   32

Definition at line 23 of file stack.c.

◆ CHUNK_EMPTY

#define CHUNK_EMPTY   ((size_t)-1)

Definition at line 19 of file stack.c.

◆ CHUNK_SIZE_DEFAULT

#define CHUNK_SIZE_DEFAULT   (1 << 16)

Definition at line 21 of file stack.c.

◆ USE_TOTELEM

#define USE_TOTELEM

Definition at line 17 of file stack.c.

Function Documentation

◆ BLI_stack_clear()

void BLI_stack_clear ( BLI_Stack stack)

Discards all elements without freeing.

Definition at line 193 of file stack.c.

References BLI_Stack::chunk_curr, BLI_Stack::chunk_elem_max, BLI_Stack::chunk_free, BLI_Stack::chunk_index, BLI_Stack::elem_num, StackChunk::next, NULL, and UNLIKELY.

Referenced by BKE_lnor_space_define(), and TEST().

◆ BLI_stack_count()

size_t BLI_stack_count ( const BLI_Stack stack)

◆ BLI_stack_discard()

void BLI_stack_discard ( BLI_Stack stack)

◆ BLI_stack_free()

void BLI_stack_free ( BLI_Stack stack)

◆ BLI_stack_is_empty()

bool BLI_stack_is_empty ( const BLI_Stack stack)

◆ BLI_stack_new()

BLI_Stack* BLI_stack_new ( size_t  elem_size,
const char *  description 
)

Create a new homogeneous stack with elements of 'elem_size' bytes.

Definition at line 80 of file stack.c.

References BLI_stack_new_ex(), and CHUNK_SIZE_DEFAULT.

◆ BLI_stack_new_ex()

BLI_Stack* BLI_stack_new_ex ( const size_t  elem_size,
const char *  description,
const size_t  chunk_size 
)

◆ BLI_stack_peek()

void* BLI_stack_peek ( BLI_Stack stack)

◆ BLI_stack_pop()

void BLI_stack_pop ( BLI_Stack stack,
void dst 
)

◆ BLI_stack_pop_n()

void BLI_stack_pop_n ( BLI_Stack stack,
void dst,
unsigned int  n 
)

A version of BLI_stack_pop which fills in an array.

Parameters
dstThe destination array, must be at least (BLI_Stack.elem_size * n) bytes long.
nThe number of items to pop.
Note
The first item in the array will be last item added to the stack.

Definition at line 144 of file stack.c.

References BLI_assert, BLI_stack_count(), BLI_stack_pop(), and BLI_Stack::elem_size.

Referenced by BLI_bvhtree_intersect_plane(), BLI_bvhtree_overlap_ex(), and TEST().

◆ BLI_stack_pop_n_reverse()

void BLI_stack_pop_n_reverse ( BLI_Stack stack,
void dst,
unsigned int  n 
)

A version of BLI_stack_pop_n which fills in an array (in the reverse order).

Note
The first item in the array will be first item added to the stack.

Definition at line 154 of file stack.c.

References BLI_assert, BLI_stack_count(), BLI_stack_pop(), and BLI_Stack::elem_size.

Referenced by BM_mesh_edgeloops_find(), BM_mesh_edgeloops_find_path(), and BM_mesh_intersect_edges().

◆ BLI_stack_push()

void BLI_stack_push ( BLI_Stack stack,
const void src 
)

◆ BLI_stack_push_r()

void* BLI_stack_push_r ( BLI_Stack stack)

◆ stack_chunk_elem_max_calc()

static size_t stack_chunk_elem_max_calc ( const size_t  elem_size,
size_t  chunk_size 
)
static
Returns
number of elements per chunk, optimized for slop-space.

Definition at line 49 of file stack.c.

References BLI_assert, CHUNK_ELEM_MIN, blender::io::obj::chunk_size, MEM_SIZE_OVERHEAD, and UNLIKELY.

Referenced by BLI_stack_new_ex().

◆ stack_free_chunks()

static void stack_free_chunks ( struct StackChunk data)
static

Definition at line 85 of file stack.c.

References data, and MEM_freeN.

Referenced by BLI_stack_free().

◆ stack_get_last_elem()

static void* stack_get_last_elem ( BLI_Stack stack)
static

Definition at line 41 of file stack.c.

Referenced by BLI_stack_peek(), BLI_stack_pop(), and BLI_stack_push_r().