Initial commit
This commit is contained in:
126
include/bh/algo.h
Executable file
126
include/bh/algo.h
Executable file
@@ -0,0 +1,126 @@
|
||||
#ifndef BH_ALGO_H
|
||||
#define BH_ALGO_H
|
||||
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
/**
|
||||
* Exchanges the values of two elements.
|
||||
*
|
||||
* \param dest Pointer to the element
|
||||
* \param src Pointer to the element
|
||||
* \param size Element size in bytes
|
||||
*/
|
||||
void bh_swap(void *dest,
|
||||
void *src,
|
||||
size_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Partitions the array relative to the specified pivot element.
|
||||
*
|
||||
* The pivot element can be part of the partitioned array.
|
||||
*
|
||||
* \param pivot Pointer to the pivot element
|
||||
* \param array Pointer to the array
|
||||
* \param size Array size
|
||||
* \param element Element size in bytes
|
||||
* \param equal Comparision function
|
||||
*
|
||||
* \return Pointer to the first element of the second partition.
|
||||
*/
|
||||
void *bh_partition(void *pivot,
|
||||
void *array,
|
||||
size_t size,
|
||||
size_t element,
|
||||
bh_equal_cb_t equal);
|
||||
|
||||
|
||||
/**
|
||||
* Sorts the array.
|
||||
*
|
||||
* \param array Pointer to the array
|
||||
* \param size Array size
|
||||
* \param element Element size in bytes
|
||||
* \param equal Comparision function
|
||||
*/
|
||||
void bh_sort(void *array,
|
||||
size_t size,
|
||||
size_t element,
|
||||
bh_equal_cb_t equal);
|
||||
|
||||
|
||||
/**
|
||||
* Makes heap in an array from the array.
|
||||
*
|
||||
* \param array Pointer to the array
|
||||
* \param size Array size
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Removes top/first element from a heap in an array.
|
||||
*
|
||||
* \param array Pointer to the array
|
||||
* \param size Array size
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Inserts new element into heap in an array.
|
||||
*
|
||||
* If the pointer to value is NULL, this function assumes that the new value
|
||||
* is at the end of the array.
|
||||
*
|
||||
* \param value Pointer to the value
|
||||
* \param array Pointer to the array
|
||||
* \param size Array size
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Removes top/first element and inserts new element into heap in an array.
|
||||
*
|
||||
* If the pointer to value is NULL, this function assumes that the new value
|
||||
* is at the end of the array.
|
||||
*
|
||||
* 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);
|
||||
* \endcode
|
||||
*
|
||||
* \param value Pointer to the value
|
||||
* \param array Pointer to the array
|
||||
* \param size Array size
|
||||
* \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);
|
||||
|
||||
|
||||
#endif /* BH_ALGO_H */
|
||||
24
include/bh/common.h
Normal file
24
include/bh/common.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef BH_COMMON_H
|
||||
#define BH_COMMON_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define BH_OK 0x0000
|
||||
#define BH_ERROR 0x0001
|
||||
#define BH_NOIMPL 0x0002
|
||||
#define BH_OOM 0x0003
|
||||
#define BH_INVALID 0x0004
|
||||
#define BH_FOUND 0x0005
|
||||
#define BH_NOTFOUND 0x0006
|
||||
#define BH_TIMEOUT 0x0007
|
||||
|
||||
#define BH_UNUSED(x) (void)(x)
|
||||
#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 *);
|
||||
|
||||
#endif /* BH_COMMON_H */
|
||||
|
||||
223
include/bh/hashmap.h
Executable file
223
include/bh/hashmap.h
Executable file
@@ -0,0 +1,223 @@
|
||||
#ifndef BH_HASHMAP_H
|
||||
#define BH_HASHMAP_H
|
||||
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
typedef struct bh_hashmap_s bh_hashmap_t;
|
||||
|
||||
|
||||
/**
|
||||
* Creates the new hashmap handle.
|
||||
*
|
||||
* \param equal Comparision function
|
||||
* \param hash Key hash function
|
||||
*
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Destroys the hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap handle
|
||||
*/
|
||||
void bh_hashmap_free(bh_hashmap_t *hashmap);
|
||||
|
||||
|
||||
/**
|
||||
* Clears the hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap handle
|
||||
*/
|
||||
void bh_hashmap_clear(bh_hashmap_t *hashmap);
|
||||
|
||||
|
||||
/**
|
||||
* Reserves space in the hashmap.
|
||||
*
|
||||
* This function can both expand and shrink the available space in hashmap.
|
||||
* This function takes into account current hashmap load factor.
|
||||
*
|
||||
* \param hashmap Hahsmap handle
|
||||
* \param size Capacity
|
||||
*
|
||||
* \note Calling this function will invalidate iterators.
|
||||
* \note Actual hashmap capacity can be bigger then requested.
|
||||
*
|
||||
* \return On success, returns zero value.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int bh_hashmap_reserve(bh_hashmap_t *hashmap,
|
||||
size_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Inserts the pair of key-value into the hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap handle
|
||||
* \param key Key
|
||||
* \param value Value
|
||||
*
|
||||
* \note This function allows duplicates to be inserted.
|
||||
* \note Calling this function will invalidate iterators.
|
||||
*
|
||||
* \return On success, returns zero value.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int bh_hashmap_insert(bh_hashmap_t *hashmap,
|
||||
void *key,
|
||||
void *value);
|
||||
|
||||
|
||||
/**
|
||||
* Removes value from the hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap handle
|
||||
* \param key Key
|
||||
*
|
||||
* \note Calling this function will invalidate iterators.
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Returns value from the hashmap by key.
|
||||
*
|
||||
* \param hashmap Hashmap handle
|
||||
* \param key Key
|
||||
* \param value Value (optional)
|
||||
*
|
||||
* \return On success, returns zero value.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int bh_hashmap_at(bh_hashmap_t *hashmap,
|
||||
void *key,
|
||||
void **value);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the hashmap is empty.
|
||||
*
|
||||
* \param hashmap Hashmap handle
|
||||
*
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the size of the hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap handle
|
||||
*
|
||||
* \return Returns the size of the hashmap.
|
||||
*/
|
||||
size_t bh_hashmap_size(bh_hashmap_t *hashmap);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the capacity of the hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap handle
|
||||
*
|
||||
* \return Returns the capacity of the hashmap.
|
||||
*/
|
||||
size_t bh_hashmap_capacity(bh_hashmap_t *hashmap);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the load factor of the hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap handle
|
||||
*
|
||||
* \return Returns the load factor of the hashmap.
|
||||
*/
|
||||
float bh_hashmap_factor(bh_hashmap_t *hashmap);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the load factor of the hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap handle
|
||||
* \param factor Load factor
|
||||
*
|
||||
* \note New load factor will be applied on the next reserve/insert operation.
|
||||
*/
|
||||
void bh_hashmap_set_factor(bh_hashmap_t *hashmap,
|
||||
float factor);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the iterator to the element in the hashmap with specified key.
|
||||
*
|
||||
* \param hashmap Hashmap handle
|
||||
* \param iter Iterator
|
||||
*
|
||||
* \return On success, returns iterator value.
|
||||
* \return On failure, returns NULL pointer.
|
||||
*
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the iterator to the next element in the hashmap.
|
||||
*
|
||||
* If the iterator is NULL pointer, this function will return iterator to the
|
||||
* first element of the hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap handle
|
||||
* \param iter Iterator
|
||||
*
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Removes value from the hashmap pointed by by iterator.
|
||||
*
|
||||
* \param hashmap Hashmap handle
|
||||
* \param iter Iterator
|
||||
*
|
||||
* \note Calling this function will invalidate iterators.
|
||||
*/
|
||||
void bh_hashmap_iter_remove(bh_hashmap_t *hashmap,
|
||||
void *iter);
|
||||
|
||||
|
||||
/**
|
||||
* Returns key, pointed by the iterator.
|
||||
*
|
||||
* \param iter Iterator
|
||||
*
|
||||
* \return Returns key.
|
||||
*/
|
||||
void *bh_hashmap_iter_key(void *iter);
|
||||
|
||||
|
||||
/**
|
||||
* Returns value, pointed by the iterator.
|
||||
*
|
||||
* \param iter Iterator
|
||||
*
|
||||
* \return Returns value.
|
||||
*/
|
||||
void *bh_hashmap_iter_value(void *iter);
|
||||
|
||||
|
||||
#endif /* BH_HASHMAP_H */
|
||||
251
include/bh/io.h
Normal file
251
include/bh/io.h
Normal file
@@ -0,0 +1,251 @@
|
||||
#ifndef BH_IO_H
|
||||
#define BH_IO_H
|
||||
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
#define BH_IO_INFO_CB 0x0000
|
||||
#define BH_IO_INIT_CB 0x0001
|
||||
#define BH_IO_DESTROY_CB 0x0002
|
||||
#define BH_IO_OPEN_CB 0x0003
|
||||
#define BH_IO_CLOSE_CB 0x0004
|
||||
#define BH_IO_READ_CB 0x0005
|
||||
#define BH_IO_WRITE_CB 0x0006
|
||||
#define BH_IO_PEEK_CB 0x0007
|
||||
#define BH_IO_TELL_CB 0x0008
|
||||
#define BH_IO_SEEK_CB 0x0009
|
||||
#define BH_IO_FLUSH_CB 0x000A
|
||||
#define BH_IO_SIZE_CB 0x000B
|
||||
#define BH_IO_FLAGS_CB 0x000C
|
||||
#define BH_IO_CLEAR_CB 0x000D
|
||||
|
||||
|
||||
#define BH_IO_READ 0x0001
|
||||
#define BH_IO_WRITE 0x0002
|
||||
#define BH_IO_READWRITE 0x0003
|
||||
#define BH_IO_APPEND 0x0010
|
||||
#define BH_IO_TRUNCATE 0x0020
|
||||
#define BH_IO_CREATE 0x0040
|
||||
#define BH_IO_EXIST 0x0080
|
||||
|
||||
|
||||
#define BH_IO_SEEK_SET 0x0000
|
||||
#define BH_IO_SEEK_CUR 0x0001
|
||||
#define BH_IO_SEEK_END 0x0002
|
||||
|
||||
|
||||
#define BH_IO_FLAG_OK 0x0000
|
||||
#define BH_IO_FLAG_ERROR 0x0001
|
||||
#define BH_IO_FLAG_EOF 0x0002
|
||||
#define BH_IO_FLAG_OPEN 0x0004
|
||||
|
||||
#define BH_FILE_CLASSNAME "bh_file"
|
||||
|
||||
typedef struct bh_io_s bh_io_t;
|
||||
typedef int (*bh_io_func_t)(void *, int, void *, void *);
|
||||
|
||||
|
||||
/**
|
||||
* Creates the IO handle that represents file.
|
||||
*
|
||||
* \param path Path to the file
|
||||
*
|
||||
* \return On success, returns IO handle.
|
||||
* \return On failure, returns NULL pointer.
|
||||
*/
|
||||
bh_io_t *bh_file_new(const char *path);
|
||||
|
||||
|
||||
/**
|
||||
* Creates the IO handle that represents buffered IO.
|
||||
*
|
||||
* \param io IO handle
|
||||
*
|
||||
* \return On success, returns IO handle.
|
||||
* \return On failure, returns NULL pointer.
|
||||
*/
|
||||
bh_io_t *bh_buffer_new(bh_io_t *io);
|
||||
|
||||
|
||||
/**
|
||||
* Creates the IO handle with specified handler and context.
|
||||
*
|
||||
* \param func IO actions handler
|
||||
* \param data Initialization data
|
||||
*
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Destroys the IO.
|
||||
*
|
||||
* \param io IO handle
|
||||
*/
|
||||
void bh_io_free(bh_io_t *io);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the IO instance classname.
|
||||
*
|
||||
* \param io IO handle
|
||||
*
|
||||
* \return On success, returns pointer to constant string.
|
||||
* \return On failure, returns NULL pointer
|
||||
*/
|
||||
const char *bh_io_classname(bh_io_t *io);
|
||||
|
||||
|
||||
/**
|
||||
* Opens the IO in specified mode of operation.
|
||||
*
|
||||
* \param io IO handle
|
||||
* \param mode Mode of operation
|
||||
*
|
||||
* \return On success, returns zero value.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int bh_io_open(bh_io_t *io,
|
||||
int mode);
|
||||
|
||||
|
||||
/**
|
||||
* Closes the IO.
|
||||
*
|
||||
* \param io IO handle
|
||||
*
|
||||
* \return On success, returns zero value.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int bh_io_close(bh_io_t *io);
|
||||
|
||||
|
||||
/**
|
||||
* Reads up to specified amount of bytes from the IO into memory buffer.
|
||||
*
|
||||
* \param io IO handle
|
||||
* \param buffer Pointer to the buffer
|
||||
* \param size Bytes to read
|
||||
* \param actual Bytes read
|
||||
*
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Writes up to specified amount of bytes into the IO from the memory buffer.
|
||||
*
|
||||
* \param io IO handle
|
||||
* \param buffer Pointer to the buffer
|
||||
* \param size Bytes to write
|
||||
* \param actual Bytes written
|
||||
*
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Peeks up to specified amount of bytes from the IO handle.
|
||||
*
|
||||
* \param io IO handle
|
||||
* \param buffer Pointer to the buffer
|
||||
* \param size Bytes to peek
|
||||
* \param actial Bytes peeked
|
||||
*
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Tells current offset in the IO.
|
||||
*
|
||||
* \param io IO handle
|
||||
* \param position Offset
|
||||
*
|
||||
* \return On success, returns zero value.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int bh_io_tell(bh_io_t *io,
|
||||
int64_t *position);
|
||||
|
||||
|
||||
/**
|
||||
* Seeks to specified offset in the IO.
|
||||
*
|
||||
* \param io IO handle
|
||||
* \param position Offset
|
||||
* \param direction Direction
|
||||
*
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Flushes the internal buffers of the IO.
|
||||
*
|
||||
* \param io IO handle
|
||||
*
|
||||
* \return On success, returns zero value.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int bh_io_flush(bh_io_t *io);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the size of the IO (either total or available size).
|
||||
*
|
||||
* \param io IO handle
|
||||
* \param size Available/total size
|
||||
*
|
||||
* \return On success, returns zero value.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int bh_io_size(bh_io_t *io,
|
||||
int64_t *size);
|
||||
|
||||
|
||||
/**
|
||||
* Returns flags of the IO.
|
||||
*
|
||||
* \param io IO handle
|
||||
*
|
||||
* \return Flags of the IO
|
||||
*/
|
||||
int bh_io_flags(bh_io_t *io);
|
||||
|
||||
|
||||
/**
|
||||
* Clears errors of the IO.
|
||||
*
|
||||
* \param io IO handle
|
||||
*
|
||||
* \return On success, returns zero value.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int bh_io_clear(bh_io_t *io);
|
||||
|
||||
|
||||
#endif /* BH_IO_H */
|
||||
715
include/bh/math.h
Normal file
715
include/bh/math.h
Normal file
@@ -0,0 +1,715 @@
|
||||
#ifndef BH_MATH_H
|
||||
#define BH_MATH_H
|
||||
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
typedef struct bh_point2f_s
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
} bh_point2f_t;
|
||||
|
||||
|
||||
typedef struct bh_point3f_s
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
} bh_point3f_t;
|
||||
|
||||
|
||||
typedef struct bh_point4f_s
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
} bh_point4f_t;
|
||||
|
||||
|
||||
typedef struct bh_point2i_s
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} bh_point2i_t;
|
||||
|
||||
|
||||
typedef struct bh_point3i_s
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
} bh_point3i_t;
|
||||
|
||||
|
||||
typedef struct bh_point4i_s
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
int w;
|
||||
} bh_point4i_t;
|
||||
|
||||
|
||||
typedef struct bh_matrix3f_s
|
||||
{
|
||||
bh_point3f_t x;
|
||||
bh_point3f_t y;
|
||||
bh_point3f_t z;
|
||||
} bh_matrix3f_t;
|
||||
|
||||
|
||||
typedef struct bh_matrix4f_s
|
||||
{
|
||||
bh_point4f_t x;
|
||||
bh_point4f_t y;
|
||||
bh_point4f_t z;
|
||||
bh_point4f_t w;
|
||||
} bh_matrix4f_t;
|
||||
|
||||
|
||||
typedef struct bh_line2f_s
|
||||
{
|
||||
bh_point2f_t normal;
|
||||
float distance;
|
||||
} bh_line2f_t;
|
||||
|
||||
|
||||
typedef struct bh_plane3f_s
|
||||
{
|
||||
bh_point3f_t normal;
|
||||
float distance;
|
||||
} bh_plane3f_t;
|
||||
|
||||
|
||||
typedef struct bh_ray2f_s
|
||||
{
|
||||
bh_point2f_t origin;
|
||||
bh_point2f_t normal;
|
||||
} bh_ray2f_t;
|
||||
|
||||
|
||||
typedef struct bh_ray3f_s
|
||||
{
|
||||
bh_point3f_t origin;
|
||||
bh_point3f_t normal;
|
||||
} bh_ray3f_t;
|
||||
|
||||
|
||||
typedef struct bh_aabb2f_s
|
||||
{
|
||||
bh_point2f_t origin;
|
||||
bh_point2f_t size;
|
||||
} bh_aabb2f_t;
|
||||
|
||||
|
||||
typedef struct bh_aabb3f_s
|
||||
{
|
||||
bh_point3f_t origin;
|
||||
bh_point3f_t size;
|
||||
} bh_aabb3f_t;
|
||||
|
||||
|
||||
typedef struct bh_aabb2i_s
|
||||
{
|
||||
bh_point2i_t origin;
|
||||
bh_point2i_t size;
|
||||
} bh_aabb2i_t;
|
||||
|
||||
|
||||
typedef struct bh_aabb3i_s
|
||||
{
|
||||
bh_point3i_t origin;
|
||||
bh_point3i_t size;
|
||||
} bh_aabb3i_t;
|
||||
|
||||
|
||||
typedef bh_point4f_t bh_quat_t;
|
||||
|
||||
|
||||
bh_point4f_t *bh_point4f_add(const bh_point4f_t *a,
|
||||
const bh_point4f_t *b,
|
||||
bh_point4f_t *result);
|
||||
|
||||
|
||||
bh_point4f_t *bh_point4f_sub(const bh_point4f_t *a,
|
||||
const bh_point4f_t *b,
|
||||
bh_point4f_t *result);
|
||||
|
||||
|
||||
bh_point4f_t *bh_point4f_mul(const bh_point4f_t *a,
|
||||
const bh_point4f_t *b,
|
||||
bh_point4f_t *result);
|
||||
|
||||
|
||||
bh_point4f_t *bh_point4f_scale(const bh_point4f_t *a,
|
||||
float b,
|
||||
bh_point4f_t *result);
|
||||
|
||||
|
||||
bh_point4f_t *bh_point4f_madd(const bh_point4f_t *a,
|
||||
const bh_point4f_t *b,
|
||||
const bh_point4f_t *c,
|
||||
bh_point4f_t *result);
|
||||
|
||||
|
||||
bh_point4f_t *bh_point4f_negate(const bh_point4f_t *in,
|
||||
bh_point4f_t *result);
|
||||
|
||||
|
||||
float bh_point4f_dot(const bh_point4f_t *a,
|
||||
const bh_point4f_t *b);
|
||||
|
||||
|
||||
float bh_point4f_dot3(const bh_point4f_t *a,
|
||||
const bh_point4f_t *b);
|
||||
|
||||
|
||||
bh_point4f_t *bh_point4f_cross(const bh_point4f_t *a,
|
||||
const bh_point4f_t *b,
|
||||
bh_point4f_t *result);
|
||||
|
||||
|
||||
float bh_point4f_length(const bh_point4f_t *in);
|
||||
|
||||
|
||||
bh_point4f_t *bh_point4f_normal(const bh_point4f_t *in,
|
||||
bh_point4f_t *result);
|
||||
|
||||
|
||||
bh_point4f_t *bh_point4f_min(const bh_point4f_t *a,
|
||||
const bh_point4f_t *b,
|
||||
bh_point4f_t *result);
|
||||
|
||||
|
||||
bh_point4f_t *bh_point4f_max(const bh_point4f_t *a,
|
||||
const bh_point4f_t *b,
|
||||
bh_point4f_t *result);
|
||||
|
||||
|
||||
bh_point4f_t *bh_point4f_lerp(const bh_point4f_t *a,
|
||||
const bh_point4f_t *b,
|
||||
float t,
|
||||
bh_point4f_t *result);
|
||||
|
||||
|
||||
bh_point4f_t *bh_point4f_slerp(const bh_point4f_t *a,
|
||||
const bh_point4f_t *b,
|
||||
float t,
|
||||
bh_point4f_t *result);
|
||||
|
||||
|
||||
bh_point3f_t *bh_point3f_add(const bh_point3f_t *a,
|
||||
const bh_point3f_t *b,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
bh_point3f_t *bh_point3f_sub(const bh_point3f_t *a,
|
||||
const bh_point3f_t *b,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
bh_point3f_t *bh_point3f_mul(const bh_point3f_t *a,
|
||||
const bh_point3f_t *b,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
bh_point3f_t *bh_point3f_scale(const bh_point3f_t *a,
|
||||
float b,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
bh_point3f_t *bh_point3f_madd(const bh_point3f_t *a,
|
||||
const bh_point3f_t *b,
|
||||
const bh_point3f_t *c,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
bh_point3f_t *bh_point3f_negate(const bh_point3f_t *in,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
float bh_point3f_dot(const bh_point3f_t *a,
|
||||
const bh_point3f_t *b);
|
||||
|
||||
|
||||
bh_point3f_t *bh_point3f_cross(const bh_point3f_t *a,
|
||||
const bh_point3f_t *b,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
float bh_point3f_length(const bh_point3f_t *in);
|
||||
|
||||
|
||||
bh_point3f_t *bh_point3f_normal(const bh_point3f_t *in,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
bh_point3f_t *bh_point3f_min(const bh_point3f_t *a,
|
||||
const bh_point3f_t *b,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
bh_point3f_t *bh_point3f_max(const bh_point3f_t *a,
|
||||
const bh_point3f_t *b,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
bh_point3f_t *bh_point3f_lerp(const bh_point3f_t *a,
|
||||
const bh_point3f_t *b,
|
||||
float t,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
bh_point3f_t *bh_point3f_slerp(const bh_point3f_t *a,
|
||||
const bh_point3f_t *b,
|
||||
float t,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
bh_point2f_t *bh_point2f_add(const bh_point2f_t *a,
|
||||
const bh_point2f_t *b,
|
||||
bh_point2f_t *result);
|
||||
|
||||
|
||||
bh_point2f_t *bh_point2f_sub(const bh_point2f_t *a,
|
||||
const bh_point2f_t *b,
|
||||
bh_point2f_t *result);
|
||||
|
||||
|
||||
bh_point2f_t *bh_point2f_mul(const bh_point2f_t *a,
|
||||
const bh_point2f_t *b,
|
||||
bh_point2f_t *result);
|
||||
|
||||
|
||||
bh_point2f_t *bh_point2f_scale(const bh_point2f_t *a,
|
||||
float b,
|
||||
bh_point2f_t *result);
|
||||
|
||||
|
||||
bh_point2f_t *bh_point2f_madd(const bh_point2f_t *a,
|
||||
const bh_point2f_t *b,
|
||||
const bh_point2f_t *c,
|
||||
bh_point2f_t *result);
|
||||
|
||||
|
||||
bh_point2f_t *bh_point2f_negate(const bh_point2f_t *in,
|
||||
bh_point2f_t *result);
|
||||
|
||||
|
||||
float bh_point2f_dot(const bh_point2f_t *a,
|
||||
const bh_point2f_t *b);
|
||||
|
||||
|
||||
float bh_point2f_cross(const bh_point2f_t *a,
|
||||
const bh_point2f_t *b);
|
||||
|
||||
|
||||
float bh_point2f_length(const bh_point2f_t *in);
|
||||
|
||||
|
||||
bh_point2f_t *bh_point2f_normal(const bh_point2f_t *in,
|
||||
bh_point2f_t *result);
|
||||
|
||||
|
||||
bh_point2f_t *bh_point2f_min(const bh_point2f_t *a,
|
||||
const bh_point2f_t *b,
|
||||
bh_point2f_t *result);
|
||||
|
||||
|
||||
bh_point2f_t *bh_point2f_max(const bh_point2f_t *a,
|
||||
const bh_point2f_t *b,
|
||||
bh_point2f_t *result);
|
||||
|
||||
|
||||
bh_point2f_t *bh_point2f_lerp(const bh_point2f_t *a,
|
||||
const bh_point2f_t *b,
|
||||
float t,
|
||||
bh_point2f_t *result);
|
||||
|
||||
|
||||
bh_point2f_t *bh_point2f_slerp(const bh_point2f_t *a,
|
||||
const bh_point2f_t *b,
|
||||
float t,
|
||||
bh_point2f_t *result);
|
||||
|
||||
|
||||
bh_point4i_t *bh_point4i_add(const bh_point4i_t *a,
|
||||
const bh_point4i_t *b,
|
||||
bh_point4i_t *result);
|
||||
|
||||
|
||||
bh_point4i_t *bh_point4i_sub(const bh_point4i_t *a,
|
||||
const bh_point4i_t *b,
|
||||
bh_point4i_t *result);
|
||||
|
||||
|
||||
bh_point4i_t *bh_point4i_mul(const bh_point4i_t *a,
|
||||
const bh_point4i_t *b,
|
||||
bh_point4i_t *result);
|
||||
|
||||
|
||||
bh_point4i_t *bh_point4i_scale(const bh_point4i_t *a,
|
||||
int b,
|
||||
bh_point4i_t *result);
|
||||
|
||||
|
||||
bh_point4i_t *bh_point4i_madd(const bh_point4i_t *a,
|
||||
const bh_point4i_t *b,
|
||||
const bh_point4i_t *c,
|
||||
bh_point4i_t *result);
|
||||
|
||||
|
||||
bh_point4i_t *bh_point4i_negate(const bh_point4i_t *in,
|
||||
bh_point4i_t *result);
|
||||
|
||||
|
||||
bh_point4i_t *bh_point4i_min(const bh_point4i_t *a,
|
||||
const bh_point4i_t *b,
|
||||
bh_point4i_t *result);
|
||||
|
||||
|
||||
bh_point4i_t *bh_point4i_max(const bh_point4i_t *a,
|
||||
const bh_point4i_t *b,
|
||||
bh_point4i_t *result);
|
||||
|
||||
|
||||
bh_point4i_t *bh_point4i_lerp(const bh_point4i_t *a,
|
||||
const bh_point4i_t *b,
|
||||
float t,
|
||||
bh_point4i_t *result);
|
||||
|
||||
|
||||
bh_point3i_t *bh_point3i_add(const bh_point3i_t *a,
|
||||
const bh_point3i_t *b,
|
||||
bh_point3i_t *result);
|
||||
|
||||
|
||||
bh_point3i_t *bh_point3i_sub(const bh_point3i_t *a,
|
||||
const bh_point3i_t *b,
|
||||
bh_point3i_t *result);
|
||||
|
||||
|
||||
bh_point3i_t *bh_point3i_mul(const bh_point3i_t *a,
|
||||
const bh_point3i_t *b,
|
||||
bh_point3i_t *result);
|
||||
|
||||
|
||||
bh_point3i_t *bh_point3i_scale(const bh_point3i_t *a,
|
||||
int b,
|
||||
bh_point3i_t *result);
|
||||
|
||||
|
||||
bh_point3i_t *bh_point3i_madd(const bh_point3i_t *a,
|
||||
const bh_point3i_t *b,
|
||||
const bh_point3i_t *c,
|
||||
bh_point3i_t *result);
|
||||
|
||||
|
||||
bh_point3i_t *bh_point3i_negate(const bh_point3i_t *in,
|
||||
bh_point3i_t *result);
|
||||
|
||||
|
||||
bh_point3i_t *bh_point3i_min(const bh_point3i_t *a,
|
||||
const bh_point3i_t *b,
|
||||
bh_point3i_t *result);
|
||||
|
||||
|
||||
bh_point3i_t *bh_point3i_max(const bh_point3i_t *a,
|
||||
const bh_point3i_t *b,
|
||||
bh_point3i_t *result);
|
||||
|
||||
|
||||
bh_point3i_t *bh_point3i_lerp(const bh_point3i_t *a,
|
||||
const bh_point3i_t *b,
|
||||
float t,
|
||||
bh_point3i_t *result);
|
||||
|
||||
|
||||
bh_point2i_t *bh_point2i_add(const bh_point2i_t *a,
|
||||
const bh_point2i_t *b,
|
||||
bh_point2i_t *result);
|
||||
|
||||
|
||||
bh_point2i_t *bh_point2i_sub(const bh_point2i_t *a,
|
||||
const bh_point2i_t *b,
|
||||
bh_point2i_t *result);
|
||||
|
||||
|
||||
bh_point2i_t *bh_point2i_mul(const bh_point2i_t *a,
|
||||
const bh_point2i_t *b,
|
||||
bh_point2i_t *result);
|
||||
|
||||
|
||||
bh_point2i_t *bh_point2i_scale(const bh_point2i_t *a,
|
||||
int b,
|
||||
bh_point2i_t *result);
|
||||
|
||||
|
||||
bh_point2i_t *bh_point2i_madd(const bh_point2i_t *a,
|
||||
const bh_point2i_t *b,
|
||||
const bh_point2i_t *c,
|
||||
bh_point2i_t *result);
|
||||
|
||||
|
||||
bh_point2i_t *bh_point2i_negate(const bh_point2i_t *in,
|
||||
bh_point2i_t *result);
|
||||
|
||||
|
||||
bh_point2i_t *bh_point2i_min(const bh_point2i_t *a,
|
||||
const bh_point2i_t *b,
|
||||
bh_point2i_t *result);
|
||||
|
||||
|
||||
bh_point2i_t *bh_point2i_max(const bh_point2i_t *a,
|
||||
const bh_point2i_t *b,
|
||||
bh_point2i_t *result);
|
||||
|
||||
|
||||
bh_point2i_t *bh_point2i_lerp(const bh_point2i_t *a,
|
||||
const bh_point2i_t *b,
|
||||
float t,
|
||||
bh_point2i_t *result);
|
||||
|
||||
|
||||
#define bh_quat_add bh_point4f_add
|
||||
|
||||
|
||||
#define bh_quat_sub bh_point4f_sub
|
||||
|
||||
|
||||
#define bh_quat_scale bh_point4f_scale
|
||||
|
||||
|
||||
#define bh_quat_negate bh_point4f_negate
|
||||
|
||||
|
||||
#define bh_quat_length bh_point4f_length
|
||||
|
||||
|
||||
#define bh_quat_normal bh_point4f_normal
|
||||
|
||||
|
||||
#define bh_quat_dot bh_point4f_dot
|
||||
|
||||
|
||||
#define bh_quat_lerp bh_point4f_lerp
|
||||
|
||||
|
||||
#define bh_quat_slerp bh_point4f_slerp
|
||||
|
||||
|
||||
bh_quat_t *bh_quat_identity(bh_quat_t *result);
|
||||
|
||||
|
||||
bh_quat_t *bh_quat_conjugate(const bh_quat_t *in,
|
||||
bh_quat_t *result);
|
||||
|
||||
|
||||
bh_quat_t *bh_quat_inverse(const bh_quat_t *in,
|
||||
bh_quat_t *result);
|
||||
|
||||
|
||||
bh_quat_t *bh_quat_mul(const bh_quat_t *a,
|
||||
const bh_quat_t *b,
|
||||
bh_quat_t *result);
|
||||
|
||||
|
||||
bh_quat_t *bh_quat_set_euler(float roll,
|
||||
float pitch,
|
||||
float yaw,
|
||||
bh_quat_t *result);
|
||||
|
||||
|
||||
bh_quat_t *bh_quat_set_rotation(const bh_point3f_t *axis,
|
||||
float angle,
|
||||
bh_quat_t *result);
|
||||
|
||||
|
||||
void bh_quat_euler(const bh_quat_t *in,
|
||||
float *roll,
|
||||
float *pitch,
|
||||
float *yaw);
|
||||
|
||||
|
||||
void bh_quat_rotation(const bh_quat_t *in,
|
||||
bh_point3f_t *axis,
|
||||
float *angle);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_quat_matrix(const bh_quat_t *in,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_identity(bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_add(const bh_matrix4f_t *a,
|
||||
const bh_matrix4f_t *b,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_sub(const bh_matrix4f_t *a,
|
||||
const bh_matrix4f_t *b,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_mul(const bh_matrix4f_t *a,
|
||||
const bh_matrix4f_t *b,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_scale(const bh_matrix4f_t *a,
|
||||
float b,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_transpose(const bh_matrix4f_t *in,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
float bh_matrix4f_trace(const bh_matrix4f_t *in);
|
||||
|
||||
|
||||
float bh_matrix4f_determinant(const bh_matrix4f_t *in);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_inverse(const bh_matrix4f_t *in,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_scaling(float x,
|
||||
float y,
|
||||
float z,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_translation(float x,
|
||||
float y,
|
||||
float z,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_rotation_x(float angle,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_rotation_y(float angle,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_rotation_z(float angle,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_rotation(const bh_point3f_t *axis,
|
||||
float angle,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_rotation_euler(float roll,
|
||||
float pitch,
|
||||
float yaw,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_rotation_quat(bh_quat_t *rotation,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_ortho(float x_min,
|
||||
float x_max,
|
||||
float y_min,
|
||||
float y_max,
|
||||
float z_min,
|
||||
float z_max,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_perspective(float fov,
|
||||
float aspect,
|
||||
float z_min,
|
||||
float z_max,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_matrix4f_t *bh_matrix4f_lookat(const bh_point3f_t *camera,
|
||||
const bh_point3f_t *at,
|
||||
const bh_point3f_t *up,
|
||||
bh_matrix4f_t *result);
|
||||
|
||||
|
||||
bh_point3f_t *bh_matrix4f_transform_point3f(const bh_matrix4f_t *a,
|
||||
const bh_point3f_t *b,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
bh_point4f_t *bh_matrix4f_transform_point4f(const bh_matrix4f_t *a,
|
||||
const bh_point4f_t *b,
|
||||
bh_point4f_t *result);
|
||||
|
||||
|
||||
bh_matrix3f_t *bh_matrix3f_identity(bh_matrix3f_t *result);
|
||||
|
||||
|
||||
bh_matrix3f_t *bh_matrix3f_add(const bh_matrix3f_t *a,
|
||||
const bh_matrix3f_t *b,
|
||||
bh_matrix3f_t *result);
|
||||
|
||||
|
||||
bh_matrix3f_t *bh_matrix3f_sub(const bh_matrix3f_t *a,
|
||||
const bh_matrix3f_t *b,
|
||||
bh_matrix3f_t *result);
|
||||
|
||||
|
||||
bh_matrix3f_t *bh_matrix3f_mul(const bh_matrix3f_t *a,
|
||||
const bh_matrix3f_t *b,
|
||||
bh_matrix3f_t *result);
|
||||
|
||||
|
||||
bh_matrix3f_t *bh_matrix3f_scale(const bh_matrix3f_t *a,
|
||||
float b,
|
||||
bh_matrix3f_t *result);
|
||||
|
||||
|
||||
bh_matrix3f_t *bh_matrix3f_transpose(const bh_matrix3f_t *in,
|
||||
bh_matrix3f_t *result);
|
||||
|
||||
|
||||
float bh_matrix3f_trace(const bh_matrix3f_t *in);
|
||||
|
||||
|
||||
float bh_matrix3f_determinant(const bh_matrix3f_t *in);
|
||||
|
||||
|
||||
bh_matrix3f_t *bh_matrix3f_inverse(const bh_matrix3f_t *in,
|
||||
bh_matrix3f_t *result);
|
||||
|
||||
|
||||
bh_matrix3f_t *bh_matrix3f_scaling(float x,
|
||||
float y,
|
||||
bh_matrix3f_t *result);
|
||||
|
||||
|
||||
bh_matrix3f_t *bh_matrix3f_translation(float x,
|
||||
float y,
|
||||
bh_matrix3f_t *result);
|
||||
|
||||
|
||||
bh_matrix3f_t *bh_matrix3f_rotation(float angle,
|
||||
bh_matrix3f_t *result);
|
||||
|
||||
|
||||
bh_point2f_t *bh_matrix3f_transform_point2f(const bh_matrix3f_t *a,
|
||||
const bh_point2f_t *b,
|
||||
bh_point2f_t *result);
|
||||
|
||||
|
||||
bh_point3f_t *bh_matrix3f_transform_point3f(const bh_matrix3f_t *a,
|
||||
const bh_point3f_t *b,
|
||||
bh_point3f_t *result);
|
||||
|
||||
|
||||
#endif /* BH_MATH_H */
|
||||
149
include/bh/queue.h
Executable file
149
include/bh/queue.h
Executable file
@@ -0,0 +1,149 @@
|
||||
#ifndef BH_QUEUE_H
|
||||
#define BH_QUEUE_H
|
||||
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
typedef struct bh_queue_s bh_queue_t;
|
||||
|
||||
|
||||
/**
|
||||
* Creates the new queue object.
|
||||
*
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Frees the \a queue object.
|
||||
*
|
||||
* \param queue Pointer to the queue object to be freed
|
||||
*/
|
||||
void bh_queue_free(bh_queue_t *queue);
|
||||
|
||||
|
||||
/**
|
||||
* Clears the \a queue object.
|
||||
*
|
||||
* \param queue Pointer to the queue object to be cleared
|
||||
*/
|
||||
void bh_queue_clear(bh_queue_t *queue);
|
||||
|
||||
|
||||
/**
|
||||
* Reserves the space for \a size elements in the \a queue.
|
||||
*
|
||||
* This function can both expand and shrink the available space in \a queue.
|
||||
*
|
||||
* \param queue Pointer to the queue object to be resized in terms of capacity
|
||||
* \param size New capacity of the queue
|
||||
*
|
||||
* \note Calling this function will invalidate iterators.
|
||||
* \note Actual hashmap capacity can be bigger then requested.
|
||||
*
|
||||
* \return On success, returns zero value.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int bh_queue_reserve(bh_queue_t *queue,
|
||||
size_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Inserts the \a value into the \a queue.
|
||||
*
|
||||
* \param queue Pointer to the queue object
|
||||
* \param value Value to be inserted
|
||||
*
|
||||
* \note Calling this function will invalidate iterators.
|
||||
*
|
||||
* \return On success, returns zero value.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int bh_queue_insert(bh_queue_t *queue,
|
||||
void *value);
|
||||
|
||||
|
||||
/**
|
||||
* Removes front value from the \a queue.
|
||||
*
|
||||
* \param queue Pointer to the queue object
|
||||
*
|
||||
* \note Calling this function will invalidate iterators.
|
||||
*/
|
||||
void bh_queue_remove(bh_queue_t *queue);
|
||||
|
||||
|
||||
/**
|
||||
* Returns front value from the \a queue.
|
||||
*
|
||||
* \param queue Pointer to the queue object
|
||||
*
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the \a queue is empty.
|
||||
*
|
||||
* \param queue Pointer to the queue object
|
||||
*
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the size of the \a queue.
|
||||
*
|
||||
* \param queue Pointer to the queue object
|
||||
*
|
||||
* \return Returns the size of the queue.
|
||||
*/
|
||||
size_t bh_queue_size(bh_queue_t *queue);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the capacity of the \a queue.
|
||||
*
|
||||
* \param queue Pointer to the queue object
|
||||
*
|
||||
* \return Returns the capacity of the queue.
|
||||
*/
|
||||
size_t bh_queue_capacity(bh_queue_t *queue);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the iterator to the next element in the \a queue.
|
||||
*
|
||||
* \param queue Pointer to the queue object
|
||||
* \param iter Opaque iterator value
|
||||
*
|
||||
* \return If the \a iter doesn't point to the last element of the queue,
|
||||
* returns next iterator value.
|
||||
* \return If the \a iter point to the last element of the queue, returns
|
||||
* null pointer.
|
||||
* \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);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value, pointed by the queue iterator \a iter.
|
||||
*
|
||||
* \param iter Opaque iterator value
|
||||
*
|
||||
* \return Returns value, pointed by iterator.
|
||||
*/
|
||||
void *bh_queue_iter_value(void *iter);
|
||||
|
||||
|
||||
#endif /* BH_QUEUE_H */
|
||||
Reference in New Issue
Block a user