Zycore 1.4.0.0
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
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
54typedef struct ZyanBitset_
55{
59 ZyanUSize size;
65
77typedef ZyanStatus (*ZyanBitsetByteOperation)(ZyanU8* v1, const ZyanU8* v2);
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
133ZYCORE_EXPORT ZyanStatus ZyanBitsetInitBuffer(ZyanBitset* bitset, ZyanUSize count, void* buffer,
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
379ZYCORE_EXPORT ZyanStatus ZyanBitsetGetSize(const ZyanBitset* bitset, ZyanUSize* size);
380
389ZYCORE_EXPORT ZyanStatus ZyanBitsetGetCapacity(const ZyanBitset* bitset, ZyanUSize* capacity);
390
400
410
411/* ---------------------------------------------------------------------------------------------- */
412
421ZYCORE_EXPORT ZyanStatus ZyanBitsetCount(const ZyanBitset* bitset, ZyanUSize* count);
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 */
ZYCORE_EXPORT ZyanStatus ZyanBitsetReset(ZyanBitset *bitset, ZyanUSize index)
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetSizeBytes(const ZyanBitset *bitset, ZyanUSize *size)
ZYCORE_EXPORT ZyanStatus ZyanBitsetAND(ZyanBitset *destination, const ZyanBitset *source)
ZYCORE_EXPORT ZyanStatus ZyanBitsetReserve(ZyanBitset *bitset, ZyanUSize count)
ZYCORE_EXPORT ZyanStatus ZyanBitsetAny(const ZyanBitset *bitset)
ZYCORE_EXPORT ZyanStatus ZyanBitsetInitEx(ZyanBitset *bitset, ZyanUSize count, ZyanAllocator *allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold)
ZYCORE_EXPORT ZyanStatus ZyanBitsetTestLSB(ZyanBitset *bitset)
ZYCORE_EXPORT ZyanStatus ZyanBitsetPerformByteOperation(ZyanBitset *destination, const ZyanBitset *source, ZyanBitsetByteOperation operation)
ZyanStatus(* ZyanBitsetByteOperation)(ZyanU8 *v1, const ZyanU8 *v2)
Definition Bitset.h:77
ZYCORE_EXPORT ZyanStatus ZyanBitsetXOR(ZyanBitset *destination, const ZyanBitset *source)
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanBitsetInit(ZyanBitset *bitset, ZyanUSize count)
ZYCORE_EXPORT ZyanStatus ZyanBitsetClear(ZyanBitset *bitset)
struct ZyanBitset_ ZyanBitset
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetSize(const ZyanBitset *bitset, ZyanUSize *size)
ZYCORE_EXPORT ZyanStatus ZyanBitsetTest(ZyanBitset *bitset, ZyanUSize index)
ZYCORE_EXPORT ZyanStatus ZyanBitsetToggle(ZyanBitset *bitset, ZyanUSize index)
ZYCORE_EXPORT ZyanStatus ZyanBitsetOR(ZyanBitset *destination, const ZyanBitset *source)
ZYCORE_EXPORT ZyanStatus ZyanBitsetCount(const ZyanBitset *bitset, ZyanUSize *count)
ZYCORE_EXPORT ZyanStatus ZyanBitsetResetAll(ZyanBitset *bitset)
ZYCORE_EXPORT ZyanStatus ZyanBitsetTestMSB(ZyanBitset *bitset)
ZYCORE_EXPORT ZyanStatus ZyanBitsetAll(const ZyanBitset *bitset)
ZYCORE_EXPORT ZyanStatus ZyanBitsetPush(ZyanBitset *bitset, ZyanBool value)
ZYCORE_EXPORT ZyanStatus ZyanBitsetSetAll(ZyanBitset *bitset)
ZYCORE_EXPORT ZyanStatus ZyanBitsetDestroy(ZyanBitset *bitset)
ZYCORE_EXPORT ZyanStatus ZyanBitsetAssign(ZyanBitset *bitset, ZyanUSize index, ZyanBool value)
ZYCORE_EXPORT ZyanStatus ZyanBitsetNone(const ZyanBitset *bitset)
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetCapacity(const ZyanBitset *bitset, ZyanUSize *capacity)
ZYCORE_EXPORT ZyanStatus ZyanBitsetShrinkToFit(ZyanBitset *bitset)
ZYCORE_EXPORT ZyanStatus ZyanBitsetInitBuffer(ZyanBitset *bitset, ZyanUSize count, void *buffer, ZyanUSize capacity)
ZYCORE_EXPORT ZyanStatus ZyanBitsetPop(ZyanBitset *bitset)
ZYCORE_EXPORT ZyanStatus ZyanBitsetGetCapacityBytes(const ZyanBitset *bitset, ZyanUSize *capacity)
ZYCORE_EXPORT ZyanStatus ZyanBitsetSet(ZyanBitset *bitset, ZyanUSize index)
ZYCORE_EXPORT ZyanStatus ZyanBitsetFlip(ZyanBitset *bitset)
#define ZYAN_REQUIRES_LIBC
Definition Defines.h:358
#define ZYCORE_EXPORT
Definition Defines.h:227
ZyanU32 ZyanStatus
Definition Status.h:48
ZyanU8 ZyanBool
Definition Types.h:192
Definition Allocator.h:89
Definition Bitset.h:55
ZyanVector bits
Definition Bitset.h:63
ZyanUSize size
Definition Bitset.h:59
Definition Vector.h:76