Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5687cb512c | ||
|
|
188cfae0d7 | ||
|
|
741566fafd | ||
|
|
9bec020f04 | ||
|
|
fe5f13d8ce | ||
|
|
df03b48319 |
No files matched your search
@@ -7,6 +7,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [3.3.1] - 2026-10-29
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- MSVC build issues
|
||||||
|
|
||||||
|
## [3.3.0] - 2026-10-24
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Containers for `b32`
|
||||||
|
|
||||||
|
## [3.2.0] - 2026-10-11
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `b32` alias for a 4-byte boolean
|
||||||
|
|
||||||
|
## [3.1.0] - 2026-10-05
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- `wpLogMakeLogger` to be compile time constant
|
||||||
|
|
||||||
|
## [3.0.0] - 2026-09-30
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `temp_begin` and `temp_end` ops to the `WpAllocator` interface
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- `wpMemArenaAllocatorTempBegin` and `wpMemArenaAllocatorTempEnd`
|
||||||
|
|
||||||
## [2.6.0] - 2026-09-30
|
## [2.6.0] - 2026-09-30
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -3,3 +3,17 @@
|
|||||||
**Wizard Apprentice Standard Library** (`wapp`) is a lightweight collection of reusable utilities for **C and C++** projects.
|
**Wizard Apprentice Standard Library** (`wapp`) is a lightweight collection of reusable utilities for **C and C++** projects.
|
||||||
|
|
||||||
For more information about the library and how to use it, check the [wiki](https://git.thewizardapprentice.com/abdelrahman/wizapp-stdlib/wiki).
|
For more information about the library and how to use it, check the [wiki](https://git.thewizardapprentice.com/abdelrahman/wizapp-stdlib/wiki).
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
Linux/macOS
|
||||||
|
|
||||||
|
```console
|
||||||
|
./build
|
||||||
|
```
|
||||||
|
|
||||||
|
Windows
|
||||||
|
|
||||||
|
```console
|
||||||
|
./build.ps1
|
||||||
|
```
|
||||||
@@ -205,7 +205,9 @@ void arrayRemoveSwapEnd(WpArray array, u64 index, u64 item_size) {
|
|||||||
|
|
||||||
u64 last_item_index = header->count - 1;
|
u64 last_item_index = header->count - 1;
|
||||||
|
|
||||||
if (index < last_item_index) {
|
// NOTE (Abdelrahman): Extract into a variable to get rid of MSVC Spectre mitigation warnings
|
||||||
|
b8 is_last_item = index == last_item_index;
|
||||||
|
if (!is_last_item) {
|
||||||
void *cur_item = arrayGetItemWithOffset(array, header->item_size * index);
|
void *cur_item = arrayGetItemWithOffset(array, header->item_size * index);
|
||||||
void *last_item = arrayGetItemWithOffset(array, header->item_size * last_item_index);
|
void *last_item = arrayGetItemWithOffset(array, header->item_size * last_item_index);
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ typedef u16 *WpU16Array;
|
|||||||
typedef u32 *WpU32Array;
|
typedef u32 *WpU32Array;
|
||||||
typedef u64 *WpU64Array;
|
typedef u64 *WpU64Array;
|
||||||
typedef b8 *WpB8Array;
|
typedef b8 *WpB8Array;
|
||||||
|
typedef b32 *WpB32Array;
|
||||||
typedef i8 *WpI8Array;
|
typedef i8 *WpI8Array;
|
||||||
typedef i16 *WpI16Array;
|
typedef i16 *WpI16Array;
|
||||||
typedef i32 *WpI32Array;
|
typedef i32 *WpI32Array;
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ typedef WpDblList WpU16List;
|
|||||||
typedef WpDblList WpU32List;
|
typedef WpDblList WpU32List;
|
||||||
typedef WpDblList WpU64List;
|
typedef WpDblList WpU64List;
|
||||||
typedef WpDblList WpB8List;
|
typedef WpDblList WpB8List;
|
||||||
|
typedef WpDblList WpB32List;
|
||||||
typedef WpDblList WpI8List;
|
typedef WpDblList WpI8List;
|
||||||
typedef WpDblList WpI16List;
|
typedef WpDblList WpI16List;
|
||||||
typedef WpDblList WpI32List;
|
typedef WpDblList WpI32List;
|
||||||
@@ -67,6 +68,7 @@ typedef WpDblNode WpU16Node;
|
|||||||
typedef WpDblNode WpU32Node;
|
typedef WpDblNode WpU32Node;
|
||||||
typedef WpDblNode WpU64Node;
|
typedef WpDblNode WpU64Node;
|
||||||
typedef WpDblNode WpB8Node;
|
typedef WpDblNode WpB8Node;
|
||||||
|
typedef WpDblNode WpB32Node;
|
||||||
typedef WpDblNode WpI8Node;
|
typedef WpDblNode WpI8Node;
|
||||||
typedef WpDblNode WpI16Node;
|
typedef WpDblNode WpI16Node;
|
||||||
typedef WpDblNode WpI32Node;
|
typedef WpDblNode WpI32Node;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "../../stream/stream.h"
|
#include "../../stream/stream.h"
|
||||||
#include "../../../common/aliases/aliases.h"
|
#include "../../../common/aliases/aliases.h"
|
||||||
|
#include "../../../common/misc/misc_utils.h"
|
||||||
|
|
||||||
#ifdef WP_PLATFORM_CPP
|
#ifdef WP_PLATFORM_CPP
|
||||||
BEGIN_C_LINKAGE
|
BEGIN_C_LINKAGE
|
||||||
@@ -30,6 +31,7 @@ typedef struct WpSiphashCtx {
|
|||||||
|
|
||||||
typedef struct WpHasherCtx {
|
typedef struct WpHasherCtx {
|
||||||
WpHasherCtxType type;
|
WpHasherCtxType type;
|
||||||
|
u8 padding[4];
|
||||||
union {
|
union {
|
||||||
WpSiphashCtx siphash;
|
WpSiphashCtx siphash;
|
||||||
void *user;
|
void *user;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ WpHasher wpX64Mur3HasherWithSeed(u32 seed) {
|
|||||||
WpU128 wpX64Mur3GetHash128(WpU8Stream *bytes, WpHasherCtx ctx) {
|
WpU128 wpX64Mur3GetHash128(WpU8Stream *bytes, WpHasherCtx ctx) {
|
||||||
validateMur3HasherCtx(&ctx);
|
validateMur3HasherCtx(&ctx);
|
||||||
|
|
||||||
const i32 nblocks = (bytes->count * bytes->item_size) / 16;
|
const i32 nblocks = (const i32)((bytes->count * bytes->item_size) / 16);
|
||||||
|
|
||||||
u64 h1 = ctx.murmur3;
|
u64 h1 = ctx.murmur3;
|
||||||
u64 h2 = ctx.murmur3;
|
u64 h2 = ctx.murmur3;
|
||||||
|
|||||||
@@ -119,12 +119,20 @@ void hashTableGrow(const WpAllocator *allocator, WpHashTable *table, u64 key_siz
|
|||||||
table->buckets = buckets;
|
table->buckets = buckets;
|
||||||
table->bucket_mask = mask;
|
table->bucket_mask = mask;
|
||||||
|
|
||||||
for (u64 i = 0; i < wpArrayCount(old_keys); ++i) {
|
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||||
void *key = arrayGet(old_keys, i, key_size);
|
// MSVC Spectre mitigation warnings
|
||||||
void *value = table->has_values ? arrayGet(old_values, i, value_size) : NULL;
|
u64 count = wpArrayCount(old_keys);
|
||||||
|
u64 index = 0;
|
||||||
|
b8 running = true;
|
||||||
|
while (running) {
|
||||||
|
void *key = arrayGet(old_keys, index, key_size);
|
||||||
|
void *value = table->has_values ? arrayGet(old_values, index, value_size) : NULL;
|
||||||
u64 hash = hashTableCalcHash(table, key, key_size);
|
u64 hash = hashTableCalcHash(table, key, key_size);
|
||||||
WpHashBucketRef ref = hashTableBucketRef(table, hash);
|
WpHashBucketRef ref = hashTableBucketRef(table, hash);
|
||||||
hashTableInsert(table, key, value, ref, key_size, value_size);
|
hashTableInsert(table, key, value, ref, key_size, value_size);
|
||||||
|
|
||||||
|
++index;
|
||||||
|
running = index < count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +140,9 @@ WpHashLookupResult hashTableLookup(WpHashTable *table, void *key, WpHashBucketRe
|
|||||||
hashTableValidate(table, key_size, 0);
|
hashTableValidate(table, key_size, 0);
|
||||||
wpDebugAssert(key != NULL, "`key` should not be NULL");
|
wpDebugAssert(key != NULL, "`key` should not be NULL");
|
||||||
|
|
||||||
while (true) {
|
u64 initial_bucket_index = ref.bucket_index;
|
||||||
|
b8 running = true;
|
||||||
|
while (running) {
|
||||||
WpHashBucket *bucket = &table->buckets[ref.bucket_index];
|
WpHashBucket *bucket = &table->buckets[ref.bucket_index];
|
||||||
|
|
||||||
if (ref.dist_and_tag == bucket->dist_and_tag) {
|
if (ref.dist_and_tag == bucket->dist_and_tag) {
|
||||||
@@ -152,7 +162,16 @@ WpHashLookupResult hashTableLookup(WpHashTable *table, void *key, WpHashBucketRe
|
|||||||
|
|
||||||
ref.dist_and_tag = hashTableDistInc(ref.dist_and_tag);
|
ref.dist_and_tag = hashTableDistInc(ref.dist_and_tag);
|
||||||
ref.bucket_index = hashTableNextBucket(table, ref.bucket_index);
|
ref.bucket_index = hashTableNextBucket(table, ref.bucket_index);
|
||||||
|
|
||||||
|
// Break if we loop back to the start bucket index
|
||||||
|
running = ref.bucket_index != initial_bucket_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (WpHashLookupResult){
|
||||||
|
.ref.dist_and_tag = ref.dist_and_tag,
|
||||||
|
.ref.bucket_index = ref.bucket_index,
|
||||||
|
.found = false,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void hashTableUpdate(WpHashTable *table, void *value, WpHashBucketRef ref, u64 value_size) {
|
void hashTableUpdate(WpHashTable *table, void *value, WpHashBucketRef ref, u64 value_size) {
|
||||||
@@ -172,7 +191,10 @@ void hashTableInsert(WpHashTable *table, void *key, void *value, WpHashBucketRef
|
|||||||
wpDebugAssert(key != NULL, "`key` should not be NULL");
|
wpDebugAssert(key != NULL, "`key` should not be NULL");
|
||||||
|
|
||||||
u64 index = wpArrayCount(table->keys);
|
u64 index = wpArrayCount(table->keys);
|
||||||
while (true) {
|
|
||||||
|
// NOTE (Abdelrahman): Extract into a variable to satisfy MSVC
|
||||||
|
b8 running = true;
|
||||||
|
while (running) {
|
||||||
WpHashBucket *bucket = &table->buckets[ref.bucket_index];
|
WpHashBucket *bucket = &table->buckets[ref.bucket_index];
|
||||||
|
|
||||||
if (bucket->dist_and_tag == 0) {
|
if (bucket->dist_and_tag == 0) {
|
||||||
@@ -202,7 +224,9 @@ void hashTableRemove(WpHashTable *table, WpHashBucketRef ref, u64 key_size, u64
|
|||||||
|
|
||||||
u64 last_item_index = wpArrayCount(table->keys) - 1;
|
u64 last_item_index = wpArrayCount(table->keys) - 1;
|
||||||
|
|
||||||
if (bucket->item_index < last_item_index) {
|
// NOTE (Abdelrahman): Extract into a variable to get rid of MSVC Spectre mitigation warnings
|
||||||
|
b8 is_last_item = bucket->item_index == last_item_index;
|
||||||
|
if (!is_last_item) {
|
||||||
// Update the bucket for the last item before swapping
|
// Update the bucket for the last item before swapping
|
||||||
u64 hash = hashTableCalcHash(table, arrayGet(table->keys, last_item_index, key_size), key_size);
|
u64 hash = hashTableCalcHash(table, arrayGet(table->keys, last_item_index, key_size), key_size);
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "../../stream/stream.h"
|
#include "../../stream/stream.h"
|
||||||
#include "../../../common/aliases/aliases.h"
|
#include "../../../common/aliases/aliases.h"
|
||||||
#include "../../../common/platform/platform.h"
|
#include "../../../common/platform/platform.h"
|
||||||
|
#include "../../../common/misc/misc_utils.h"
|
||||||
|
|
||||||
#ifdef WP_PLATFORM_CPP
|
#ifdef WP_PLATFORM_CPP
|
||||||
BEGIN_C_LINKAGE
|
BEGIN_C_LINKAGE
|
||||||
@@ -56,7 +57,7 @@ typedef struct WpHashTable {
|
|||||||
u64 magic;
|
u64 magic;
|
||||||
u64 bucket_mask;
|
u64 bucket_mask;
|
||||||
f32 load_factor;
|
f32 load_factor;
|
||||||
b8 has_values;
|
b32 has_values;
|
||||||
} WpHashTable;
|
} WpHashTable;
|
||||||
|
|
||||||
typedef struct WpHashBucketRef {
|
typedef struct WpHashBucketRef {
|
||||||
@@ -66,7 +67,9 @@ typedef struct WpHashBucketRef {
|
|||||||
|
|
||||||
typedef struct WpHashLookupResult {
|
typedef struct WpHashLookupResult {
|
||||||
WpHashBucketRef ref;
|
WpHashBucketRef ref;
|
||||||
b8 found;
|
b32 found;
|
||||||
|
|
||||||
|
wpMiscUtilsReservePadding(sizeof(WpHashBucketRef) + sizeof(b32));
|
||||||
} WpHashLookupResult;
|
} WpHashLookupResult;
|
||||||
|
|
||||||
void hashTableAlloc(const WpAllocator *allocator, WpHashTable *table,
|
void hashTableAlloc(const WpAllocator *allocator, WpHashTable *table,
|
||||||
|
|||||||
@@ -56,6 +56,26 @@ void wpMemAllocatorFree(const WpAllocator *allocator, void **ptr, u64 size) {
|
|||||||
allocator->free(ptr, size, allocator->obj);
|
allocator->free(ptr, size, allocator->obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wpMemAllocatorTempBegin(const WpAllocator *allocator) {
|
||||||
|
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||||
|
|
||||||
|
if (!wpMemAllocatorOpSupported(allocator, WP_MEM_OP_TEMP_BEGIN)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
allocator->temp_begin(allocator->obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wpMemAllocatorTempEnd(const WpAllocator *allocator) {
|
||||||
|
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||||
|
|
||||||
|
if (!wpMemAllocatorOpSupported(allocator, WP_MEM_OP_TEMP_END)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
allocator->temp_end(allocator->obj);
|
||||||
|
}
|
||||||
|
|
||||||
b8 wpMemAllocatorOpSupported(const WpAllocator *allocator, WpMemOp op) {
|
b8 wpMemAllocatorOpSupported(const WpAllocator *allocator, WpMemOp op) {
|
||||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||||
|
|
||||||
@@ -70,6 +90,11 @@ b8 wpMemAllocatorOpSupported(const WpAllocator *allocator, WpMemOp op) {
|
|||||||
return allocator->realloc_aligned != NULL;
|
return allocator->realloc_aligned != NULL;
|
||||||
case WP_MEM_OP_FREE:
|
case WP_MEM_OP_FREE:
|
||||||
return allocator->free != NULL;
|
return allocator->free != NULL;
|
||||||
|
case WP_MEM_OP_TEMP_BEGIN:
|
||||||
|
return allocator->temp_begin != NULL;
|
||||||
|
case WP_MEM_OP_TEMP_END:
|
||||||
|
return allocator->temp_end != NULL;
|
||||||
|
case COUNT_MEM_OPS:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,24 +17,30 @@ typedef enum WpMemOp {
|
|||||||
WP_MEM_OP_REALLOC,
|
WP_MEM_OP_REALLOC,
|
||||||
WP_MEM_OP_REALLOC_ALIGNED,
|
WP_MEM_OP_REALLOC_ALIGNED,
|
||||||
WP_MEM_OP_FREE,
|
WP_MEM_OP_FREE,
|
||||||
|
WP_MEM_OP_TEMP_BEGIN,
|
||||||
|
WP_MEM_OP_TEMP_END,
|
||||||
|
|
||||||
COUNT_MEM_OPS
|
COUNT_MEM_OPS
|
||||||
} WpMemOp;
|
} WpMemOp;
|
||||||
|
|
||||||
typedef void *(WpMemAllocFunc)(u64 size, void *alloc_obj);
|
typedef void *(WpMemAllocFunc)(u64 size, void *alloc_obj);
|
||||||
typedef void *(WpMemAllocAlignedFunc)(u64 size, u64 alignment, void *alloc_obj);
|
typedef void *(WpMemAllocAlignedFunc)(u64 size, u64 alignment, void *alloc_obj);
|
||||||
typedef void *(WpMemReallocFunc)(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
|
typedef void *(WpMemReallocFunc)(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
|
||||||
typedef void *(WpMemReallocAlignedFunc)(void *ptr, u64 old_size, u64 new_size, u64 alignment, void *alloc_obj);
|
typedef void *(WpMemReallocAlignedFunc)(void *ptr, u64 old_size, u64 new_size, u64 alignment, void *alloc_obj);
|
||||||
typedef void (WpMemFreeFunc)(void **ptr, u64 size, void *alloc_obj);
|
typedef void (WpMemFreeFunc)(void **ptr, u64 size, void *alloc_obj);
|
||||||
|
typedef void (WpMemTempBeginFunc)(void *alloc_obj);
|
||||||
|
typedef void (WpMemTempEndFunc)(void *alloc_obj);
|
||||||
|
|
||||||
typedef struct WpAllocator WpAllocator;
|
typedef struct WpAllocator WpAllocator;
|
||||||
struct WpAllocator {
|
struct WpAllocator {
|
||||||
void *obj;
|
void *obj;
|
||||||
WpMemAllocFunc *alloc;
|
WpMemAllocFunc *alloc;
|
||||||
WpMemAllocAlignedFunc *alloc_aligned;
|
WpMemAllocAlignedFunc *alloc_aligned;
|
||||||
WpMemReallocFunc *realloc;
|
WpMemReallocFunc *realloc;
|
||||||
WpMemReallocAlignedFunc *realloc_aligned;
|
WpMemReallocAlignedFunc *realloc_aligned;
|
||||||
WpMemFreeFunc *free;
|
WpMemFreeFunc *free;
|
||||||
|
WpMemTempBeginFunc *temp_begin;
|
||||||
|
WpMemTempEndFunc *temp_end;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef WP_PLATFORM_CPP
|
#ifdef WP_PLATFORM_CPP
|
||||||
@@ -50,8 +56,10 @@ void *wpMemAllocatorAlloc(const WpAllocator *allocator, u64 size);
|
|||||||
void *wpMemAllocatorAllocAligned(const WpAllocator *allocator, u64 size, u64 alignment);
|
void *wpMemAllocatorAllocAligned(const WpAllocator *allocator, u64 size, u64 alignment);
|
||||||
void *wpMemAllocatorRealloc(const WpAllocator *allocator, void *ptr, u64 old_size, u64 new_size);
|
void *wpMemAllocatorRealloc(const WpAllocator *allocator, void *ptr, u64 old_size, u64 new_size);
|
||||||
void *wpMemAllocatorReallocAligned(const WpAllocator *allocator, void *ptr, u64 old_size,
|
void *wpMemAllocatorReallocAligned(const WpAllocator *allocator, void *ptr, u64 old_size,
|
||||||
u64 new_size, u64 alignment);
|
u64 new_size, u64 alignment);
|
||||||
void wpMemAllocatorFree(const WpAllocator *allocator, void **ptr, u64 size);
|
void wpMemAllocatorFree(const WpAllocator *allocator, void **ptr, u64 size);
|
||||||
|
void wpMemAllocatorTempBegin(const WpAllocator *allocator);
|
||||||
|
void wpMemAllocatorTempEnd(const WpAllocator *allocator);
|
||||||
b8 wpMemAllocatorOpSupported(const WpAllocator *allocator, WpMemOp op);
|
b8 wpMemAllocatorOpSupported(const WpAllocator *allocator, WpMemOp op);
|
||||||
|
|
||||||
#ifdef WP_PLATFORM_CPP
|
#ifdef WP_PLATFORM_CPP
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ typedef WpQueue WpU16Queue;
|
|||||||
typedef WpQueue WpU32Queue;
|
typedef WpQueue WpU32Queue;
|
||||||
typedef WpQueue WpU64Queue;
|
typedef WpQueue WpU64Queue;
|
||||||
typedef WpQueue WpB8Queue;
|
typedef WpQueue WpB8Queue;
|
||||||
|
typedef WpQueue WpB32Queue;
|
||||||
typedef WpQueue WpI8Queue;
|
typedef WpQueue WpI8Queue;
|
||||||
typedef WpQueue WpI16Queue;
|
typedef WpQueue WpI16Queue;
|
||||||
typedef WpQueue WpI32Queue;
|
typedef WpQueue WpI32Queue;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ typedef WpStream WpU16Stream;
|
|||||||
typedef WpStream WpU32Stream;
|
typedef WpStream WpU32Stream;
|
||||||
typedef WpStream WpU64Stream;
|
typedef WpStream WpU64Stream;
|
||||||
typedef WpStream WpB8Stream;
|
typedef WpStream WpB8Stream;
|
||||||
|
typedef WpStream WpB32Stream;
|
||||||
typedef WpStream WpI8Stream;
|
typedef WpStream WpI8Stream;
|
||||||
typedef WpStream WpI16Stream;
|
typedef WpStream WpI16Stream;
|
||||||
typedef WpStream WpI32Stream;
|
typedef WpStream WpI32Stream;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ typedef uint64_t u64;
|
|||||||
#define wpU64Const UINT64_C
|
#define wpU64Const UINT64_C
|
||||||
|
|
||||||
typedef uint8_t b8;
|
typedef uint8_t b8;
|
||||||
|
typedef uint32_t b32;
|
||||||
|
|
||||||
#ifndef WP_PLATFORM_CPP
|
#ifndef WP_PLATFORM_CPP
|
||||||
|
|
||||||
|
|||||||
+20
-10
@@ -3,6 +3,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "../base/strings/str8/str8.h"
|
#include "../base/strings/str8/str8.h"
|
||||||
#include "../common/aliases/aliases.h"
|
#include "../common/aliases/aliases.h"
|
||||||
|
#include "../common/platform/platform.h"
|
||||||
#include "../common/assert/assert.h"
|
#include "../common/assert/assert.h"
|
||||||
#include "../common/misc/misc_utils.h"
|
#include "../common/misc/misc_utils.h"
|
||||||
#include "../os/file/file.h"
|
#include "../os/file/file.h"
|
||||||
@@ -11,9 +12,9 @@
|
|||||||
#define MIN_LOG_MSG_LENGTH 128
|
#define MIN_LOG_MSG_LENGTH 128
|
||||||
#define TIME_BUF_CAPACITY 70
|
#define TIME_BUF_CAPACITY 70
|
||||||
|
|
||||||
wp_intern WpStr8RO L_BRACKET = wpStr8LitRo("[");
|
wp_intern WpStr8RO L_BRACKET = wpStr8LitRoInitialiserList("[");
|
||||||
wp_intern WpStr8RO R_BRACKET_SPACE = wpStr8LitRo("] ");
|
wp_intern WpStr8RO R_BRACKET_SPACE = wpStr8LitRoInitialiserList("] ");
|
||||||
wp_intern WpStr8RO R_BRACKET_NEWLINE = wpStr8LitRo("]\n");
|
wp_intern WpStr8RO R_BRACKET_NEWLINE = wpStr8LitRoInitialiserList("]\n");
|
||||||
|
|
||||||
typedef struct LogConfig {
|
typedef struct LogConfig {
|
||||||
WpFile *outlog;
|
WpFile *outlog;
|
||||||
@@ -48,10 +49,6 @@ void wpLogConfigure(WpFile *outlog, WpFile *errlog, WpLogLevel level) {
|
|||||||
LOG_CONFIG.level = level;
|
LOG_CONFIG.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
WpLogger wpLogMakeLogger(WpStr8 name) {
|
|
||||||
return (WpLogger){ .name = name };
|
|
||||||
}
|
|
||||||
|
|
||||||
void wpLogDebug(const WpLogger *logger, WpStr8 msg) {
|
void wpLogDebug(const WpLogger *logger, WpStr8 msg) {
|
||||||
wpDebugAssert(logger != NULL, "`logger` should not be NULL");
|
wpDebugAssert(logger != NULL, "`logger` should not be NULL");
|
||||||
if (LOG_CONFIG.level < WP_LOG_LEVEL_DEBUG) { return; }
|
if (LOG_CONFIG.level < WP_LOG_LEVEL_DEBUG) { return; }
|
||||||
@@ -105,14 +102,20 @@ wp_intern void getCurrentTimeString(WpStr8 *dst) {
|
|||||||
char buf[TIME_BUF_CAPACITY];
|
char buf[TIME_BUF_CAPACITY];
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
struct tm utc;
|
struct tm utc;
|
||||||
|
|
||||||
|
#ifdef WP_PLATFORM_WINDOWS
|
||||||
|
gmtime_s(&utc, &now);
|
||||||
|
#else
|
||||||
gmtime_r(&now, &utc);
|
gmtime_r(&now, &utc);
|
||||||
|
#endif
|
||||||
|
|
||||||
strftime(buf, sizeof(buf), "%FT%TZ ", &utc);
|
strftime(buf, sizeof(buf), "%FT%TZ ", &utc);
|
||||||
wpStr8CopyCstrCapped(dst, buf);
|
wpStr8CopyCstrCapped(dst, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_intern void writeLogLine(WpFile *fp, const WpLogger *logger, WpStr8 msg, WpLogLevel level) {
|
wp_intern void writeLogLine(WpFile *fp, const WpLogger *logger, WpStr8 msg, WpLogLevel level) {
|
||||||
WpStr8 padding = wpStr8Buf(MIN_LOG_MSG_LENGTH);
|
WpStr8 padding = wpStr8Buf(MIN_LOG_MSG_LENGTH);
|
||||||
u32 padding_size = msg.size < MIN_LOG_MSG_LENGTH ? MIN_LOG_MSG_LENGTH - msg.size + 1 : 0;
|
u32 padding_size = (u32)(msg.size < MIN_LOG_MSG_LENGTH ? MIN_LOG_MSG_LENGTH - msg.size + 1 : 0);
|
||||||
wpStr8Format(&padding, "%-*s", padding_size, " ");
|
wpStr8Format(&padding, "%-*s", padding_size, " ");
|
||||||
|
|
||||||
WpStr8 time_str = wpStr8Buf(TIME_BUF_CAPACITY);
|
WpStr8 time_str = wpStr8Buf(TIME_BUF_CAPACITY);
|
||||||
@@ -131,7 +134,14 @@ wp_intern void writeLogLine(WpFile *fp, const WpLogger *logger, WpStr8 msg, WpLo
|
|||||||
&R_BRACKET_NEWLINE
|
&R_BRACKET_NEWLINE
|
||||||
);
|
);
|
||||||
|
|
||||||
for (u64 i = 0; i < wpArrayCount(strings); ++i) {
|
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||||
wpFileWriteStr8(strings[i], fp);
|
// MSVC Spectre mitigation warnings
|
||||||
|
u64 count = wpArrayCount(strings);
|
||||||
|
u64 index = 0;
|
||||||
|
b8 running = true;
|
||||||
|
while (running) {
|
||||||
|
wpFileWriteStr8(strings[index], fp);
|
||||||
|
++index;
|
||||||
|
running = index < count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+7
-1
@@ -3,6 +3,7 @@
|
|||||||
#ifndef LOG_H
|
#ifndef LOG_H
|
||||||
#define LOG_H
|
#define LOG_H
|
||||||
|
|
||||||
|
#include "../common/platform/platform.h"
|
||||||
#include "../os/file/file.h"
|
#include "../os/file/file.h"
|
||||||
#include "../base/strings/str8/str8.h"
|
#include "../base/strings/str8/str8.h"
|
||||||
|
|
||||||
@@ -25,9 +26,14 @@ typedef struct WpLogger {
|
|||||||
WpStr8 name;
|
WpStr8 name;
|
||||||
} WpLogger;
|
} WpLogger;
|
||||||
|
|
||||||
|
#ifdef WP_PLATFORM_CPP
|
||||||
|
#define wpLogMakeLogger(NAME) (WpLogger{NAME})
|
||||||
|
#else
|
||||||
|
#define wpLogMakeLogger(NAME) ((WpLogger){ .name = NAME })
|
||||||
|
#endif
|
||||||
|
|
||||||
void wpLogSetLevel(WpLogLevel level);
|
void wpLogSetLevel(WpLogLevel level);
|
||||||
void wpLogConfigure(WpFile *outlog, WpFile *errlog, WpLogLevel level);
|
void wpLogConfigure(WpFile *outlog, WpFile *errlog, WpLogLevel level);
|
||||||
WpLogger wpLogMakeLogger(WpStr8 name);
|
|
||||||
void wpLogDebug(const WpLogger *logger, WpStr8 msg);
|
void wpLogDebug(const WpLogger *logger, WpStr8 msg);
|
||||||
void wpLogInfo(const WpLogger *logger, WpStr8 msg);
|
void wpLogInfo(const WpLogger *logger, WpStr8 msg);
|
||||||
void wpLogWarning(const WpLogger *logger, WpStr8 msg);
|
void wpLogWarning(const WpLogger *logger, WpStr8 msg);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include "mem_arena_allocator.h"
|
#include "mem_arena_allocator.h"
|
||||||
#include "mem_arena.h"
|
#include "mem_arena.h"
|
||||||
#include "../../mem/mem_os.h"
|
|
||||||
#include "../../../common/aliases/aliases.h"
|
#include "../../../common/aliases/aliases.h"
|
||||||
#include "../../../common/assert/assert.h"
|
#include "../../../common/assert/assert.h"
|
||||||
|
|
||||||
@@ -11,7 +10,9 @@ wp_intern void *memArenaAlloc(u64 size, void *alloc_obj);
|
|||||||
wp_intern void *memArenaAllocAligned(u64 size, u64 alignment, void *alloc_obj);
|
wp_intern void *memArenaAllocAligned(u64 size, u64 alignment, void *alloc_obj);
|
||||||
wp_intern void *memArenaRealloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
|
wp_intern void *memArenaRealloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
|
||||||
wp_intern void *memArenaReallocAligned(void *ptr, u64 old_size, u64 new_size, u64 alignment,
|
wp_intern void *memArenaReallocAligned(void *ptr, u64 old_size, u64 new_size, u64 alignment,
|
||||||
void *alloc_obj);
|
void *alloc_obj);
|
||||||
|
wp_intern void memArenaTempBegin(void *alloc_obj);
|
||||||
|
wp_intern void memArenaTempEnd(void *alloc_obj);
|
||||||
|
|
||||||
WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size) {
|
WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size) {
|
||||||
WpAllocator allocator = {0};
|
WpAllocator allocator = {0};
|
||||||
@@ -37,16 +38,6 @@ WpAllocator wpMemArenaAllocatorInitCustom(u64 base_capacity, WpMemAllocFlags fla
|
|||||||
return allocator;
|
return allocator;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wpMemArenaAllocatorTempBegin(const WpAllocator *allocator) {
|
|
||||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
|
||||||
wpMemArenaTempBegin((WpArena *)(allocator->obj));
|
|
||||||
}
|
|
||||||
|
|
||||||
void wpMemArenaAllocatorTempEnd(const WpAllocator *allocator) {
|
|
||||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
|
||||||
wpMemArenaTempEnd((WpArena *)(allocator->obj));
|
|
||||||
}
|
|
||||||
|
|
||||||
void wpMemArenaAllocatorClear(WpAllocator *allocator) {
|
void wpMemArenaAllocatorClear(WpAllocator *allocator) {
|
||||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||||
wpMemArenaClear((WpArena *)(allocator->obj));
|
wpMemArenaClear((WpArena *)(allocator->obj));
|
||||||
@@ -63,6 +54,8 @@ wp_intern void initialiseArenaAllocator(WpAllocator *allocator) {
|
|||||||
allocator->alloc_aligned = memArenaAllocAligned;
|
allocator->alloc_aligned = memArenaAllocAligned;
|
||||||
allocator->realloc = memArenaRealloc;
|
allocator->realloc = memArenaRealloc;
|
||||||
allocator->realloc_aligned = memArenaReallocAligned;
|
allocator->realloc_aligned = memArenaReallocAligned;
|
||||||
|
allocator->temp_begin = memArenaTempBegin;
|
||||||
|
allocator->temp_end = memArenaTempEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_intern void *memArenaAlloc(u64 size, void *alloc_obj) {
|
wp_intern void *memArenaAlloc(u64 size, void *alloc_obj) {
|
||||||
@@ -85,3 +78,13 @@ wp_intern void *memArenaReallocAligned(void *ptr, u64 old_size, u64 new_size, u6
|
|||||||
WpArena *arena = (WpArena *)alloc_obj;
|
WpArena *arena = (WpArena *)alloc_obj;
|
||||||
return wpMemArenaReallocAligned(arena, ptr, old_size, new_size, alignment);
|
return wpMemArenaReallocAligned(arena, ptr, old_size, new_size, alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wp_intern void memArenaTempBegin(void *alloc_obj) {
|
||||||
|
WpArena *arena = (WpArena *)alloc_obj;
|
||||||
|
wpMemArenaTempBegin(arena);
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_intern void memArenaTempEnd(void *alloc_obj) {
|
||||||
|
WpArena *arena = (WpArena *)alloc_obj;
|
||||||
|
wpMemArenaTempEnd(arena);
|
||||||
|
}
|
||||||
@@ -34,8 +34,6 @@ BEGIN_C_LINKAGE
|
|||||||
*/
|
*/
|
||||||
WpAllocator wpMemArenaAllocatorInitCustom(u64 base_capacity, WpMemAllocFlags flags, b8 zero_buffer);
|
WpAllocator wpMemArenaAllocatorInitCustom(u64 base_capacity, WpMemAllocFlags flags, b8 zero_buffer);
|
||||||
WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size);
|
WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size);
|
||||||
void wpMemArenaAllocatorTempBegin(const WpAllocator *allocator);
|
|
||||||
void wpMemArenaAllocatorTempEnd(const WpAllocator *allocator);
|
|
||||||
void wpMemArenaAllocatorClear(WpAllocator *allocator);
|
void wpMemArenaAllocatorClear(WpAllocator *allocator);
|
||||||
void wpMemArenaAllocatorDestroy(WpAllocator *allocator);
|
void wpMemArenaAllocatorDestroy(WpAllocator *allocator);
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ wp_intern void seedOsGenerator(u64 seed) {
|
|||||||
seed = (u64)ts.tv_nsec;
|
seed = (u64)ts.tv_nsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
srand(seed);
|
srand((u32)seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_intern u64 genRandomNumber(void) {
|
wp_intern u64 genRandomNumber(void) {
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ WpXor256State wpPrngXorshiftInit(void) {
|
|||||||
|
|
||||||
WpXor256State wpPrngXorshiftInitWithSeed(u64 seed) {
|
WpXor256State wpPrngXorshiftInitWithSeed(u64 seed) {
|
||||||
WpSplitmix64State sm64;
|
WpSplitmix64State sm64;
|
||||||
if (seed > 0) {
|
|
||||||
|
// NOTE (Abdelrahman): Extract into a variable to get rid of MSVC Spectre mitigation warnings
|
||||||
|
b8 seed_not_zero = seed > 0;
|
||||||
|
if (seed_not_zero) {
|
||||||
sm64 = wpPrngSplitmix64InitWithSeed(seed);
|
sm64 = wpPrngSplitmix64InitWithSeed(seed);
|
||||||
} else {
|
} else {
|
||||||
sm64 = wpPrngSplitmix64Init();
|
sm64 = wpPrngSplitmix64Init();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#define TEMP_BUF_SIZE (40 + sizeof(i32) * 8)
|
#define TEMP_BUF_SIZE (40 + sizeof(i32) * 8)
|
||||||
|
|
||||||
wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {0};
|
wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {0};
|
||||||
wp_intern WpAllocator temp_allocator = {0};
|
wp_intern WpAllocator temp_allocator = {0};
|
||||||
|
|
||||||
WpTestFuncResult test_arena_allocator(void) {
|
WpTestFuncResult test_arena_allocator(void) {
|
||||||
WpAllocator allocator = wpMemArenaAllocatorInit(4096);
|
WpAllocator allocator = wpMemArenaAllocatorInit(4096);
|
||||||
@@ -45,7 +45,7 @@ WpTestFuncResult test_arena_allocator_temp_begin(void) {
|
|||||||
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||||
b8 result = num1 != NULL;
|
b8 result = num1 != NULL;
|
||||||
|
|
||||||
wpMemArenaAllocatorTempBegin(&temp_allocator);
|
wpMemAllocatorTempBegin(&temp_allocator);
|
||||||
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||||
result = result && num2 != NULL;
|
result = result && num2 != NULL;
|
||||||
i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||||
@@ -55,7 +55,7 @@ WpTestFuncResult test_arena_allocator_temp_begin(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WpTestFuncResult test_arena_allocator_temp_end(void) {
|
WpTestFuncResult test_arena_allocator_temp_end(void) {
|
||||||
wpMemArenaAllocatorTempEnd(&temp_allocator);
|
wpMemAllocatorTempEnd(&temp_allocator);
|
||||||
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||||
b8 result = num1 != NULL;
|
b8 result = num1 != NULL;
|
||||||
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#define TEMP_BUF_SIZE (40 + sizeof(i32) * 8)
|
#define TEMP_BUF_SIZE (40 + sizeof(i32) * 8)
|
||||||
|
|
||||||
wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {};
|
wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {};
|
||||||
wp_intern WpAllocator temp_allocator = {};
|
wp_intern WpAllocator temp_allocator = {};
|
||||||
|
|
||||||
WpTestFuncResult test_arena_allocator(void) {
|
WpTestFuncResult test_arena_allocator(void) {
|
||||||
WpAllocator allocator = wpMemArenaAllocatorInit(4096);
|
WpAllocator allocator = wpMemArenaAllocatorInit(4096);
|
||||||
@@ -45,7 +45,7 @@ WpTestFuncResult test_arena_allocator_temp_begin(void) {
|
|||||||
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||||
b8 result = num1 != NULL;
|
b8 result = num1 != NULL;
|
||||||
|
|
||||||
wpMemArenaAllocatorTempBegin(&temp_allocator);
|
wpMemAllocatorTempBegin(&temp_allocator);
|
||||||
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||||
result = result && num2 != NULL;
|
result = result && num2 != NULL;
|
||||||
i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||||
@@ -55,7 +55,7 @@ WpTestFuncResult test_arena_allocator_temp_begin(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WpTestFuncResult test_arena_allocator_temp_end(void) {
|
WpTestFuncResult test_arena_allocator_temp_end(void) {
|
||||||
wpMemArenaAllocatorTempEnd(&temp_allocator);
|
wpMemAllocatorTempEnd(&temp_allocator);
|
||||||
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||||
b8 result = num1 != NULL;
|
b8 result = num1 != NULL;
|
||||||
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||||
|
|||||||
@@ -7,8 +7,13 @@
|
|||||||
// compile and run any of them on any platform, but your performance with the
|
// compile and run any of them on any platform, but your performance with the
|
||||||
// non-native version will be less than optimal.
|
// non-native version will be less than optimal.
|
||||||
|
|
||||||
|
#include "wapp.h"
|
||||||
#include "MurmurHash3.h"
|
#include "MurmurHash3.h"
|
||||||
|
|
||||||
|
#ifdef WP_PLATFORM_WINDOWS
|
||||||
|
#pragma warning(disable:5045)
|
||||||
|
#endif
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Platform-specific functions and macros
|
// Platform-specific functions and macros
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,13 @@
|
|||||||
// compile and run any of them on any platform, but your performance with the
|
// compile and run any of them on any platform, but your performance with the
|
||||||
// non-native version will be less than optimal.
|
// non-native version will be less than optimal.
|
||||||
|
|
||||||
|
#include "wapp.h"
|
||||||
#include "MurmurHash3.h"
|
#include "MurmurHash3.h"
|
||||||
|
|
||||||
|
#ifdef WP_PLATFORM_WINDOWS
|
||||||
|
#pragma warning(disable:5045)
|
||||||
|
#endif
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Platform-specific functions and macros
|
// Platform-specific functions and macros
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ int siphash(const void *in, const size_t inlen, const void *k, uint8_t *out,
|
|||||||
uint64_t m;
|
uint64_t m;
|
||||||
int i;
|
int i;
|
||||||
const unsigned char *end = ni + inlen - (inlen % sizeof(uint64_t));
|
const unsigned char *end = ni + inlen - (inlen % sizeof(uint64_t));
|
||||||
const int left = inlen & 7;
|
const int left = (const int)(inlen & 7);
|
||||||
uint64_t b = ((uint64_t)inlen) << 56;
|
uint64_t b = ((uint64_t)inlen) << 56;
|
||||||
v3 ^= k1;
|
v3 ^= k1;
|
||||||
v2 ^= k0;
|
v2 ^= k0;
|
||||||
|
|||||||
@@ -22,19 +22,19 @@ WpTestFuncResult test_murmur3(void) {
|
|||||||
|
|
||||||
// Sring hash
|
// Sring hash
|
||||||
WpU128 mur_hash = hasher.func(&str_bytes, hasher.ctx);
|
WpU128 mur_hash = hasher.func(&str_bytes, hasher.ctx);
|
||||||
MurmurHash3_x64_128(str_bytes.data, str_bytes.count * str_bytes.item_size, hasher.ctx.murmur3, (void *)hash);
|
MurmurHash3_x64_128(str_bytes.data, (i32)(str_bytes.count * str_bytes.item_size), hasher.ctx.murmur3, (void *)hash);
|
||||||
|
|
||||||
result = result && mur_hash.value[0] == hash[0] && mur_hash.value[1] == hash[1];
|
result = result && mur_hash.value[0] == hash[0] && mur_hash.value[1] == hash[1];
|
||||||
|
|
||||||
// Array hash
|
// Array hash
|
||||||
mur_hash = hasher.func(&arr_bytes, hasher.ctx);
|
mur_hash = hasher.func(&arr_bytes, hasher.ctx);
|
||||||
MurmurHash3_x64_128(arr_bytes.data, arr_bytes.count * arr_bytes.item_size, hasher.ctx.murmur3, (void *)hash);
|
MurmurHash3_x64_128(arr_bytes.data, (i32)(arr_bytes.count * arr_bytes.item_size), hasher.ctx.murmur3, (void *)hash);
|
||||||
|
|
||||||
result = result && mur_hash.value[0] == hash[0] && mur_hash.value[1] == hash[1];
|
result = result && mur_hash.value[0] == hash[0] && mur_hash.value[1] == hash[1];
|
||||||
|
|
||||||
// Number hash
|
// Number hash
|
||||||
mur_hash = hasher.func(&num_bytes, hasher.ctx);
|
mur_hash = hasher.func(&num_bytes, hasher.ctx);
|
||||||
MurmurHash3_x64_128(num_bytes.data, num_bytes.count * num_bytes.item_size, hasher.ctx.murmur3, (void *)hash);
|
MurmurHash3_x64_128(num_bytes.data, (i32)(num_bytes.count * num_bytes.item_size), hasher.ctx.murmur3, (void *)hash);
|
||||||
|
|
||||||
result = result && mur_hash.value[0] == hash[0] && mur_hash.value[1] == hash[1];
|
result = result && mur_hash.value[0] == hash[0] && mur_hash.value[1] == hash[1];
|
||||||
|
|
||||||
|
|||||||
@@ -22,19 +22,19 @@ WpTestFuncResult test_murmur3(void) {
|
|||||||
|
|
||||||
// Sring hash
|
// Sring hash
|
||||||
WpU128 mur_hash = hasher.func(&str_bytes, hasher.ctx);
|
WpU128 mur_hash = hasher.func(&str_bytes, hasher.ctx);
|
||||||
MurmurHash3_x64_128(str_bytes.data, str_bytes.count * str_bytes.item_size, hasher.ctx.murmur3, (void *)hash);
|
MurmurHash3_x64_128(str_bytes.data, (i32)(str_bytes.count * str_bytes.item_size), hasher.ctx.murmur3, (void *)hash);
|
||||||
|
|
||||||
result = result && mur_hash.value[0] == hash[0] && mur_hash.value[1] == hash[1];
|
result = result && mur_hash.value[0] == hash[0] && mur_hash.value[1] == hash[1];
|
||||||
|
|
||||||
// Array hash
|
// Array hash
|
||||||
mur_hash = hasher.func(&arr_bytes, hasher.ctx);
|
mur_hash = hasher.func(&arr_bytes, hasher.ctx);
|
||||||
MurmurHash3_x64_128(arr_bytes.data, arr_bytes.count * arr_bytes.item_size, hasher.ctx.murmur3, (void *)hash);
|
MurmurHash3_x64_128(arr_bytes.data, (i32)(arr_bytes.count * arr_bytes.item_size), hasher.ctx.murmur3, (void *)hash);
|
||||||
|
|
||||||
result = result && mur_hash.value[0] == hash[0] && mur_hash.value[1] == hash[1];
|
result = result && mur_hash.value[0] == hash[0] && mur_hash.value[1] == hash[1];
|
||||||
|
|
||||||
// Number hash
|
// Number hash
|
||||||
mur_hash = hasher.func(&num_bytes, hasher.ctx);
|
mur_hash = hasher.func(&num_bytes, hasher.ctx);
|
||||||
MurmurHash3_x64_128(num_bytes.data, num_bytes.count * num_bytes.item_size, hasher.ctx.murmur3, (void *)hash);
|
MurmurHash3_x64_128(num_bytes.data, (i32)(num_bytes.count * num_bytes.item_size), hasher.ctx.murmur3, (void *)hash);
|
||||||
|
|
||||||
result = result && mur_hash.value[0] == hash[0] && mur_hash.value[1] == hash[1];
|
result = result && mur_hash.value[0] == hash[0] && mur_hash.value[1] == hash[1];
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
#include "wapp.h"
|
#include "wapp.h"
|
||||||
#include "test_hashmap.h"
|
#include "test_hashmap.h"
|
||||||
|
|
||||||
|
#ifdef WP_PLATFORM_WINDOWS
|
||||||
|
#pragma warning(disable:5045)
|
||||||
|
#endif
|
||||||
|
|
||||||
wp_persist inline WpU8Stream encoder(void *data);
|
wp_persist inline WpU8Stream encoder(void *data);
|
||||||
wp_persist inline b8 key_eq(void *a, void *b);
|
wp_persist inline b8 key_eq(void *a, void *b);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
#include "wapp.h"
|
#include "wapp.h"
|
||||||
#include "test_hashmap.h"
|
#include "test_hashmap.h"
|
||||||
|
|
||||||
|
#ifdef WP_PLATFORM_WINDOWS
|
||||||
|
#pragma warning(disable:5045)
|
||||||
|
#endif
|
||||||
|
|
||||||
wp_persist inline WpU8Stream encoder(void *data);
|
wp_persist inline WpU8Stream encoder(void *data);
|
||||||
wp_persist inline b8 key_eq(void *a, void *b);
|
wp_persist inline b8 key_eq(void *a, void *b);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
#include "wapp.h"
|
#include "wapp.h"
|
||||||
#include "test_hashset.h"
|
#include "test_hashset.h"
|
||||||
|
|
||||||
|
#ifdef WP_PLATFORM_WINDOWS
|
||||||
|
#pragma warning(disable:5045)
|
||||||
|
#endif
|
||||||
|
|
||||||
wp_persist inline WpU8Stream encoder(void *data);
|
wp_persist inline WpU8Stream encoder(void *data);
|
||||||
wp_persist inline b8 key_eq(void *a, void *b);
|
wp_persist inline b8 key_eq(void *a, void *b);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
#include "wapp.h"
|
#include "wapp.h"
|
||||||
#include "test_hashset.h"
|
#include "test_hashset.h"
|
||||||
|
|
||||||
|
#ifdef WP_PLATFORM_WINDOWS
|
||||||
|
#pragma warning(disable:5045)
|
||||||
|
#endif
|
||||||
|
|
||||||
wp_persist inline WpU8Stream encoder(void *data);
|
wp_persist inline WpU8Stream encoder(void *data);
|
||||||
wp_persist inline b8 key_eq(void *a, void *b);
|
wp_persist inline b8 key_eq(void *a, void *b);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user