Zycore 1.5.2
Zyan Core Library for C
Loading...
Searching...
No Matches
Bitset.h
Go to the documentation of this file.
1/***************************************************************************************************
2
3 Zyan Core Library (Zycore-C)
4
5 Original Author : Florian Bernd
6
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24
25***************************************************************************************************/
26
31
32#ifndef ZYCORE_BITSET_H
33#define ZYCORE_BITSET_H
34
35#include <Zycore/Allocator.h>
36#include <Zycore/Status.h>
37#include <Zycore/Types.h>
38#include <Zycore/Vector.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/* ============================================================================================== */
45/* Enums and types */
46/* ============================================================================================== */
47
65
78
79/* ============================================================================================== */
80/* Exported functions */
81/* ============================================================================================== */
82
83/* ---------------------------------------------------------------------------------------------- */
84/* Constructor and destructor */
85/* ---------------------------------------------------------------------------------------------- */
86
87#ifndef ZYAN_NO_LIBC
88
101
102#endif // ZYAN_NO_LIBC
103
120 ZyanAllocator* allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold);
121
134 ZyanUSize capacity);
135
144
145/* ---------------------------------------------------------------------------------------------- */
146/* Logical operations */
147/* ---------------------------------------------------------------------------------------------- */
148
163 const ZyanBitset* source, ZyanBitsetByteOperation operation);
164
178
192
206
215
216/* ---------------------------------------------------------------------------------------------- */
217/* Bit access */
218/* ---------------------------------------------------------------------------------------------- */
219
229
239
250
260
271
281
291
292/* ---------------------------------------------------------------------------------------------- */
293
302
311
312/* ---------------------------------------------------------------------------------------------- */
313/* Size management */
314/* ---------------------------------------------------------------------------------------------- */
315
325
334
343
344/* ---------------------------------------------------------------------------------------------- */
345/* Memory management */
346/* ---------------------------------------------------------------------------------------------- */
347
357
366
367/* ---------------------------------------------------------------------------------------------- */
368/* Information */
369/* ---------------------------------------------------------------------------------------------- */
370
380
390
400
410
411/* ---------------------------------------------------------------------------------------------- */
412
422
432
442
452
454//
456// * Returns a 32-bit unsigned integer representation of the data.
457// *
458// * @param bitset A pointer to the `ZyanBitset` instance.
459// * @param value Receives the 32-bit unsigned integer representation of the data.
460// *
461// * @return A zyan status code.
462// */
463//ZYCORE_EXPORT ZyanStatus ZyanBitsetToU32(const ZyanBitset* bitset, ZyanU32* value);
464//
466// * Returns a 64-bit unsigned integer representation of the data.
467// *
468// * @param bitset A pointer to the `ZyanBitset` instance.
469// * @param value Receives the 64-bit unsigned integer representation of the data.
470// *
471// * @return A zyan status code.
472// */
473//ZYCORE_EXPORT ZyanStatus ZyanBitsetToU64(const ZyanBitset* bitset, ZyanU64* value);
474
475/* ---------------------------------------------------------------------------------------------- */
476
477/* ============================================================================================== */
478
479#ifdef __cplusplus
480}
481#endif
482
483#endif /* ZYCORE_BITSET_H */
struct ZyanAllocator_ ZyanAllocator
Defines the ZyanAllocator struct.
ZYCORE_EXPORT ZyanStatus ZyanBitsetReset(ZyanBitset *bitset, ZyanUSize index)
Sets the bit at index of the given ZyanBitset instance to 0.
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetSizeBytes(const ZyanBitset *bitset, ZyanUSize *size)
Returns the current size of the bitset in bytes.
ZYCORE_EXPORT ZyanStatus ZyanBitsetAND(ZyanBitset *destination, const ZyanBitset *source)
Performs a logical AND operation on the given ZyanBitset instances.
ZYCORE_EXPORT ZyanStatus ZyanBitsetReserve(ZyanBitset *bitset, ZyanUSize count)
Changes the capacity of the given ZyanBitset instance.
ZYCORE_EXPORT ZyanStatus ZyanBitsetAny(const ZyanBitset *bitset)
Checks, if at least one bit of the given bitset is set.
ZYCORE_EXPORT ZyanStatus ZyanBitsetInitEx(ZyanBitset *bitset, ZyanUSize count, ZyanAllocator *allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold)
Initializes the given ZyanBitset instance and sets a custom allocator and memory allocation/deallocat...
ZYCORE_EXPORT ZyanStatus ZyanBitsetTestLSB(ZyanBitset *bitset)
Returns the value of the least significant bit.
ZYCORE_EXPORT ZyanStatus ZyanBitsetPerformByteOperation(ZyanBitset *destination, const ZyanBitset *source, ZyanBitsetByteOperation operation)
Performs a byte-wise operation for every byte in the given ZyanBitset instances.
ZyanStatus(* ZyanBitsetByteOperation)(ZyanU8 *v1, const ZyanU8 *v2)
Defines the ZyanBitsetByteOperation function prototype.
Definition Bitset.h:77
ZYCORE_EXPORT ZyanStatus ZyanBitsetXOR(ZyanBitset *destination, const ZyanBitset *source)
Performs a logical XOR operation on the given ZyanBitset instances.
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanBitsetInit(ZyanBitset *bitset, ZyanUSize count)
Initializes the given ZyanBitset instance.
ZYCORE_EXPORT ZyanStatus ZyanBitsetClear(ZyanBitset *bitset)
Deletes all bits of the given ZyanBitset instance.
struct ZyanBitset_ ZyanBitset
Defines the ZyanVector struct.
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetSize(const ZyanBitset *bitset, ZyanUSize *size)
Returns the current size of the bitset in bits.
ZYCORE_EXPORT ZyanStatus ZyanBitsetTest(ZyanBitset *bitset, ZyanUSize index)
Returns the value of the bit at index.
ZYCORE_EXPORT ZyanStatus ZyanBitsetToggle(ZyanBitset *bitset, ZyanUSize index)
Toggles the bit at index of the given ZyanBitset instance.
ZYCORE_EXPORT ZyanStatus ZyanBitsetOR(ZyanBitset *destination, const ZyanBitset *source)
Performs a logical OR operation on the given ZyanBitset instances.
ZYCORE_EXPORT ZyanStatus ZyanBitsetCount(const ZyanBitset *bitset, ZyanUSize *count)
Returns the amount of bits set in the given bitset.
ZYCORE_EXPORT ZyanStatus ZyanBitsetResetAll(ZyanBitset *bitset)
Sets all bits of the given ZyanBitset instance to 0.
ZYCORE_EXPORT ZyanStatus ZyanBitsetTestMSB(ZyanBitset *bitset)
Returns the value of the most significant bit.
ZYCORE_EXPORT ZyanStatus ZyanBitsetAll(const ZyanBitset *bitset)
Checks, if all bits of the given bitset are set.
ZYCORE_EXPORT ZyanStatus ZyanBitsetPush(ZyanBitset *bitset, ZyanBool value)
Adds a new bit at the end of the bitset.
ZYCORE_EXPORT ZyanStatus ZyanBitsetSetAll(ZyanBitset *bitset)
Sets all bits of the given ZyanBitset instance to 1.
ZYCORE_EXPORT ZyanStatus ZyanBitsetDestroy(ZyanBitset *bitset)
Destroys the given ZyanBitset instance.
ZYCORE_EXPORT ZyanStatus ZyanBitsetAssign(ZyanBitset *bitset, ZyanUSize index, ZyanBool value)
Sets the bit at index of the given ZyanBitset instance to the specified value.
ZYCORE_EXPORT ZyanStatus ZyanBitsetNone(const ZyanBitset *bitset)
Checks, if none bits of the given bitset are set.
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetCapacity(const ZyanBitset *bitset, ZyanUSize *capacity)
Returns the current capacity of the bitset in bits.
ZYCORE_EXPORT ZyanStatus ZyanBitsetShrinkToFit(ZyanBitset *bitset)
Shrinks the capacity of the given bitset to match it's size.
ZYCORE_EXPORT ZyanStatus ZyanBitsetInitBuffer(ZyanBitset *bitset, ZyanUSize count, void *buffer, ZyanUSize capacity)
Initializes the given ZyanBitset instance and configures it to use a custom user defined buffer with ...
ZYCORE_EXPORT ZyanStatus ZyanBitsetPop(ZyanBitset *bitset)
Removes the last bit of the bitset.
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetCapacityBytes(const ZyanBitset *bitset, ZyanUSize *capacity)
Returns the current capacity of the bitset in bytes.
ZYCORE_EXPORT ZyanStatus ZyanBitsetSet(ZyanBitset *bitset, ZyanUSize index)
Sets the bit at index of the given ZyanBitset instance to 1.
ZYCORE_EXPORT ZyanStatus ZyanBitsetFlip(ZyanBitset *bitset)
Flips all bits of the given ZyanBitset instance.
#define ZYAN_REQUIRES_LIBC
Marks functions that require libc (cannot be used with ZYAN_NO_LIBC).
Definition Defines.h:468
#define ZYCORE_EXPORT
Symbol is exported in shared library builds.
Definition Defines.h:330
Status code definitions and check macros.
ZyanU32 ZyanStatus
Defines the ZyanStatus data type.
Definition Status.h:48
Includes and defines some default data types.
ZyanU8 ZyanBool
Defines the ZyanBool data-type.
Definition Types.h:296
size_t ZyanUSize
Definition Types.h:224
uint8_t ZyanU8
Definition Types.h:216
Implements the vector container class.
struct ZyanVector_ ZyanVector
Defines the ZyanVector struct.
Defines the ZyanVector struct.
Definition Bitset.h:55
ZyanUSize size
The bitset size.
Definition Bitset.h:59
ZyanVector bits
The bitset data.
Definition Bitset.h:63