Change code and naming style, fix several bugs, removed math types.

After a while I felt that putting underscores between words was not the
best solution, so I changed the underscores to capital letters.

Fixed consistency bug between POSIX/Win32 platform in BH_FileOpen.

Removed definitions for math types (vector, matrix, etc.) due to
potential aliasing issues.
This commit is contained in:
2025-01-30 13:53:26 +03:00
parent 8d73a9b473
commit c89cf8f316
22 changed files with 3400 additions and 4135 deletions

View File

@@ -12,7 +12,7 @@
* \param src Pointer to the element
* \param size Element size in bytes
*/
void bh_swap(void *dest,
void BH_Swap(void *dest,
void *src,
size_t size);
@@ -30,11 +30,11 @@ void bh_swap(void *dest,
*
* \return Pointer to the first element of the second partition.
*/
void *bh_partition(void *pivot,
void *BH_Partition(void *pivot,
void *array,
size_t size,
size_t element,
bh_equal_cb_t equal);
BH_EqualCallback equal);
/**
@@ -45,10 +45,10 @@ void *bh_partition(void *pivot,
* \param element Element size in bytes
* \param equal Comparision function
*/
void bh_sort(void *array,
void BH_Sort(void *array,
size_t size,
size_t element,
bh_equal_cb_t equal);
BH_EqualCallback equal);
/**
@@ -59,10 +59,10 @@ void bh_sort(void *array,
* \param element Element size in bytes
* \param equal Comparision function
*/
void bh_heap_make(void *array,
size_t size,
size_t element,
bh_equal_cb_t equal);
void BH_HeapMake(void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
/**
@@ -73,10 +73,10 @@ void bh_heap_make(void *array,
* \param element Element size in bytes
* \param equal Comparasion function
*/
void bh_heap_remove(void *array,
size_t size,
size_t element,
bh_equal_cb_t equal);
void BH_HeapRemove(void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
/**
@@ -91,11 +91,11 @@ void bh_heap_remove(void *array,
* \param element Element size in bytes
* \param equal Comparasion function
*/
void bh_heap_insert(void *value,
void *array,
size_t size,
size_t element,
bh_equal_cb_t equal);
void BH_HeapInsert(void *value,
void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
/**
@@ -106,8 +106,8 @@ void bh_heap_insert(void *value,
*
* This function is roughly equivalent to the following code:
* \code
* bh_heap_remove(array, size, element, equal);
* bh_heap_insert(value, array, size - 1, element, equal);
* BH_HeapRemove(array, size, element, equal);
* BH_HeapInsert(value, array, size - 1, element, equal);
* \endcode
*
* \param value Pointer to the value
@@ -116,11 +116,11 @@ void bh_heap_insert(void *value,
* \param element Element size in bytes
* \param equal Comparasion function
*/
void bh_heap_replace(void *value,
void *array,
size_t size,
size_t element,
bh_equal_cb_t equal);
void BH_HeapReplace(void *value,
void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
#endif /* BH_ALGO_H */

View File

@@ -17,8 +17,9 @@
#define BH_PTR2INT(x) ((intptr_t)(x))
#define BH_INT2PTR(x) ((void*)(x))
typedef int (*bh_equal_cb_t)(const void *, const void *);
typedef size_t (*bh_hash_cb_t)(const void *);
typedef int (*BH_EqualCallback)(const void *, const void *);
typedef size_t (*BH_HashCallback)(const void *);
#endif /* BH_COMMON_H */

View File

@@ -5,7 +5,7 @@
#include "common.h"
typedef struct bh_hashmap_s bh_hashmap_t;
typedef struct BH_Hashmap BH_Hashmap;
/**
@@ -17,8 +17,8 @@ typedef struct bh_hashmap_s bh_hashmap_t;
* \return On success, returns hashmap handle.
* \return On failure, returns a null pointer.
*/
bh_hashmap_t *bh_hashmap_new(bh_equal_cb_t equal,
bh_hash_cb_t hash);
BH_Hashmap *BH_HashmapNew(BH_EqualCallback equal,
BH_HashCallback hash);
/**
@@ -26,7 +26,7 @@ bh_hashmap_t *bh_hashmap_new(bh_equal_cb_t equal,
*
* \param hashmap Hashmap handle
*/
void bh_hashmap_free(bh_hashmap_t *hashmap);
void BH_HashmapFree(BH_Hashmap *hashmap);
/**
@@ -34,7 +34,7 @@ void bh_hashmap_free(bh_hashmap_t *hashmap);
*
* \param hashmap Hashmap handle
*/
void bh_hashmap_clear(bh_hashmap_t *hashmap);
void BH_HashmapClear(BH_Hashmap *hashmap);
/**
@@ -52,8 +52,8 @@ void bh_hashmap_clear(bh_hashmap_t *hashmap);
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_hashmap_reserve(bh_hashmap_t *hashmap,
size_t size);
int BH_HashmapReserve(BH_Hashmap *hashmap,
size_t size);
/**
@@ -69,9 +69,9 @@ int bh_hashmap_reserve(bh_hashmap_t *hashmap,
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_hashmap_insert(bh_hashmap_t *hashmap,
void *key,
void *value);
int BH_HashmapInsert(BH_Hashmap *hashmap,
void *key,
void *value);
/**
@@ -84,8 +84,8 @@ int bh_hashmap_insert(bh_hashmap_t *hashmap,
* \note If hashmap contains several elements with the same key, this function
* will remove only one key-value pair.
*/
void bh_hashmap_remove(bh_hashmap_t *hashmap,
void *key);
void BH_HashmapRemove(BH_Hashmap *hashmap,
void *key);
/**
@@ -98,9 +98,9 @@ void bh_hashmap_remove(bh_hashmap_t *hashmap,
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_hashmap_at(bh_hashmap_t *hashmap,
void *key,
void **value);
int BH_HashmapAt(BH_Hashmap *hashmap,
void *key,
void **value);
/**
@@ -111,7 +111,7 @@ int bh_hashmap_at(bh_hashmap_t *hashmap,
* \return If hashmap is empty, returns non-zero value
* \return If hashmap is not empty, returns zero value
*/
int bh_hashmap_empty(bh_hashmap_t *hashmap);
int BH_HashmapEmpty(BH_Hashmap *hashmap);
/**
@@ -121,7 +121,7 @@ int bh_hashmap_empty(bh_hashmap_t *hashmap);
*
* \return Returns the size of the hashmap.
*/
size_t bh_hashmap_size(bh_hashmap_t *hashmap);
size_t BH_HashmapSize(BH_Hashmap *hashmap);
/**
@@ -131,7 +131,7 @@ size_t bh_hashmap_size(bh_hashmap_t *hashmap);
*
* \return Returns the capacity of the hashmap.
*/
size_t bh_hashmap_capacity(bh_hashmap_t *hashmap);
size_t BH_HashmapCapacity(BH_Hashmap *hashmap);
/**
@@ -141,7 +141,7 @@ size_t bh_hashmap_capacity(bh_hashmap_t *hashmap);
*
* \return Returns the load factor of the hashmap.
*/
float bh_hashmap_factor(bh_hashmap_t *hashmap);
float BH_HashmapFactor(BH_Hashmap *hashmap);
/**
@@ -152,8 +152,8 @@ float bh_hashmap_factor(bh_hashmap_t *hashmap);
*
* \note New load factor will be applied on the next reserve/insert operation.
*/
void bh_hashmap_set_factor(bh_hashmap_t *hashmap,
float factor);
void BH_HashmapSetFactor(BH_Hashmap *hashmap,
float factor);
/**
@@ -168,8 +168,8 @@ void bh_hashmap_set_factor(bh_hashmap_t *hashmap,
* \note If hashmap contains several elements with the same key, this function
* will return iterator to one of them
*/
void *bh_hashmap_iter_at(bh_hashmap_t *hashmap,
void *key);
void *BH_HashmapIterAt(BH_Hashmap *hashmap,
void *key);
/**
@@ -184,8 +184,8 @@ void *bh_hashmap_iter_at(bh_hashmap_t *hashmap,
* \return On success, returns new iterator value for the next element.
* \return On failure, returns NULL pointer.
*/
void *bh_hashmap_iter_next(bh_hashmap_t *hashmap,
void *iter);
void *BH_HashmapIterNext(BH_Hashmap *hashmap,
void *iter);
/**
@@ -196,8 +196,8 @@ void *bh_hashmap_iter_next(bh_hashmap_t *hashmap,
*
* \note Calling this function will invalidate iterators.
*/
void bh_hashmap_iter_remove(bh_hashmap_t *hashmap,
void *iter);
void BH_HashmapIterRemove(BH_Hashmap *hashmap,
void *iter);
/**
@@ -207,7 +207,7 @@ void bh_hashmap_iter_remove(bh_hashmap_t *hashmap,
*
* \return Returns key.
*/
void *bh_hashmap_iter_key(void *iter);
void *BH_HashmapIterKey(void *iter);
/**
@@ -217,7 +217,7 @@ void *bh_hashmap_iter_key(void *iter);
*
* \return Returns value.
*/
void *bh_hashmap_iter_value(void *iter);
void *BH_HashmapIterValue(void *iter);
#endif /* BH_HASHMAP_H */

View File

@@ -40,10 +40,11 @@
#define BH_IO_FLAG_EOF 0x0002
#define BH_IO_FLAG_OPEN 0x0004
#define BH_FILE_CLASSNAME "bh_file"
#define BH_FILE_CLASSNAME "BH_File"
typedef struct bh_io_s bh_io_t;
typedef int (*bh_io_func_t)(void *, int, void *, void *);
typedef struct BH_IO BH_IO;
typedef int (*BH_IOCallback)(void *, int ,void *, void *);
/**
@@ -54,7 +55,7 @@ typedef int (*bh_io_func_t)(void *, int, void *, void *);
* \return On success, returns IO handle.
* \return On failure, returns NULL pointer.
*/
bh_io_t *bh_file_new(const char *path);
BH_IO *BH_FileNew(const char *path);
/**
@@ -65,7 +66,7 @@ bh_io_t *bh_file_new(const char *path);
* \return On success, returns IO handle.
* \return On failure, returns NULL pointer.
*/
bh_io_t *bh_buffer_new(bh_io_t *io);
BH_IO *BH_BufferNew(BH_IO *io);
/**
@@ -77,8 +78,8 @@ bh_io_t *bh_buffer_new(bh_io_t *io);
* \return On success, returns IO handle.
* \return On failure, returns NULL pointer.
*/
bh_io_t *bh_io_new(bh_io_func_t func,
void *data);
BH_IO *BH_IONew(BH_IOCallback cb,
void *data);
/**
@@ -86,7 +87,7 @@ bh_io_t *bh_io_new(bh_io_func_t func,
*
* \param io IO handle
*/
void bh_io_free(bh_io_t *io);
void BH_IOFree(BH_IO *io);
/**
@@ -97,7 +98,7 @@ void bh_io_free(bh_io_t *io);
* \return On success, returns pointer to constant string.
* \return On failure, returns NULL pointer
*/
const char *bh_io_classname(bh_io_t *io);
const char *BH_IOClassname(BH_IO* io);
/**
@@ -109,8 +110,8 @@ const char *bh_io_classname(bh_io_t *io);
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_io_open(bh_io_t *io,
int mode);
int BH_IOOpen(BH_IO *io,
int mode);
/**
@@ -121,7 +122,7 @@ int bh_io_open(bh_io_t *io,
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_io_close(bh_io_t *io);
int BH_IOClose(BH_IO *io);
/**
@@ -135,10 +136,10 @@ int bh_io_close(bh_io_t *io);
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_io_read(bh_io_t *io,
char *buffer,
size_t size,
size_t *actual);
int BH_IORead(BH_IO *io,
char *buffer,
size_t size,
size_t *actual);
/**
@@ -152,10 +153,10 @@ int bh_io_read(bh_io_t *io,
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_io_write(bh_io_t *io,
const char *buffer,
size_t size,
size_t *actual);
int BH_IOWrite(BH_IO *io,
const char *buffer,
size_t size,
size_t *actual);
/**
@@ -169,10 +170,10 @@ int bh_io_write(bh_io_t *io,
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_io_peek(bh_io_t *io,
char *buffer,
size_t size,
size_t *actual);
int BH_IOPeek(BH_IO *io,
char *buffer,
size_t size,
size_t *actual);
/**
@@ -184,8 +185,8 @@ int bh_io_peek(bh_io_t *io,
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_io_tell(bh_io_t *io,
int64_t *position);
int BH_IOTell(BH_IO *io,
int64_t *position);
/**
@@ -198,9 +199,9 @@ int bh_io_tell(bh_io_t *io,
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_io_seek(bh_io_t *io,
int64_t position,
int direction);
int BH_IOSeek(BH_IO *io,
int64_t position,
int direction);
/**
@@ -211,7 +212,7 @@ int bh_io_seek(bh_io_t *io,
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_io_flush(bh_io_t *io);
int BH_IOFlush(BH_IO *io);
/**
@@ -223,8 +224,8 @@ int bh_io_flush(bh_io_t *io);
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_io_size(bh_io_t *io,
int64_t *size);
int BH_IOSize(BH_IO *io,
int64_t *size);
/**
@@ -234,7 +235,7 @@ int bh_io_size(bh_io_t *io,
*
* \return Flags of the IO
*/
int bh_io_flags(bh_io_t *io);
int BH_IOFlags(BH_IO *io);
/**
@@ -245,7 +246,7 @@ int bh_io_flags(bh_io_t *io);
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_io_clear(bh_io_t *io);
int BH_IOClear(BH_IO *io);
#endif /* BH_IO_H */

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,7 @@
#include "common.h"
typedef struct bh_queue_s bh_queue_t;
typedef struct BH_Queue BH_Queue;
/**
@@ -14,7 +14,7 @@ typedef struct bh_queue_s bh_queue_t;
* \return On success, returns the pointer to the new queue object.
* \return On failure, returns a null pointer.
*/
bh_queue_t *bh_queue_new(void);
BH_Queue *BH_QueueNew(void);
/**
@@ -22,7 +22,7 @@ bh_queue_t *bh_queue_new(void);
*
* \param queue Pointer to the queue object to be freed
*/
void bh_queue_free(bh_queue_t *queue);
void BH_QueueFree(BH_Queue *queue);
/**
@@ -30,7 +30,7 @@ void bh_queue_free(bh_queue_t *queue);
*
* \param queue Pointer to the queue object to be cleared
*/
void bh_queue_clear(bh_queue_t *queue);
void BH_QueueClear(BH_Queue *queue);
/**
@@ -47,8 +47,8 @@ void bh_queue_clear(bh_queue_t *queue);
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_queue_reserve(bh_queue_t *queue,
size_t size);
int BH_QueueReserve(BH_Queue *queue,
size_t size);
/**
@@ -62,8 +62,8 @@ int bh_queue_reserve(bh_queue_t *queue,
* \return On success, returns zero value.
* \return On failure, returns error code.
*/
int bh_queue_insert(bh_queue_t *queue,
void *value);
int BH_QueueInsert(BH_Queue *queue,
void *value);
/**
@@ -73,7 +73,7 @@ int bh_queue_insert(bh_queue_t *queue,
*
* \note Calling this function will invalidate iterators.
*/
void bh_queue_remove(bh_queue_t *queue);
void BH_QueueRemove(BH_Queue *queue);
/**
@@ -84,8 +84,8 @@ void bh_queue_remove(bh_queue_t *queue);
* \return On success, returns front value from the queue.
* \return On failure, returns null pointer.
*/
int bh_queue_front(bh_queue_t *queue,
void **value);
int BH_QueueFront(BH_Queue *queue,
void **value);
/**
@@ -96,7 +96,7 @@ int bh_queue_front(bh_queue_t *queue,
* \return If queue is empty, returns non-zero value
* \return If queue is not empty, returns zero value
*/
int bh_queue_empty(bh_queue_t *queue);
int BH_QueueEmpty(BH_Queue *queue);
/**
@@ -106,7 +106,7 @@ int bh_queue_empty(bh_queue_t *queue);
*
* \return Returns the size of the queue.
*/
size_t bh_queue_size(bh_queue_t *queue);
size_t BH_QueueSize(BH_Queue *queue);
/**
@@ -116,7 +116,7 @@ size_t bh_queue_size(bh_queue_t *queue);
*
* \return Returns the capacity of the queue.
*/
size_t bh_queue_capacity(bh_queue_t *queue);
size_t BH_QueueCapacity(BH_Queue *queue);
/**
@@ -132,8 +132,8 @@ size_t bh_queue_capacity(bh_queue_t *queue);
* \return If the \a iter is the null pointer, returns iterator to the
* first element of the queue.
*/
void *bh_queue_iter_next(bh_queue_t *queue,
void *iter);
void *BH_QueueIterNext(BH_Queue *queue,
void *iter);
/**
@@ -143,7 +143,7 @@ void *bh_queue_iter_next(bh_queue_t *queue,
*
* \return Returns value, pointed by iterator.
*/
void *bh_queue_iter_value(void *iter);
void *BH_QueueIterValue(void *iter);
#endif /* BH_QUEUE_H */