Personal library for my EPITECH projects.
#include "my/my.h"
#include "my/collections/hash_map.h"
// Demonstrate the use of the OPT(T) type
static OPT(f64) safe_div(f64_t a, f64_t b)
{
if (b == 0)
return (NONE(f64));
return (SOME(f64, a / b));
}
// Put arguments in a hash map
int main(int ac, char **av) {
hash_map_t *args = hash_map_new();
char *foo = NULL;
for (usize_t i = 1; i + 1 < ac; i += 2)
hash_map_insert(args, av[i], av[i + 1]);
foo = hash_map_get(args, "foo");
if (foo)
my_printf("foo: %s\n", foo);
hash_map_destroy(args);
return (0);
}
[iu](8|16|32|64|size)_t
: integer data types (u8_t
,i32_t
, ...)f(32|64)_t
: floating point data types (e.g. anf32_t
is just afloat
)<primitive>_(min|max)
:min
andmax
functions for any primitive
OPT(T)
: similar to Rust'sOption<T>
or Haskell'sMaybe T
RES(T, E)
: similar to Rust'sResult<T, E>
OPT(<primitive>)
:OPT(T)
for all primitives!!RC(T)
: (R)eference (C)ounting primitive; similar to C++'sstd::shared_ptr
my_malloc
,my_free
andmy_calloc
my_memcpy
,my_memmove
andmy_memset
my_open
andmy_close
my_read
andmy_write
vector_t
: a continuous growable array (copies the elements' data)list_t
: circular doubly linked list (stores pointers to elements)hash_map_t
: an hash table implementation (stores pointers to elements)
my_printf
: yeah (no support for floating point data types yet tho)my_format
: format a string to a newly allocatedchar *
bufreader_t
: abstract buffered input streambufwriter_t
: abstract buffered output streamfilereader_t
: implementation ofbufreader_t
around a file descriptorfilewriter_t
: implementation ofbufwriter_t
around a file descriptor