C Container Collection (CCC)
Loading...
Searching...
No Matches
private_flat_bitset.h File Reference

The Private Flat Bitset Types and Interface. More...

#include "../configuration.h"
#include "../types.h"
Include dependency graph for private_flat_bitset.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Detailed Description

The Private Flat Bitset Types and Interface.

The bitset is meant for simple contiguous bit operations. Highlights of this implementation include the care given to range based operations in linear time.

Data Structures

struct  CCC_Flat_bitset
 

Macros

#define CCC_private_flat_bitset_block_count(private_bit_capacity)
 
#define CCC_private_flat_bitset_block_bytes(private_bit_capacity)
 
#define CCC_private_flat_bitset_default()
 
#define CCC_private_flat_bitset_non_CCC_private_flat_bitset_default_size( private_cap, ...)    __VA_ARGS__
 
#define CCC_private_flat_bitset_default_size(private_cap, ...)   private_cap
 
#define CCC_private_flat_bitset_optional_size(private_cap, ...)
 
#define CCC_private_flat_bitset_for( private_cap, private_count, private_bitblock_pointer)
 
#define CCC_private_flat_bitset_from( private_allocator, private_start_index, private_count, private_on_char, private_string, ...)
 
#define CCC_private_flat_bitset_with_capacity( private_allocate, private_cap, ...)
 
#define CCC_private_flat_bitset_count_check_storage_for( private_count, private_bit_compound_literal, private_optional_storage_specifier...)
 
#define CCC_private_flat_bitset_storage_for( private_bit_compound_literal, private_optional_storage_specifier...)
 
#define CCC_private_flat_bitset_with_storage( private_count, private_compound_literal_array, private_optional_storage_specifier...)
 

Enumerations

enum  : size_t { CCC_PRIVATE_FLAT_BITSET_BLOCK_BITS = (sizeof(*(struct CCC_Flat_bitset){}.blocks) * CHAR_BIT) }
 

Functions

CCC_Result CCC_private_flat_bitset_reserve (struct CCC_Flat_bitset *, size_t, CCC_Allocator const *)
 
CCC_Tribool CCC_private_flat_bitset_set (struct CCC_Flat_bitset *, size_t, CCC_Tribool)
 

Macro Definition Documentation

◆ CCC_private_flat_bitset_block_bytes

#define CCC_private_flat_bitset_block_bytes (   private_bit_capacity)
Value:
(sizeof(*(struct CCC_Flat_bitset){}.blocks) \
* CCC_private_flat_bitset_block_count(private_bit_capacity))
#define CCC_private_flat_bitset_block_count(private_bit_capacity)
Definition: private_flat_bitset.h:70
Definition: private_flat_bitset.h:41

Returns the number of bytes needed for the required blocks.

◆ CCC_private_flat_bitset_block_count

#define CCC_private_flat_bitset_block_count (   private_bit_capacity)
Value:
(((private_bit_capacity) + (CCC_PRIVATE_FLAT_BITSET_BLOCK_BITS - 1)) \
@ CCC_PRIVATE_FLAT_BITSET_BLOCK_BITS
Definition: private_flat_bitset.h:52

Returns the number of blocks needed to support a given capacity of bits. Assumes the given capacity is greater than 0. Classic div round up.

◆ CCC_private_flat_bitset_count_check_storage_for

#define CCC_private_flat_bitset_count_check_storage_for (   private_count,
  private_bit_compound_literal,
  private_optional_storage_specifier... 
)
Value:
(typeof ( \
*(struct CCC_Flat_bitset){}.blocks \
sizeof(private_bit_compound_literal) \
)]) { \
}

Clang is more forgiving with what qualifies as a constant expression for both constructing compound literals and using static asserts. The static asserts are so helpful that it is worth every effort to give them to the user. GCC is not so forgiving.

◆ CCC_private_flat_bitset_default

#define CCC_private_flat_bitset_default ( )
Value:
(struct CCC_Flat_bitset) { \
}

◆ CCC_private_flat_bitset_default_size

#define CCC_private_flat_bitset_default_size (   private_cap,
  ... 
)    private_cap

◆ CCC_private_flat_bitset_for

#define CCC_private_flat_bitset_for (   private_cap,
  private_count,
  private_bitblock_pointer 
)
Value:
(struct CCC_Flat_bitset) { \
.blocks = memset( \
(private_bitblock_pointer), \
0, \
), \
.count = (private_count), .capacity = (private_cap), \
}
#define CCC_private_flat_bitset_block_bytes(private_bit_capacity)
Definition: private_flat_bitset.h:75
size_t capacity
Definition: private_flat_bitset.h:47

