Loading...
Searching...
No Matches
Bitset.h
Go to the documentation of this file.
/***************************************************************************************************
Zyan Core Library (Zycore-C)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
#ifndef ZYCORE_BITSET_H
#define ZYCORE_BITSET_H
#include <Zycore/Allocator.h>
#include <Zycore/Status.h>
#include <Zycore/Types.h>
#include <Zycore/Vector.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
typedef struct ZyanBitset_
{
ZyanUSize size;
ZyanVector bits;
} ZyanBitset;
typedef ZyanStatus (*ZyanBitsetByteOperation)(ZyanU8* v1, const ZyanU8* v2);
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Constructor and destructor */
/* ---------------------------------------------------------------------------------------------- */
#ifndef ZYAN_NO_LIBC
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanBitsetInit(ZyanBitset* bitset, ZyanUSize count);
#endif // ZYAN_NO_LIBC
ZYCORE_EXPORT ZyanStatus ZyanBitsetInitEx(ZyanBitset* bitset, ZyanUSize count,
ZyanAllocator* allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold);
ZYCORE_EXPORT ZyanStatus ZyanBitsetInitBuffer(ZyanBitset* bitset, ZyanUSize count, void* buffer,
ZyanUSize capacity);
ZYCORE_EXPORT ZyanStatus ZyanBitsetDestroy(ZyanBitset* bitset);
/* ---------------------------------------------------------------------------------------------- */
/* Logical operations */
/* ---------------------------------------------------------------------------------------------- */
ZYCORE_EXPORT ZyanStatus ZyanBitsetPerformByteOperation(ZyanBitset* destination,
const ZyanBitset* source, ZyanBitsetByteOperation operation);
ZYCORE_EXPORT ZyanStatus ZyanBitsetAND(ZyanBitset* destination, const ZyanBitset* source);
ZYCORE_EXPORT ZyanStatus ZyanBitsetOR (ZyanBitset* destination, const ZyanBitset* source);
ZYCORE_EXPORT ZyanStatus ZyanBitsetXOR(ZyanBitset* destination, const ZyanBitset* source);
ZYCORE_EXPORT ZyanStatus ZyanBitsetFlip(ZyanBitset* bitset);
/* ---------------------------------------------------------------------------------------------- */
/* Bit access */
/* ---------------------------------------------------------------------------------------------- */
ZYCORE_EXPORT ZyanStatus ZyanBitsetSet(ZyanBitset* bitset, ZyanUSize index);
ZYCORE_EXPORT ZyanStatus ZyanBitsetReset(ZyanBitset* bitset, ZyanUSize index);
ZYCORE_EXPORT ZyanStatus ZyanBitsetAssign(ZyanBitset* bitset, ZyanUSize index, ZyanBool value);
ZYCORE_EXPORT ZyanStatus ZyanBitsetToggle(ZyanBitset* bitset, ZyanUSize index);
ZYCORE_EXPORT ZyanStatus ZyanBitsetTest(ZyanBitset* bitset, ZyanUSize index);
ZYCORE_EXPORT ZyanStatus ZyanBitsetTestMSB(ZyanBitset* bitset);
ZYCORE_EXPORT ZyanStatus ZyanBitsetTestLSB(ZyanBitset* bitset);
/* ---------------------------------------------------------------------------------------------- */
ZYCORE_EXPORT ZyanStatus ZyanBitsetSetAll(ZyanBitset* bitset);
ZYCORE_EXPORT ZyanStatus ZyanBitsetResetAll(ZyanBitset* bitset);
/* ---------------------------------------------------------------------------------------------- */
/* Size management */
/* ---------------------------------------------------------------------------------------------- */
ZYCORE_EXPORT ZyanStatus ZyanBitsetPush(ZyanBitset* bitset, ZyanBool value);
ZYCORE_EXPORT ZyanStatus ZyanBitsetPop(ZyanBitset* bitset);
ZYCORE_EXPORT ZyanStatus ZyanBitsetClear(ZyanBitset* bitset);
/* ---------------------------------------------------------------------------------------------- */
/* Memory management */
/* ---------------------------------------------------------------------------------------------- */
ZYCORE_EXPORT ZyanStatus ZyanBitsetReserve(ZyanBitset* bitset, ZyanUSize count);
ZYCORE_EXPORT ZyanStatus ZyanBitsetShrinkToFit(ZyanBitset* bitset);
/* ---------------------------------------------------------------------------------------------- */
/* Information */
/* ---------------------------------------------------------------------------------------------- */
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetSize(const ZyanBitset* bitset, ZyanUSize* size);
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetCapacity(const ZyanBitset* bitset, ZyanUSize* capacity);
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetSizeBytes(const ZyanBitset* bitset, ZyanUSize* size);
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetCapacityBytes(const ZyanBitset* bitset, ZyanUSize* capacity);
/* ---------------------------------------------------------------------------------------------- */
ZYCORE_EXPORT ZyanStatus ZyanBitsetCount(const ZyanBitset* bitset, ZyanUSize* count);
ZYCORE_EXPORT ZyanStatus ZyanBitsetAll(const ZyanBitset* bitset);
ZYCORE_EXPORT ZyanStatus ZyanBitsetAny(const ZyanBitset* bitset);
ZYCORE_EXPORT ZyanStatus ZyanBitsetNone(const ZyanBitset* bitset);
//
// * Returns a 32-bit unsigned integer representation of the data.
// *
// * @param bitset A pointer to the `ZyanBitset` instance.
// * @param value Receives the 32-bit unsigned integer representation of the data.
// *
// * @return A zyan status code.
// */
//ZYCORE_EXPORT ZyanStatus ZyanBitsetToU32(const ZyanBitset* bitset, ZyanU32* value);
//
// * Returns a 64-bit unsigned integer representation of the data.
// *
// * @param bitset A pointer to the `ZyanBitset` instance.
// * @param value Receives the 64-bit unsigned integer representation of the data.
// *
// * @return A zyan status code.
// */
//ZYCORE_EXPORT ZyanStatus ZyanBitsetToU64(const ZyanBitset* bitset, ZyanU64* value);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYCORE_BITSET_H */
Allocator.h
ZyanAllocator
struct ZyanAllocator_ ZyanAllocator
ZyanBitsetReset
ZYCORE_EXPORT ZyanStatus ZyanBitsetReset(ZyanBitset *bitset, ZyanUSize index)
ZyanBitsetGetSizeBytes
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetSizeBytes(const ZyanBitset *bitset, ZyanUSize *size)
ZyanBitsetAND
ZYCORE_EXPORT ZyanStatus ZyanBitsetAND(ZyanBitset *destination, const ZyanBitset *source)
ZyanBitsetReserve
ZYCORE_EXPORT ZyanStatus ZyanBitsetReserve(ZyanBitset *bitset, ZyanUSize count)
ZyanBitsetAny
ZYCORE_EXPORT ZyanStatus ZyanBitsetAny(const ZyanBitset *bitset)
ZyanBitsetInitEx
ZYCORE_EXPORT ZyanStatus ZyanBitsetInitEx(ZyanBitset *bitset, ZyanUSize count, ZyanAllocator *allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold)
ZyanBitsetTestLSB
ZYCORE_EXPORT ZyanStatus ZyanBitsetTestLSB(ZyanBitset *bitset)
ZyanBitsetPerformByteOperation
ZYCORE_EXPORT ZyanStatus ZyanBitsetPerformByteOperation(ZyanBitset *destination, const ZyanBitset *source, ZyanBitsetByteOperation operation)
ZyanBitsetByteOperation
ZyanStatus(* ZyanBitsetByteOperation)(ZyanU8 *v1, const ZyanU8 *v2)
Definition Bitset.h:77
ZyanBitsetXOR
ZYCORE_EXPORT ZyanStatus ZyanBitsetXOR(ZyanBitset *destination, const ZyanBitset *source)
ZyanBitsetInit
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanBitsetInit(ZyanBitset *bitset, ZyanUSize count)
ZyanBitsetClear
ZYCORE_EXPORT ZyanStatus ZyanBitsetClear(ZyanBitset *bitset)
ZyanBitset
struct ZyanBitset_ ZyanBitset
ZyanBitsetGetSize
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetSize(const ZyanBitset *bitset, ZyanUSize *size)
ZyanBitsetTest
ZYCORE_EXPORT ZyanStatus ZyanBitsetTest(ZyanBitset *bitset, ZyanUSize index)
ZyanBitsetToggle
ZYCORE_EXPORT ZyanStatus ZyanBitsetToggle(ZyanBitset *bitset, ZyanUSize index)
ZyanBitsetOR
ZYCORE_EXPORT ZyanStatus ZyanBitsetOR(ZyanBitset *destination, const ZyanBitset *source)
ZyanBitsetCount
ZYCORE_EXPORT ZyanStatus ZyanBitsetCount(const ZyanBitset *bitset, ZyanUSize *count)
ZyanBitsetResetAll
ZYCORE_EXPORT ZyanStatus ZyanBitsetResetAll(ZyanBitset *bitset)
ZyanBitsetTestMSB
ZYCORE_EXPORT ZyanStatus ZyanBitsetTestMSB(ZyanBitset *bitset)
ZyanBitsetAll
ZYCORE_EXPORT ZyanStatus ZyanBitsetAll(const ZyanBitset *bitset)
ZyanBitsetPush
ZYCORE_EXPORT ZyanStatus ZyanBitsetPush(ZyanBitset *bitset, ZyanBool value)
ZyanBitsetSetAll
ZYCORE_EXPORT ZyanStatus ZyanBitsetSetAll(ZyanBitset *bitset)
ZyanBitsetDestroy
ZYCORE_EXPORT ZyanStatus ZyanBitsetDestroy(ZyanBitset *bitset)
ZyanBitsetAssign
ZYCORE_EXPORT ZyanStatus ZyanBitsetAssign(ZyanBitset *bitset, ZyanUSize index, ZyanBool value)
ZyanBitsetNone
ZYCORE_EXPORT ZyanStatus ZyanBitsetNone(const ZyanBitset *bitset)
ZyanBitsetGetCapacity
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetCapacity(const ZyanBitset *bitset, ZyanUSize *capacity)
ZyanBitsetShrinkToFit
ZYCORE_EXPORT ZyanStatus ZyanBitsetShrinkToFit(ZyanBitset *bitset)
ZyanBitsetInitBuffer
ZYCORE_EXPORT ZyanStatus ZyanBitsetInitBuffer(ZyanBitset *bitset, ZyanUSize count, void *buffer, ZyanUSize capacity)
ZyanBitsetPop
ZYCORE_EXPORT ZyanStatus ZyanBitsetPop(ZyanBitset *bitset)
ZyanBitsetGetCapacityBytes
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetCapacityBytes(const ZyanBitset *bitset, ZyanUSize *capacity)
ZyanBitsetSet
ZYCORE_EXPORT ZyanStatus ZyanBitsetSet(ZyanBitset *bitset, ZyanUSize index)
ZyanBitsetFlip
ZYCORE_EXPORT ZyanStatus ZyanBitsetFlip(ZyanBitset *bitset)
ZYAN_REQUIRES_LIBC
#define ZYAN_REQUIRES_LIBC
Definition Defines.h:382
ZYCORE_EXPORT
#define ZYCORE_EXPORT
Definition Defines.h:244
Status.h
ZyanStatus
ZyanU32 ZyanStatus
Definition Status.h:48
Types.h
ZyanBool
ZyanU8 ZyanBool
Definition Types.h:296
Vector.h
ZyanVector
struct ZyanVector_ ZyanVector
ZyanBitset_
Definition Bitset.h:55
ZyanBitset_::bits
ZyanVector bits
Definition Bitset.h:63
ZyanBitset_::size
ZyanUSize size
Definition Bitset.h:59