odin-blend2d

Odin bindings to Blend2D
Log | Files | Refs | README | LICENSE

bitset.odin (5851B)


      1 // This file is part of Blend2D project <https://blend2d.com>
      2 //
      3 // See blend2d.h or LICENSE.md for license and copyright information
      4 // SPDX-License-Identifier: Zlib
      5 package blend2d
      6 
      7 when ODIN_OS == .Windows {
      8 	foreign import lib "blend2d.lib"
      9 } else when ODIN_OS == .Darwin {
     10 	foreign import lib "libblend2d.a"
     11 } else when ODIN_OS == .Linux {
     12 	foreign import lib "libblend2d.a"
     13 }
     14 
     15 
     16 //! \name BLBitSet - Constants
     17 //! \{
     18 BitSetConstants :: enum u32 {
     19 	//! Invalid bit-index.
     20 	//!
     21 	//! This is the only index that cannot be stored in `BLBitSet`.
     22 	INVALID_INDEX      = 4294967295,
     23 
     24 	//! Range mask used by `BLBitsetSegment::start` value - if set the segment is a range of all ones.
     25 	RANGE_MASK         = 2147483648,
     26 
     27 	//! Number of words in a BLBitSetSegment.
     28 	SEGMENT_WORD_COUNT = 4,
     29 }
     30 
     31 //! BitSet segment.
     32 //!
     33 //! Segment provides either a dense set of bits starting at `start` or a range of bits all set to one. The start of
     34 //! the segment is always aligned to segment size, which can be calculated as `32 * BL_BIT_SET_SEGMENT_WORD_COUNT`.
     35 //! Even ranges are aligned to this value, thus up to 3 segments are used to describe a range that doesn't start/end
     36 //! at the segment boundary.
     37 //!
     38 //! When the segment describes dense bits its size is always fixed and represents `32 * BL_BIT_SET_SEGMENT_WORD_COUNT`
     39 //! bits, which is currently 128 bits. However, when the segment describes all ones, the first value in data `data[0]`
     40 //! describes the last bit of the range, which means that an arbitrary range can be encoded within a single segment.
     41 BitSetSegment :: struct {
     42 	_start_word: u32,
     43 	_data:       [4]u32,
     44 }
     45 
     46 //! BitSet data view.
     47 BitSetData :: struct {
     48 	segment_data:  ^BitSetSegment,
     49 	segment_count: u32,
     50 	sso_segments:  [3]BitSetSegment,
     51 }
     52 
     53 @(default_calling_convention="c", link_prefix="bl_")
     54 foreign lib {
     55 	//! \name BLBitSet - C API
     56 	//! \{
     57 	bit_set_init                     :: proc(self: ^BitSetCore) -> Result ---
     58 	bit_set_init_move                :: proc(self: ^BitSetCore, other: ^BitSetCore) -> Result ---
     59 	bit_set_init_weak                :: proc(self: ^BitSetCore, other: ^BitSetCore) -> Result ---
     60 	bit_set_init_range               :: proc(self: ^BitSetCore, start_bit: u32, end_bit: u32) -> Result ---
     61 	bit_set_destroy                  :: proc(self: ^BitSetCore) -> Result ---
     62 	bit_set_reset                    :: proc(self: ^BitSetCore) -> Result ---
     63 	bit_set_assign_move              :: proc(self: ^BitSetCore, other: ^BitSetCore) -> Result ---
     64 	bit_set_assign_weak              :: proc(self: ^BitSetCore, other: ^BitSetCore) -> Result ---
     65 	bit_set_assign_deep              :: proc(self: ^BitSetCore, other: ^BitSetCore) -> Result ---
     66 	bit_set_assign_range             :: proc(self: ^BitSetCore, start_bit: u32, end_bit: u32) -> Result ---
     67 	bit_set_assign_words             :: proc(self: ^BitSetCore, start_word: u32, word_data: ^u32, word_count: u32) -> Result ---
     68 	bit_set_is_empty                 :: proc(self: ^BitSetCore) -> i32 ---
     69 	bit_set_get_data                 :: proc(self: ^BitSetCore, out: ^BitSetData) -> Result ---
     70 	bit_set_get_segment_count        :: proc(self: ^BitSetCore) -> u32 ---
     71 	bit_set_get_segment_capacity     :: proc(self: ^BitSetCore) -> u32 ---
     72 	bit_set_get_cardinality          :: proc(self: ^BitSetCore) -> u32 ---
     73 	bit_set_get_cardinality_in_range :: proc(self: ^BitSetCore, start_bit: u32, end_bit: u32) -> u32 ---
     74 	bit_set_has_bit                  :: proc(self: ^BitSetCore, bit_index: u32) -> i32 ---
     75 	bit_set_has_bits_in_range        :: proc(self: ^BitSetCore, start_bit: u32, end_bit: u32) -> i32 ---
     76 	bit_set_subsumes                 :: proc(a: ^BitSetCore, b: ^BitSetCore) -> i32 ---
     77 	bit_set_intersects               :: proc(a: ^BitSetCore, b: ^BitSetCore) -> i32 ---
     78 	bit_set_get_range                :: proc(self: ^BitSetCore, start_out: ^u32, end_out: ^u32) -> i32 ---
     79 	bit_set_equals                   :: proc(a: ^BitSetCore, b: ^BitSetCore) -> i32 ---
     80 	bit_set_compare                  :: proc(a: ^BitSetCore, b: ^BitSetCore) -> i32 ---
     81 	bit_set_clear                    :: proc(self: ^BitSetCore) -> Result ---
     82 	bit_set_shrink                   :: proc(self: ^BitSetCore) -> Result ---
     83 	bit_set_optimize                 :: proc(self: ^BitSetCore) -> Result ---
     84 	bit_set_chop                     :: proc(self: ^BitSetCore, start_bit: u32, end_bit: u32) -> Result ---
     85 	bit_set_add_bit                  :: proc(self: ^BitSetCore, bit_index: u32) -> Result ---
     86 	bit_set_add_range                :: proc(self: ^BitSetCore, range_start_bit: u32, range_end_bit: u32) -> Result ---
     87 	bit_set_add_words                :: proc(self: ^BitSetCore, start_word: u32, word_data: ^u32, word_count: u32) -> Result ---
     88 	bit_set_clear_bit                :: proc(self: ^BitSetCore, bit_index: u32) -> Result ---
     89 	bit_set_clear_range              :: proc(self: ^BitSetCore, range_start_bit: u32, range_end_bit: u32) -> Result ---
     90 
     91 	// TODO: Future API (BitSet).
     92 	/*
     93 	BL_API BLResult BL_CDECL bl_bit_set_combine(BLBitSetCore* dst, const BLBitSetCore* a, const BLBitSetCore* b, BLBooleanOp boolean_op) BL_NOEXCEPT_C;
     94 	*/
     95 	bit_set_builder_commit    :: proc(self: ^BitSetCore, builder: ^BitSetBuilderCore, new_area_index: u32) -> Result ---
     96 	bit_set_builder_add_range :: proc(self: ^BitSetCore, builder: ^BitSetBuilderCore, start_bit: u32, end_bit: u32) -> Result ---
     97 }
     98 
     99 //! BitSet container [C API].
    100 BitSetCore :: struct {
    101 	_d: ObjectDetail,
    102 }
    103 
    104 //! BitSet builder [C API].
    105 BitSetBuilderCore :: struct {
    106 	//! Shift to get `_area_index` from bit index, equals to `log2(kBitCount)`.
    107 	_area_shift: u32,
    108 
    109 	//! Area index - index from 0...N where each index represents `kBitCount` bits.
    110 	_area_index: u32,
    111 }
    112 
    113 //! BitSet container [Impl].
    114 BitSetImpl :: struct {
    115 	//! Count of used segments in `segment_data`.
    116 	segment_count: u32,
    117 
    118 	//! Count of allocated segments in `segment_data`.
    119 	segment_capacity: u32,
    120 }
    121