This initializer must be runtime only because the possibility the bitset comes from an uninitialized heap.

◆ CCC_private_flat_bitset_from

#define CCC_private_flat_bitset_from (   private_allocator,
  private_start_index,
  private_count,
  private_on_char,
  private_string,
  ... 
)
Value:
(struct { struct CCC_Flat_bitset private; }){(__extension__({ \
struct CCC_Flat_bitset private_bitset \
size_t const private_cap = CCC_private_flat_bitset_optional_size( \
(private_count), __VA_ARGS__ \
); \
size_t private_index = (private_start_index); \
&private_bitset, \
private_cap < private_count ? private_count : private_cap, \
&private_allocator \
) \
== CCC_RESULT_OK) { \
private_bitset.count = private_count; \
while (private_index < private_count \
&& private_string[private_index]) { \
&private_bitset, \
private_index, \
(CCC_Tribool)(private_string[private_index] \
== private_on_char) \
); \
++private_index; \
} \
private_bitset.count = private_index; \
} \
private_bitset; \
}))}.private
#define CCC_private_flat_bitset_optional_size(private_cap,...)
Definition: private_flat_bitset.h:92
#define CCC_private_flat_bitset_default()
Definition: private_flat_bitset.h:80
CCC_Result CCC_private_flat_bitset_reserve(struct CCC_Flat_bitset *, size_t, CCC_Allocator const *)
CCC_Tribool CCC_private_flat_bitset_set(struct CCC_Flat_bitset *, size_t, CCC_Tribool)
size_t count
Definition: private_flat_bitset.h:45
CCC_Tribool
A three state boolean to allow for an error state. Error is -1, False is 0, and True is 1.
Definition: types.h:178
@ CCC_RESULT_OK
Definition: types.h:194

Determine if user wants capacity different than count. Then pass to inline function for bit set construction.

◆ CCC_private_flat_bitset_non_CCC_private_flat_bitset_default_size

#define CCC_private_flat_bitset_non_CCC_private_flat_bitset_default_size (   private_cap,
  ... 
)     __VA_ARGS__

NOLINTNEXTLINE

◆ CCC_private_flat_bitset_optional_size

#define CCC_private_flat_bitset_optional_size (   private_cap,
  ... 
)
Value:
__VA_OPT__(CCC_private_flat_bitset_non_) \
##CCC_private_flat_bitset_default_size(private_cap, __VA_ARGS__)

◆ CCC_private_flat_bitset_storage_for

#define CCC_private_flat_bitset_storage_for (   private_bit_compound_literal,
  private_optional_storage_specifier... 
)
Value:
0, \
private_bit_compound_literal, \
private_optional_storage_specifier \
)
#define CCC_private_flat_bitset_count_check_storage_for( private_count, private_bit_compound_literal, private_optional_storage_specifier...)
Definition: private_flat_bitset.h:219

◆ CCC_private_flat_bitset_with_capacity

#define CCC_private_flat_bitset_with_capacity (   private_allocate,
  private_cap,
  ... 
)
Value:
(struct { struct CCC_Flat_bitset private; }){(__extension__({ \
struct CCC_Flat_bitset private_bitset \
size_t const private_count = CCC_private_flat_bitset_optional_size( \
(private_cap), __VA_ARGS__ \
); \
&private_bitset, private_cap, &private_allocate \
) \
== CCC_RESULT_OK) { \
private_bitset.count = private_count; \
} \
private_bitset; \
}))}.private

.

◆ CCC_private_flat_bitset_with_storage

#define CCC_private_flat_bitset_with_storage (   private_count,
  private_compound_literal_array,
  private_optional_storage_specifier... 
)
Value:
(struct CCC_Flat_bitset) { \
private_count, \
private_compound_literal_array, \
private_optional_storage_specifier \
), \
.count = (private_count), \
sizeof(private_compound_literal_array) \
) \
* sizeof(*(struct CCC_Flat_bitset){}.blocks) * CHAR_BIT, \
}

Enumeration Type Documentation

◆ anonymous enum

anonymous enum : size_t
Enumerator
CCC_PRIVATE_FLAT_BITSET_BLOCK_BITS 

The number of bits in a bit block. In sync with set type.

Function Documentation

◆ CCC_private_flat_bitset_reserve()

CCC_Result CCC_private_flat_bitset_reserve ( struct CCC_Flat_bitset ,
size_t  ,
CCC_Allocator const *   
)

◆ CCC_private_flat_bitset_set()

CCC_Tribool CCC_private_flat_bitset_set ( struct CCC_Flat_bitset ,
size_t  ,
CCC_Tribool   
)