Derive-C
Loading...
Searching...
No Matches
utils.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <derive-c/core.h>
#include <derive-c/panic.h>
Include dependency graph for utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static bool is_power_of_2 (size_t x)
 
static size_t apply_capacity_policy (size_t capacity)
 
static size_t modulus_capacity (size_t index, size_t capacity)
 

Variables

static size_t const PROBE_DISTANCE = 1
 
static size_t const INITIAL_CAPACITY = 32
 

Function Documentation

◆ apply_capacity_policy()

static size_t apply_capacity_policy ( size_t capacity)
inlinestatic

Definition at line 10 of file utils.h.

10 {
11 // TODO(oliverkillane): play with overallocation policy
12 return next_power_of_2(capacity + capacity / 2);
13}
static size_t next_power_of_2(size_t x)
Definition core.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_power_of_2()

static bool is_power_of_2 ( size_t x)
inlinestatic

Definition at line 8 of file utils.h.

8{ return x != 0 && (x & (x - 1)) == 0; }
Here is the caller graph for this function:

◆ modulus_capacity()

static size_t modulus_capacity ( size_t index,
size_t capacity )
inlinestatic

Definition at line 15 of file utils.h.

15 {
17 // NOTE: If we know capacity is a power of 2, we can reduce the cost of 'index + 1 % capacity'
18 return index & (capacity - 1);
19}
#define DEBUG_ASSERT(expr)
Definition panic.h:24
static bool is_power_of_2(size_t x)
Definition utils.h:8
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ INITIAL_CAPACITY

size_t const INITIAL_CAPACITY = 32
static

Definition at line 22 of file utils.h.

◆ PROBE_DISTANCE

size_t const PROBE_DISTANCE = 1
static

Definition at line 21 of file utils.h.