Derive-C
Loading...
Searching...
No Matches
utils.h File Reference
#include <stdint.h>
#include <stddef.h>
#include <derive-c/core/math.h>
#include <derive-c/core/prelude.h>

Go to the source code of this file.

Data Structures

struct  _dc_ankerl_mdata
struct  _dc_ankerl_small_bucket
struct  _dc_ankerl_bucket

Typedefs

typedef uint8_t _dc_ankerl_dfd

Functions

static DC_INTERNAL size_t _dc_ankerl_buckets_capacity (size_t for_items)
static DC_INTERNAL uint8_t _dc_ankerl_fingerprint_from_hash (size_t hash)
static DC_INTERNAL _dc_ankerl_dfd _dc_ankerl_dfd_increment (_dc_ankerl_dfd dfd)
static DC_INTERNAL _dc_ankerl_dfd _dc_ankerl_dfd_decrement_for_backshift (_dc_ankerl_dfd dfd)
static DC_INTERNAL _dc_ankerl_dfd _dc_ankerl_dfd_new (uint8_t distance)
static DC_INTERNAL bool _dc_ankerl_mdata_present (_dc_ankerl_mdata const *bucket)
 DC_STATIC_ASSERT (sizeof(_dc_ankerl_small_bucket)==4)
static DC_INTERNAL _dc_ankerl_small_bucket new (_dc_ankerl_mdata mdata, size_t index)
static DC_INTERNAL size_t get_index (_dc_ankerl_small_bucket const *bucket)
 DC_STATIC_ASSERT (sizeof(_dc_ankerl_bucket)==8)
static DC_INTERNAL size_t get_index (_dc_ankerl_bucket const *bucket)

Variables

static const size_t dc_ankerl_initial_items = 256
static const _dc_ankerl_dfd _dc_ankerl_dfd_none = 0
static const _dc_ankerl_dfd _dc_ankerl_dfd_max = (_dc_ankerl_dfd)UINT8_MAX
DC_STATIC_CONSTANT size_t max_index_exclusive = (size_t)UINT16_MAX

Typedef Documentation

◆ _dc_ankerl_dfd

typedef uint8_t _dc_ankerl_dfd

Definition at line 24 of file utils.h.

Function Documentation

◆ _dc_ankerl_buckets_capacity()

DC_INTERNAL size_t _dc_ankerl_buckets_capacity ( size_t for_items)
static

Definition at line 11 of file utils.h.

11 {
12 if (for_items < dc_ankerl_initial_items) {
14 }
15 return dc_math_next_power_of_2(for_items);
16}
static const size_t dc_ankerl_initial_items
Definition utils.h:9
static DC_INLINE DC_CONST size_t dc_math_next_power_of_2(size_t x)
Definition math.h:46

◆ _dc_ankerl_dfd_decrement_for_backshift()

DC_INTERNAL _dc_ankerl_dfd _dc_ankerl_dfd_decrement_for_backshift ( _dc_ankerl_dfd dfd)
static

Definition at line 32 of file utils.h.

32 {
34 if (dfd == _dc_ankerl_dfd_max) {
35 return _dc_ankerl_dfd_max;
36 }
37 return (_dc_ankerl_dfd)(dfd - 1U);
38}
static const _dc_ankerl_dfd _dc_ankerl_dfd_max
Definition utils.h:26
uint8_t _dc_ankerl_dfd
Definition utils.h:24
static const _dc_ankerl_dfd _dc_ankerl_dfd_none
Definition utils.h:25
#define DC_ASSERT(expr,...)
Definition panic.h:37

◆ _dc_ankerl_dfd_increment()

DC_INTERNAL _dc_ankerl_dfd _dc_ankerl_dfd_increment ( _dc_ankerl_dfd dfd)
static

Definition at line 28 of file utils.h.

28 {
29 return (dfd == _dc_ankerl_dfd_max) ? _dc_ankerl_dfd_max : (_dc_ankerl_dfd)(dfd + 1U);
30}

◆ _dc_ankerl_dfd_new()

DC_INTERNAL _dc_ankerl_dfd _dc_ankerl_dfd_new ( uint8_t distance)
static

Definition at line 40 of file utils.h.

40 {
41 return (_dc_ankerl_dfd)(distance + 1U);
42}

◆ _dc_ankerl_fingerprint_from_hash()

DC_INTERNAL uint8_t _dc_ankerl_fingerprint_from_hash ( size_t hash)
static

Definition at line 18 of file utils.h.

18 {
19 uint8_t fp = (uint8_t)(hash >> (sizeof(size_t) * 8U - 8U));
20 return (fp == 0) ? 1U : fp;
21}

◆ _dc_ankerl_mdata_present()

DC_INTERNAL bool _dc_ankerl_mdata_present ( _dc_ankerl_mdata const * bucket)
static

Definition at line 49 of file utils.h.

49 {
50 return bucket->dfd != _dc_ankerl_dfd_none;
51}

◆ DC_STATIC_ASSERT() [1/2]

DC_STATIC_ASSERT ( sizeof(_dc_ankerl_bucket) = =8)

◆ DC_STATIC_ASSERT() [2/2]

DC_STATIC_ASSERT ( sizeof(_dc_ankerl_small_bucket) = =4)

◆ get_index() [1/2]

DC_INTERNAL size_t get_index ( _dc_ankerl_bucket const * bucket)
static

Definition at line 99 of file utils.h.

99 {
100 return (size_t)bucket->index_lo + ((size_t)bucket->index_hi << 32);
101}

◆ get_index() [2/2]

DC_INTERNAL size_t get_index ( _dc_ankerl_small_bucket const * bucket)
static

Definition at line 73 of file utils.h.

73 {
74 return (size_t)bucket->index;
75}

◆ new()

DC_INTERNAL _dc_ankerl_bucket new ( _dc_ankerl_mdata mdata,
size_t index )
static

Definition at line 63 of file utils.h.

64 {
67 .mdata = mdata,
68 .index = (uint16_t)(index),
69 };
70}
DC_STATIC_CONSTANT size_t max_index_exclusive
Definition utils.h:61
#define NS(pre, post)
Definition namespace.h:14
#define DC_ASSUME(expr,...)
Definition panic.h:57

Variable Documentation

◆ _dc_ankerl_dfd_max

const _dc_ankerl_dfd _dc_ankerl_dfd_max = (_dc_ankerl_dfd)UINT8_MAX
static

Definition at line 26 of file utils.h.

◆ _dc_ankerl_dfd_none

const _dc_ankerl_dfd _dc_ankerl_dfd_none = 0
static

Definition at line 25 of file utils.h.

◆ dc_ankerl_initial_items

const size_t dc_ankerl_initial_items = 256
static

Definition at line 9 of file utils.h.

◆ max_index_exclusive

DC_STATIC_CONSTANT size_t max_index_exclusive = (size_t)UINT16_MAX

Definition at line 61 of file utils.h.