fx.collections: update header directories
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
include(../cmake/Templates.cmake)
|
include(../cmake/Templates.cmake)
|
||||||
|
|
||||||
add_fx_module(NAME ds DEPENDENCIES core)
|
add_fx_assembly(
|
||||||
|
NAME fx.collections
|
||||||
|
DEPENDENCIES fx)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <fx/core/iterator.h>
|
#include <fx/collections/array.h>
|
||||||
#include <fx/core/stream.h>
|
#include <fx/collections/string.h>
|
||||||
#include <fx/ds/array.h>
|
#include <fx/iterator.h>
|
||||||
#include <fx/ds/string.h>
|
#include <fx/stream.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include <fx/ds/bitbuffer.h>
|
#include <fx/collections/bitbuffer.h>
|
||||||
|
|
||||||
/*** PRIVATE DATA *************************************************************/
|
/*** PRIVATE DATA *************************************************************/
|
||||||
|
|
||||||
|
|||||||
+45
-15
@@ -1,6 +1,6 @@
|
|||||||
#include <fx/core/bitop.h>
|
#include <fx/bitop.h>
|
||||||
#include <fx/core/stream.h>
|
#include <fx/collections/bitmap.h>
|
||||||
#include <fx/ds/bitmap.h>
|
#include <fx/stream.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define BITS_PER_WORD (8 * sizeof(bitmap_word_t))
|
#define BITS_PER_WORD (8 * sizeof(bitmap_word_t))
|
||||||
@@ -36,11 +36,17 @@ static void bitmap_clear_bit(struct fx_bitmap_p *map, size_t bit)
|
|||||||
map->map_words[index] &= ~mask;
|
map->map_words[index] &= ~mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bitmap_set_range(struct fx_bitmap_p *map, size_t first_bit, size_t nbits)
|
static void bitmap_set_range(
|
||||||
|
struct fx_bitmap_p *map,
|
||||||
|
size_t first_bit,
|
||||||
|
size_t nbits)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bitmap_clear_range(struct fx_bitmap_p *map, size_t first_bit, size_t nbits)
|
static void bitmap_clear_range(
|
||||||
|
struct fx_bitmap_p *map,
|
||||||
|
size_t first_bit,
|
||||||
|
size_t nbits)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,13 +222,21 @@ void fx_bitmap_clear_bit(fx_bitmap *map, size_t bit)
|
|||||||
void fx_bitmap_set_range(fx_bitmap *map, size_t first_bit, size_t nbits)
|
void fx_bitmap_set_range(fx_bitmap *map, size_t first_bit, size_t nbits)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC_V(
|
FX_CLASS_DISPATCH_STATIC_V(
|
||||||
FX_TYPE_BITMAP, bitmap_set_range, map, first_bit, nbits);
|
FX_TYPE_BITMAP,
|
||||||
|
bitmap_set_range,
|
||||||
|
map,
|
||||||
|
first_bit,
|
||||||
|
nbits);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fx_bitmap_clear_range(fx_bitmap *map, size_t first_bit, size_t nbits)
|
void fx_bitmap_clear_range(fx_bitmap *map, size_t first_bit, size_t nbits)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC_V(
|
FX_CLASS_DISPATCH_STATIC_V(
|
||||||
FX_TYPE_BITMAP, bitmap_clear_range, map, first_bit, nbits);
|
FX_TYPE_BITMAP,
|
||||||
|
bitmap_clear_range,
|
||||||
|
map,
|
||||||
|
first_bit,
|
||||||
|
nbits);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fx_bitmap_set_all(fx_bitmap *map)
|
void fx_bitmap_set_all(fx_bitmap *map)
|
||||||
@@ -247,7 +261,10 @@ size_t fx_bitmap_count_set_bits(const fx_bitmap *map)
|
|||||||
|
|
||||||
size_t fx_bitmap_count_clear_bits(const fx_bitmap *map)
|
size_t fx_bitmap_count_clear_bits(const fx_bitmap *map)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_BITMAP, bitmap_count_clear_bits, map);
|
FX_CLASS_DISPATCH_STATIC_0(
|
||||||
|
FX_TYPE_BITMAP,
|
||||||
|
bitmap_count_clear_bits,
|
||||||
|
map);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t fx_bitmap_highest_set_bit(const fx_bitmap *map)
|
size_t fx_bitmap_highest_set_bit(const fx_bitmap *map)
|
||||||
@@ -257,7 +274,10 @@ size_t fx_bitmap_highest_set_bit(const fx_bitmap *map)
|
|||||||
|
|
||||||
size_t fx_bitmap_highest_clear_bit(const fx_bitmap *map)
|
size_t fx_bitmap_highest_clear_bit(const fx_bitmap *map)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_BITMAP, bitmap_highest_clear_bit, map);
|
FX_CLASS_DISPATCH_STATIC_0(
|
||||||
|
FX_TYPE_BITMAP,
|
||||||
|
bitmap_highest_clear_bit,
|
||||||
|
map);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t fx_bitmap_lowest_set_bit(const fx_bitmap *map)
|
size_t fx_bitmap_lowest_set_bit(const fx_bitmap *map)
|
||||||
@@ -267,7 +287,10 @@ size_t fx_bitmap_lowest_set_bit(const fx_bitmap *map)
|
|||||||
|
|
||||||
size_t fx_bitmap_lowest_clear_bit(const fx_bitmap *map)
|
size_t fx_bitmap_lowest_clear_bit(const fx_bitmap *map)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_BITMAP, bitmap_lowest_clear_bit, map);
|
FX_CLASS_DISPATCH_STATIC_0(
|
||||||
|
FX_TYPE_BITMAP,
|
||||||
|
bitmap_lowest_clear_bit,
|
||||||
|
map);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** PUBLIC ALIAS FUNCTIONS ***************************************************/
|
/*** PUBLIC ALIAS FUNCTIONS ***************************************************/
|
||||||
@@ -285,7 +308,8 @@ static void bitmap_fini(fx_object *obj, void *priv)
|
|||||||
|
|
||||||
static void bitmap_to_string(const fx_object *obj, fx_stream *out)
|
static void bitmap_to_string(const fx_object *obj, fx_stream *out)
|
||||||
{
|
{
|
||||||
const struct fx_bitmap_p *map = fx_object_get_private(obj, FX_TYPE_BITMAP);
|
const struct fx_bitmap_p *map
|
||||||
|
= fx_object_get_private(obj, FX_TYPE_BITMAP);
|
||||||
|
|
||||||
unsigned char *bytes = (unsigned char *)map->map_words;
|
unsigned char *bytes = (unsigned char *)map->map_words;
|
||||||
size_t nr_bytes = map->map_nr_words * sizeof(bitmap_word_t);
|
size_t nr_bytes = map->map_nr_words * sizeof(bitmap_word_t);
|
||||||
@@ -294,10 +318,16 @@ static void bitmap_to_string(const fx_object *obj, fx_stream *out)
|
|||||||
for (size_t i = 0; i < nr_bytes - 1; i++) {
|
for (size_t i = 0; i < nr_bytes - 1; i++) {
|
||||||
c = bytes[i];
|
c = bytes[i];
|
||||||
fx_stream_write_fmt(
|
fx_stream_write_fmt(
|
||||||
out, NULL, "%c%c%c%c%c%c%c%c", c & 0x80 ? '1' : '0',
|
out,
|
||||||
c & 0x40 ? '1' : '0', c & 0x20 ? '1' : '0',
|
NULL,
|
||||||
c & 0x10 ? '1' : '0', c & 0x08 ? '1' : '0',
|
"%c%c%c%c%c%c%c%c",
|
||||||
c & 0x04 ? '1' : '0', c & 0x02 ? '1' : '0',
|
c & 0x80 ? '1' : '0',
|
||||||
|
c & 0x40 ? '1' : '0',
|
||||||
|
c & 0x20 ? '1' : '0',
|
||||||
|
c & 0x10 ? '1' : '0',
|
||||||
|
c & 0x08 ? '1' : '0',
|
||||||
|
c & 0x04 ? '1' : '0',
|
||||||
|
c & 0x02 ? '1' : '0',
|
||||||
c & 0x01 ? '1' : '0');
|
c & 0x01 ? '1' : '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+53
-14
@@ -1,5 +1,5 @@
|
|||||||
#include <fx/core/iterator.h>
|
#include <fx/collections/buffer.h>
|
||||||
#include <fx/ds/buffer.h>
|
#include <fx/iterator.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -21,7 +21,8 @@ static fx_status resize_buffer(struct fx_buffer_p *buffer, size_t new_capacity)
|
|||||||
{
|
{
|
||||||
if (buffer->buf_cap < new_capacity) {
|
if (buffer->buf_cap < new_capacity) {
|
||||||
void *new_data = realloc(
|
void *new_data = realloc(
|
||||||
buffer->buf_data, new_capacity * buffer->buf_itemsz);
|
buffer->buf_data,
|
||||||
|
new_capacity * buffer->buf_itemsz);
|
||||||
if (!new_data) {
|
if (!new_data) {
|
||||||
return FX_ERR_NO_MEMORY;
|
return FX_ERR_NO_MEMORY;
|
||||||
}
|
}
|
||||||
@@ -29,7 +30,8 @@ static fx_status resize_buffer(struct fx_buffer_p *buffer, size_t new_capacity)
|
|||||||
buffer->buf_data = new_data;
|
buffer->buf_data = new_data;
|
||||||
} else {
|
} else {
|
||||||
void *new_data = realloc(
|
void *new_data = realloc(
|
||||||
buffer->buf_data, new_capacity * buffer->buf_itemsz);
|
buffer->buf_data,
|
||||||
|
new_capacity * buffer->buf_itemsz);
|
||||||
if (!new_data) {
|
if (!new_data) {
|
||||||
return FX_ERR_NO_MEMORY;
|
return FX_ERR_NO_MEMORY;
|
||||||
}
|
}
|
||||||
@@ -78,7 +80,10 @@ static enum fx_status buffer_resize(struct fx_buffer_p *buf, size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static enum fx_status buffer_insert(
|
static enum fx_status buffer_insert(
|
||||||
struct fx_buffer_p *buffer, const void *p, size_t count, size_t at)
|
struct fx_buffer_p *buffer,
|
||||||
|
const void *p,
|
||||||
|
size_t count,
|
||||||
|
size_t at)
|
||||||
{
|
{
|
||||||
if (at == FX_NPOS) {
|
if (at == FX_NPOS) {
|
||||||
at = buffer->buf_len;
|
at = buffer->buf_len;
|
||||||
@@ -110,7 +115,10 @@ static enum fx_status buffer_insert(
|
|||||||
return FX_SUCCESS;
|
return FX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum fx_status buffer_remove(struct fx_buffer_p *buffer, size_t at, size_t count)
|
static enum fx_status buffer_remove(
|
||||||
|
struct fx_buffer_p *buffer,
|
||||||
|
size_t at,
|
||||||
|
size_t count)
|
||||||
{
|
{
|
||||||
if (at >= buffer->buf_len) {
|
if (at >= buffer->buf_len) {
|
||||||
return FX_ERR_OUT_OF_BOUNDS;
|
return FX_ERR_OUT_OF_BOUNDS;
|
||||||
@@ -162,7 +170,9 @@ static enum fx_status buffer_clear(struct fx_buffer_p *buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static enum fx_status buffer_push_back(
|
static enum fx_status buffer_push_back(
|
||||||
struct fx_buffer_p *buf, size_t count, void **p)
|
struct fx_buffer_p *buf,
|
||||||
|
size_t count,
|
||||||
|
void **p)
|
||||||
{
|
{
|
||||||
enum fx_status status = FX_SUCCESS;
|
enum fx_status status = FX_SUCCESS;
|
||||||
|
|
||||||
@@ -181,7 +191,9 @@ static enum fx_status buffer_push_back(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static enum fx_status buffer_push_front(
|
static enum fx_status buffer_push_front(
|
||||||
struct fx_buffer_p *buf, size_t count, void **p)
|
struct fx_buffer_p *buf,
|
||||||
|
size_t count,
|
||||||
|
void **p)
|
||||||
{
|
{
|
||||||
enum fx_status status = FX_SUCCESS;
|
enum fx_status status = FX_SUCCESS;
|
||||||
|
|
||||||
@@ -286,7 +298,10 @@ fx_buffer *fx_buffer_create_from_bytes(const void *buf, size_t len)
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
fx_buffer *fx_buffer_create_from_array(const void *buf, size_t item_sz, size_t len)
|
fx_buffer *fx_buffer_create_from_array(
|
||||||
|
const void *buf,
|
||||||
|
size_t item_sz,
|
||||||
|
size_t len)
|
||||||
{
|
{
|
||||||
fx_buffer *buffer = fx_object_create(FX_TYPE_BUFFER);
|
fx_buffer *buffer = fx_object_create(FX_TYPE_BUFFER);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
@@ -325,14 +340,28 @@ enum fx_status fx_buffer_resize(fx_buffer *buf, size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum fx_status fx_buffer_insert(
|
enum fx_status fx_buffer_insert(
|
||||||
fx_buffer *buffer, const void *p, size_t count, size_t at)
|
fx_buffer *buffer,
|
||||||
|
const void *p,
|
||||||
|
size_t count,
|
||||||
|
size_t at)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_BUFFER, buffer_insert, buffer, p, count, at);
|
FX_CLASS_DISPATCH_STATIC(
|
||||||
|
FX_TYPE_BUFFER,
|
||||||
|
buffer_insert,
|
||||||
|
buffer,
|
||||||
|
p,
|
||||||
|
count,
|
||||||
|
at);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum fx_status fx_buffer_remove(fx_buffer *buffer, size_t at, size_t count)
|
enum fx_status fx_buffer_remove(fx_buffer *buffer, size_t at, size_t count)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_BUFFER, buffer_remove, buffer, at, count);
|
FX_CLASS_DISPATCH_STATIC(
|
||||||
|
FX_TYPE_BUFFER,
|
||||||
|
buffer_remove,
|
||||||
|
buffer,
|
||||||
|
at,
|
||||||
|
count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *fx_buffer_ptr(const fx_buffer *buffer)
|
void *fx_buffer_ptr(const fx_buffer *buffer)
|
||||||
@@ -362,12 +391,22 @@ enum fx_status fx_buffer_clear(fx_buffer *buffer)
|
|||||||
|
|
||||||
enum fx_status fx_buffer_push_back(fx_buffer *buf, size_t count, void **p)
|
enum fx_status fx_buffer_push_back(fx_buffer *buf, size_t count, void **p)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_BUFFER, buffer_push_back, buf, count, p);
|
FX_CLASS_DISPATCH_STATIC(
|
||||||
|
FX_TYPE_BUFFER,
|
||||||
|
buffer_push_back,
|
||||||
|
buf,
|
||||||
|
count,
|
||||||
|
p);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum fx_status fx_buffer_push_front(fx_buffer *buf, size_t count, void **p)
|
enum fx_status fx_buffer_push_front(fx_buffer *buf, size_t count, void **p)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_BUFFER, buffer_push_front, buf, count, p);
|
FX_CLASS_DISPATCH_STATIC(
|
||||||
|
FX_TYPE_BUFFER,
|
||||||
|
buffer_push_front,
|
||||||
|
buf,
|
||||||
|
count,
|
||||||
|
p);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum fx_status fx_buffer_pop_back(fx_buffer *buf, size_t count)
|
enum fx_status fx_buffer_pop_back(fx_buffer *buf, size_t count)
|
||||||
|
|||||||
+58
-19
@@ -1,6 +1,6 @@
|
|||||||
#include <fx/core/stream.h>
|
#include <fx/collections/datetime.h>
|
||||||
#include <fx/ds/datetime.h>
|
#include <fx/collections/string.h>
|
||||||
#include <fx/ds/string.h>
|
#include <fx/stream.h>
|
||||||
|
|
||||||
/*** PRIVATE DATA *************************************************************/
|
/*** PRIVATE DATA *************************************************************/
|
||||||
|
|
||||||
@@ -89,7 +89,8 @@ static bool is_zone_valid(const struct fx_datetime_p *dt)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(dt->dt_zone_offset_minute >= 0 && dt->dt_zone_offset_minute <= 59)) {
|
if (!(dt->dt_zone_offset_minute >= 0
|
||||||
|
&& dt->dt_zone_offset_minute <= 59)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,12 +310,18 @@ fail:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum fx_status encode_rfc3339(const struct fx_datetime_p *dt, fx_stream *out)
|
static enum fx_status encode_rfc3339(
|
||||||
|
const struct fx_datetime_p *dt,
|
||||||
|
fx_stream *out)
|
||||||
{
|
{
|
||||||
if (dt->dt_has_date) {
|
if (dt->dt_has_date) {
|
||||||
fx_stream_write_fmt(
|
fx_stream_write_fmt(
|
||||||
out, NULL, "%04ld-%02ld-%02ld", dt->dt_year,
|
out,
|
||||||
dt->dt_month, dt->dt_day);
|
NULL,
|
||||||
|
"%04ld-%02ld-%02ld",
|
||||||
|
dt->dt_year,
|
||||||
|
dt->dt_month,
|
||||||
|
dt->dt_day);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dt->dt_has_date && dt->dt_has_time) {
|
if (dt->dt_has_date && dt->dt_has_time) {
|
||||||
@@ -323,7 +330,11 @@ static enum fx_status encode_rfc3339(const struct fx_datetime_p *dt, fx_stream *
|
|||||||
|
|
||||||
if (dt->dt_has_time) {
|
if (dt->dt_has_time) {
|
||||||
fx_stream_write_fmt(
|
fx_stream_write_fmt(
|
||||||
out, NULL, "%02ld:%02ld:%02ld", dt->dt_hour, dt->dt_min,
|
out,
|
||||||
|
NULL,
|
||||||
|
"%02ld:%02ld:%02ld",
|
||||||
|
dt->dt_hour,
|
||||||
|
dt->dt_min,
|
||||||
dt->dt_sec);
|
dt->dt_sec);
|
||||||
|
|
||||||
if (dt->dt_msec > 0) {
|
if (dt->dt_msec > 0) {
|
||||||
@@ -336,7 +347,9 @@ static enum fx_status encode_rfc3339(const struct fx_datetime_p *dt, fx_stream *
|
|||||||
fx_stream_write_char(out, 'Z');
|
fx_stream_write_char(out, 'Z');
|
||||||
} else {
|
} else {
|
||||||
fx_stream_write_fmt(
|
fx_stream_write_fmt(
|
||||||
out, NULL, "%c%02ld:%02ld",
|
out,
|
||||||
|
NULL,
|
||||||
|
"%c%02ld:%02ld",
|
||||||
dt->dt_zone_offset_negative ? '-' : '+',
|
dt->dt_zone_offset_negative ? '-' : '+',
|
||||||
dt->dt_zone_offset_hour,
|
dt->dt_zone_offset_hour,
|
||||||
dt->dt_zone_offset_minute);
|
dt->dt_zone_offset_minute);
|
||||||
@@ -348,7 +361,9 @@ static enum fx_status encode_rfc3339(const struct fx_datetime_p *dt, fx_stream *
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void datetime_to_string(
|
static void datetime_to_string(
|
||||||
const struct fx_datetime_p *dt, fx_datetime_format format, fx_stream *dest)
|
const struct fx_datetime_p *dt,
|
||||||
|
fx_datetime_format format,
|
||||||
|
fx_stream *dest)
|
||||||
{
|
{
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case FX_DATETIME_FORMAT_RFC3339:
|
case FX_DATETIME_FORMAT_RFC3339:
|
||||||
@@ -453,10 +468,16 @@ fx_datetime *fx_datetime_parse(enum fx_datetime_format format, const char *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void fx_datetime_to_string(
|
void fx_datetime_to_string(
|
||||||
const fx_datetime *dt, fx_datetime_format format, fx_stream *dest)
|
const fx_datetime *dt,
|
||||||
|
fx_datetime_format format,
|
||||||
|
fx_stream *dest)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC(
|
FX_CLASS_DISPATCH_STATIC(
|
||||||
FX_TYPE_DATETIME, datetime_to_string, dt, format, dest);
|
FX_TYPE_DATETIME,
|
||||||
|
datetime_to_string,
|
||||||
|
dt,
|
||||||
|
format,
|
||||||
|
dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fx_datetime_is_localtime(const fx_datetime *dt)
|
bool fx_datetime_is_localtime(const fx_datetime *dt)
|
||||||
@@ -512,17 +533,25 @@ long fx_datetime_subsecond(const fx_datetime *dt)
|
|||||||
bool fx_datetime_zone_offset_is_negative(const fx_datetime *dt)
|
bool fx_datetime_zone_offset_is_negative(const fx_datetime *dt)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC_0(
|
FX_CLASS_DISPATCH_STATIC_0(
|
||||||
FX_TYPE_DATETIME, datetime_zone_offset_is_negative, dt);
|
FX_TYPE_DATETIME,
|
||||||
|
datetime_zone_offset_is_negative,
|
||||||
|
dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
long fx_datetime_zone_offset_hour(const fx_datetime *dt)
|
long fx_datetime_zone_offset_hour(const fx_datetime *dt)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DATETIME, datetime_zone_offset_hour, dt);
|
FX_CLASS_DISPATCH_STATIC_0(
|
||||||
|
FX_TYPE_DATETIME,
|
||||||
|
datetime_zone_offset_hour,
|
||||||
|
dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
long fx_datetime_zone_offset_minute(const fx_datetime *dt)
|
long fx_datetime_zone_offset_minute(const fx_datetime *dt)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DATETIME, datetime_zone_offset_minute, dt);
|
FX_CLASS_DISPATCH_STATIC_0(
|
||||||
|
FX_TYPE_DATETIME,
|
||||||
|
datetime_zone_offset_minute,
|
||||||
|
dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||||
@@ -543,8 +572,12 @@ static void _datetime_to_string(const fx_object *obj, fx_stream *out)
|
|||||||
|
|
||||||
if (dt->dt_has_date) {
|
if (dt->dt_has_date) {
|
||||||
fx_stream_write_fmt(
|
fx_stream_write_fmt(
|
||||||
out, NULL, "%04ld-%02ld-%02ld", dt->dt_year,
|
out,
|
||||||
dt->dt_month, dt->dt_day);
|
NULL,
|
||||||
|
"%04ld-%02ld-%02ld",
|
||||||
|
dt->dt_year,
|
||||||
|
dt->dt_month,
|
||||||
|
dt->dt_day);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dt->dt_has_date && dt->dt_has_time) {
|
if (dt->dt_has_date && dt->dt_has_time) {
|
||||||
@@ -553,7 +586,11 @@ static void _datetime_to_string(const fx_object *obj, fx_stream *out)
|
|||||||
|
|
||||||
if (dt->dt_has_time) {
|
if (dt->dt_has_time) {
|
||||||
fx_stream_write_fmt(
|
fx_stream_write_fmt(
|
||||||
out, NULL, "%02ld:%02ld:%02ld", dt->dt_hour, dt->dt_min,
|
out,
|
||||||
|
NULL,
|
||||||
|
"%02ld:%02ld:%02ld",
|
||||||
|
dt->dt_hour,
|
||||||
|
dt->dt_min,
|
||||||
dt->dt_sec);
|
dt->dt_sec);
|
||||||
|
|
||||||
if (dt->dt_msec > 0) {
|
if (dt->dt_msec > 0) {
|
||||||
@@ -562,7 +599,9 @@ static void _datetime_to_string(const fx_object *obj, fx_stream *out)
|
|||||||
|
|
||||||
if (!dt->dt_localtime) {
|
if (!dt->dt_localtime) {
|
||||||
fx_stream_write_fmt(
|
fx_stream_write_fmt(
|
||||||
out, NULL, " %c%02ld:%02ld",
|
out,
|
||||||
|
NULL,
|
||||||
|
" %c%02ld:%02ld",
|
||||||
dt->dt_zone_offset_negative ? '-' : '+',
|
dt->dt_zone_offset_negative ? '-' : '+',
|
||||||
dt->dt_zone_offset_hour,
|
dt->dt_zone_offset_hour,
|
||||||
dt->dt_zone_offset_minute);
|
dt->dt_zone_offset_minute);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <fx/core/status.h>
|
#include <fx/collections/dict.h>
|
||||||
#include <fx/core/stream.h>
|
#include <fx/collections/string.h>
|
||||||
#include <fx/ds/dict.h>
|
#include <fx/status.h>
|
||||||
#include <fx/ds/string.h>
|
#include <fx/stream.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|||||||
+92
-41
@@ -1,7 +1,7 @@
|
|||||||
#include <fx/core/misc.h>
|
#include <fx/collections/hashmap.h>
|
||||||
#include <fx/core/status.h>
|
#include <fx/collections/string.h>
|
||||||
#include <fx/ds/hashmap.h>
|
#include <fx/misc.h>
|
||||||
#include <fx/ds/string.h>
|
#include <fx/status.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -42,9 +42,16 @@ struct fx_hashmap_iterator_p {
|
|||||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
static FX_BST_DEFINE_SIMPLE_GET(
|
static FX_BST_DEFINE_SIMPLE_GET(
|
||||||
struct fx_hashmap_bucket, uint64_t, bk_node, bk_hash, get_bucket);
|
struct fx_hashmap_bucket,
|
||||||
|
uint64_t,
|
||||||
|
bk_node,
|
||||||
|
bk_hash,
|
||||||
|
get_bucket);
|
||||||
static FX_BST_DEFINE_SIMPLE_INSERT(
|
static FX_BST_DEFINE_SIMPLE_INSERT(
|
||||||
struct fx_hashmap_bucket, bk_node, bk_hash, put_bucket);
|
struct fx_hashmap_bucket,
|
||||||
|
bk_node,
|
||||||
|
bk_hash,
|
||||||
|
put_bucket);
|
||||||
|
|
||||||
static uint64_t hash_data(const void *p, size_t size)
|
static uint64_t hash_data(const void *p, size_t size)
|
||||||
{
|
{
|
||||||
@@ -69,7 +76,8 @@ static uint64_t hash_key(const struct fx_hashmap_key *key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool compare_key(
|
static bool compare_key(
|
||||||
const struct fx_hashmap_key *a, const struct fx_hashmap_key *b)
|
const struct fx_hashmap_key *a,
|
||||||
|
const struct fx_hashmap_key *b)
|
||||||
{
|
{
|
||||||
const void *a_data = NULL, *fx_data = NULL;
|
const void *a_data = NULL, *fx_data = NULL;
|
||||||
size_t a_len = 0, fx_len = 0;
|
size_t a_len = 0, fx_len = 0;
|
||||||
@@ -99,8 +107,10 @@ static bool compare_key(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool get_next_node(
|
static bool get_next_node(
|
||||||
struct fx_bst_node *cur_node, struct fx_queue_entry *cur_entry,
|
struct fx_bst_node *cur_node,
|
||||||
struct fx_bst_node **out_next_node, struct fx_queue_entry **out_next_entry)
|
struct fx_queue_entry *cur_entry,
|
||||||
|
struct fx_bst_node **out_next_node,
|
||||||
|
struct fx_queue_entry **out_next_entry)
|
||||||
{
|
{
|
||||||
struct fx_hashmap_bucket *cur_bucket
|
struct fx_hashmap_bucket *cur_bucket
|
||||||
= fx_unbox(struct fx_hashmap_bucket, cur_node, bk_node);
|
= fx_unbox(struct fx_hashmap_bucket, cur_node, bk_node);
|
||||||
@@ -122,8 +132,10 @@ static bool get_next_node(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct fx_hashmap_bucket *next_bucket
|
struct fx_hashmap_bucket *next_bucket = fx_unbox(
|
||||||
= fx_unbox(struct fx_hashmap_bucket, next_node, bk_node);
|
struct fx_hashmap_bucket,
|
||||||
|
next_node,
|
||||||
|
bk_node);
|
||||||
if (!next_bucket) {
|
if (!next_bucket) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -169,11 +181,13 @@ static struct fx_hashmap_bucket_item *create_bucket_item(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static fx_status hashmap_put(
|
static fx_status hashmap_put(
|
||||||
struct fx_hashmap_p *hashmap, const fx_hashmap_key *key,
|
struct fx_hashmap_p *hashmap,
|
||||||
|
const fx_hashmap_key *key,
|
||||||
const fx_hashmap_value *value)
|
const fx_hashmap_value *value)
|
||||||
{
|
{
|
||||||
uint64_t hash = hash_key(key);
|
uint64_t hash = hash_key(key);
|
||||||
struct fx_hashmap_bucket *bucket = get_bucket(&hashmap->h_buckets, hash);
|
struct fx_hashmap_bucket *bucket
|
||||||
|
= get_bucket(&hashmap->h_buckets, hash);
|
||||||
|
|
||||||
if (!bucket) {
|
if (!bucket) {
|
||||||
bucket = create_bucket();
|
bucket = create_bucket();
|
||||||
@@ -187,8 +201,10 @@ static fx_status hashmap_put(
|
|||||||
|
|
||||||
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
||||||
while (entry) {
|
while (entry) {
|
||||||
struct fx_hashmap_bucket_item *item
|
struct fx_hashmap_bucket_item *item = fx_unbox(
|
||||||
= fx_unbox(struct fx_hashmap_bucket_item, entry, bi_entry);
|
struct fx_hashmap_bucket_item,
|
||||||
|
entry,
|
||||||
|
bi_entry);
|
||||||
|
|
||||||
if (compare_key(&item->bi_key, key)) {
|
if (compare_key(&item->bi_key, key)) {
|
||||||
memcpy(&item->bi_value, value, sizeof *value);
|
memcpy(&item->bi_value, value, sizeof *value);
|
||||||
@@ -213,19 +229,23 @@ static fx_status hashmap_put(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct fx_hashmap_value *hashmap_get(
|
static const struct fx_hashmap_value *hashmap_get(
|
||||||
const struct fx_hashmap_p *hashmap, const struct fx_hashmap_key *key)
|
const struct fx_hashmap_p *hashmap,
|
||||||
|
const struct fx_hashmap_key *key)
|
||||||
{
|
{
|
||||||
uint64_t hash = hash_key(key);
|
uint64_t hash = hash_key(key);
|
||||||
|
|
||||||
struct fx_hashmap_bucket *bucket = get_bucket(&hashmap->h_buckets, hash);
|
struct fx_hashmap_bucket *bucket
|
||||||
|
= get_bucket(&hashmap->h_buckets, hash);
|
||||||
if (!bucket) {
|
if (!bucket) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
||||||
while (entry) {
|
while (entry) {
|
||||||
struct fx_hashmap_bucket_item *item
|
struct fx_hashmap_bucket_item *item = fx_unbox(
|
||||||
= fx_unbox(struct fx_hashmap_bucket_item, entry, bi_entry);
|
struct fx_hashmap_bucket_item,
|
||||||
|
entry,
|
||||||
|
bi_entry);
|
||||||
|
|
||||||
if (compare_key(&item->bi_key, key)) {
|
if (compare_key(&item->bi_key, key)) {
|
||||||
return &item->bi_value;
|
return &item->bi_value;
|
||||||
@@ -238,18 +258,22 @@ static const struct fx_hashmap_value *hashmap_get(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool hashmap_has_key(
|
static bool hashmap_has_key(
|
||||||
const struct fx_hashmap_p *hashmap, const fx_hashmap_key *key)
|
const struct fx_hashmap_p *hashmap,
|
||||||
|
const fx_hashmap_key *key)
|
||||||
{
|
{
|
||||||
uint64_t hash = hash_key(key);
|
uint64_t hash = hash_key(key);
|
||||||
struct fx_hashmap_bucket *bucket = get_bucket(&hashmap->h_buckets, hash);
|
struct fx_hashmap_bucket *bucket
|
||||||
|
= get_bucket(&hashmap->h_buckets, hash);
|
||||||
if (!bucket) {
|
if (!bucket) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
||||||
while (entry) {
|
while (entry) {
|
||||||
struct fx_hashmap_bucket_item *item
|
struct fx_hashmap_bucket_item *item = fx_unbox(
|
||||||
= fx_unbox(struct fx_hashmap_bucket_item, entry, bi_entry);
|
struct fx_hashmap_bucket_item,
|
||||||
|
entry,
|
||||||
|
bi_entry);
|
||||||
|
|
||||||
if (compare_key(&item->bi_key, key)) {
|
if (compare_key(&item->bi_key, key)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -276,8 +300,10 @@ static bool hashmap_is_empty(const struct fx_hashmap_p *hashmap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fx_queue_entry *first_entry = fx_queue_first(&first_bucket->bk_items);
|
fx_queue_entry *first_entry = fx_queue_first(&first_bucket->bk_items);
|
||||||
struct fx_hashmap_bucket_item *first_item
|
struct fx_hashmap_bucket_item *first_item = fx_unbox(
|
||||||
= fx_unbox(struct fx_hashmap_bucket_item, first_entry, bi_entry);
|
struct fx_hashmap_bucket_item,
|
||||||
|
first_entry,
|
||||||
|
bi_entry);
|
||||||
if (!first_item) {
|
if (!first_item) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -286,7 +312,8 @@ static bool hashmap_is_empty(const struct fx_hashmap_p *hashmap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static fx_status delete_item(
|
static fx_status delete_item(
|
||||||
struct fx_hashmap_p *hashmap, struct fx_hashmap_bucket *bucket,
|
struct fx_hashmap_p *hashmap,
|
||||||
|
struct fx_hashmap_bucket *bucket,
|
||||||
struct fx_hashmap_bucket_item *item)
|
struct fx_hashmap_bucket_item *item)
|
||||||
{
|
{
|
||||||
fx_queue_delete(&bucket->bk_items, &item->bi_entry);
|
fx_queue_delete(&bucket->bk_items, &item->bi_entry);
|
||||||
@@ -313,7 +340,8 @@ static fx_status delete_item(
|
|||||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||||
|
|
||||||
fx_hashmap *fx_hashmap_create(
|
fx_hashmap *fx_hashmap_create(
|
||||||
fx_hashmap_key_destructor key_dtor, fx_hashmap_value_destructor value_dtor)
|
fx_hashmap_key_destructor key_dtor,
|
||||||
|
fx_hashmap_value_destructor value_dtor)
|
||||||
{
|
{
|
||||||
fx_hashmap *hashmap = fx_object_create(FX_TYPE_HASHMAP);
|
fx_hashmap *hashmap = fx_object_create(FX_TYPE_HASHMAP);
|
||||||
if (!hashmap) {
|
if (!hashmap) {
|
||||||
@@ -330,9 +358,11 @@ fx_hashmap *fx_hashmap_create_with_items(const fx_hashmap_item *items)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct fx_hashmap_p *p = fx_object_get_private(hashmap, FX_TYPE_HASHMAP);
|
struct fx_hashmap_p *p
|
||||||
|
= fx_object_get_private(hashmap, FX_TYPE_HASHMAP);
|
||||||
|
|
||||||
for (size_t i = 0; items[i].key.key_data && items[i].key.key_size; i++) {
|
for (size_t i = 0; items[i].key.key_data && items[i].key.key_size;
|
||||||
|
i++) {
|
||||||
hashmap_put(p, &items[i].key, &items[i].value);
|
hashmap_put(p, &items[i].key, &items[i].value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,20 +370,32 @@ fx_hashmap *fx_hashmap_create_with_items(const fx_hashmap_item *items)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fx_status fx_hashmap_put(
|
fx_status fx_hashmap_put(
|
||||||
fx_hashmap *hashmap, const fx_hashmap_key *key, const fx_hashmap_value *value)
|
fx_hashmap *hashmap,
|
||||||
|
const fx_hashmap_key *key,
|
||||||
|
const fx_hashmap_value *value)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_HASHMAP, hashmap_put, hashmap, key, value);
|
FX_CLASS_DISPATCH_STATIC(
|
||||||
|
FX_TYPE_HASHMAP,
|
||||||
|
hashmap_put,
|
||||||
|
hashmap,
|
||||||
|
key,
|
||||||
|
value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct fx_hashmap_value *fx_hashmap_get(
|
const struct fx_hashmap_value *fx_hashmap_get(
|
||||||
const fx_hashmap *hashmap, const struct fx_hashmap_key *key)
|
const fx_hashmap *hashmap,
|
||||||
|
const struct fx_hashmap_key *key)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_HASHMAP, hashmap_get, hashmap, key);
|
FX_CLASS_DISPATCH_STATIC(FX_TYPE_HASHMAP, hashmap_get, hashmap, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fx_hashmap_has_key(const fx_hashmap *hashmap, const fx_hashmap_key *key)
|
bool fx_hashmap_has_key(const fx_hashmap *hashmap, const fx_hashmap_key *key)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_HASHMAP, hashmap_has_key, hashmap, key);
|
FX_CLASS_DISPATCH_STATIC(
|
||||||
|
FX_TYPE_HASHMAP,
|
||||||
|
hashmap_has_key,
|
||||||
|
hashmap,
|
||||||
|
key);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t fx_hashmap_get_size(const fx_hashmap *hashmap)
|
size_t fx_hashmap_get_size(const fx_hashmap *hashmap)
|
||||||
@@ -368,7 +410,8 @@ bool fx_hashmap_is_empty(const fx_hashmap *hashmap)
|
|||||||
|
|
||||||
fx_iterator *fx_hashmap_begin(fx_hashmap *hashmap)
|
fx_iterator *fx_hashmap_begin(fx_hashmap *hashmap)
|
||||||
{
|
{
|
||||||
fx_hashmap_iterator *it_obj = fx_object_create(FX_TYPE_HASHMAP_ITERATOR);
|
fx_hashmap_iterator *it_obj
|
||||||
|
= fx_object_create(FX_TYPE_HASHMAP_ITERATOR);
|
||||||
struct fx_hashmap_iterator_p *it
|
struct fx_hashmap_iterator_p *it
|
||||||
= fx_object_get_private(it_obj, FX_TYPE_HASHMAP_ITERATOR);
|
= fx_object_get_private(it_obj, FX_TYPE_HASHMAP_ITERATOR);
|
||||||
|
|
||||||
@@ -391,9 +434,12 @@ fx_iterator *fx_hashmap_begin(fx_hashmap *hashmap)
|
|||||||
return it_obj;
|
return it_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct fx_queue_entry *first_entry = fx_queue_first(&first_bucket->bk_items);
|
struct fx_queue_entry *first_entry
|
||||||
struct fx_hashmap_bucket_item *first_item
|
= fx_queue_first(&first_bucket->bk_items);
|
||||||
= fx_unbox(struct fx_hashmap_bucket_item, first_entry, bi_entry);
|
struct fx_hashmap_bucket_item *first_item = fx_unbox(
|
||||||
|
struct fx_hashmap_bucket_item,
|
||||||
|
first_entry,
|
||||||
|
bi_entry);
|
||||||
if (!first_item) {
|
if (!first_item) {
|
||||||
memset(&it->item, 0x0, sizeof it->item);
|
memset(&it->item, 0x0, sizeof it->item);
|
||||||
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
|
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
|
||||||
@@ -435,8 +481,11 @@ static void hashmap_fini(fx_object *obj, void *priv)
|
|||||||
struct fx_queue_entry *entry = fx_queue_first(&b->bk_items);
|
struct fx_queue_entry *entry = fx_queue_first(&b->bk_items);
|
||||||
while (entry) {
|
while (entry) {
|
||||||
struct fx_hashmap_bucket_item *item = fx_unbox(
|
struct fx_hashmap_bucket_item *item = fx_unbox(
|
||||||
struct fx_hashmap_bucket_item, entry, bi_entry);
|
struct fx_hashmap_bucket_item,
|
||||||
struct fx_queue_entry *next_entry = fx_queue_next(entry);
|
entry,
|
||||||
|
bi_entry);
|
||||||
|
struct fx_queue_entry *next_entry
|
||||||
|
= fx_queue_next(entry);
|
||||||
fx_queue_delete(&b->bk_items, entry);
|
fx_queue_delete(&b->bk_items, entry);
|
||||||
|
|
||||||
if (map->h_key_dtor) {
|
if (map->h_key_dtor) {
|
||||||
@@ -444,7 +493,8 @@ static void hashmap_fini(fx_object *obj, void *priv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (map->h_value_dtor) {
|
if (map->h_value_dtor) {
|
||||||
map->h_value_dtor((void *)item->bi_value.value_data);
|
map->h_value_dtor(
|
||||||
|
(void *)item->bi_value.value_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(item);
|
free(item);
|
||||||
@@ -524,7 +574,8 @@ static enum fx_status iterator_erase(fx_iterator *obj)
|
|||||||
|
|
||||||
if (next_item) {
|
if (next_item) {
|
||||||
memcpy(&it->item.key, &next_item->bi_key, sizeof it->item.key);
|
memcpy(&it->item.key, &next_item->bi_key, sizeof it->item.key);
|
||||||
memcpy(&it->item.value, &next_item->bi_value,
|
memcpy(&it->item.value,
|
||||||
|
&next_item->bi_value,
|
||||||
sizeof it->item.value);
|
sizeof it->item.value);
|
||||||
|
|
||||||
it->_cbn = next_node;
|
it->_cbn = next_node;
|
||||||
|
|||||||
+17
-13
@@ -9,10 +9,10 @@
|
|||||||
#ifndef FX_DS_ARRAY_H_
|
#ifndef FX_DS_ARRAY_H_
|
||||||
#define FX_DS_ARRAY_H_
|
#define FX_DS_ARRAY_H_
|
||||||
|
|
||||||
#include <fx/core/iterator.h>
|
#include <fx/iterator.h>
|
||||||
#include <fx/core/macros.h>
|
#include <fx/macros.h>
|
||||||
#include <fx/core/misc.h>
|
#include <fx/misc.h>
|
||||||
#include <fx/core/status.h>
|
#include <fx/status.h>
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
@@ -51,11 +51,13 @@ FX_TYPE_DEFAULT_CONSTRUCTOR(fx_array, FX_TYPE_ARRAY);
|
|||||||
* @return A pointer to the new fx_array, or NULL if an error occurred.
|
* @return A pointer to the new fx_array, or NULL if an error occurred.
|
||||||
*/
|
*/
|
||||||
FX_API fx_array *fx_array_create_with_values(
|
FX_API fx_array *fx_array_create_with_values(
|
||||||
fx_object *const *values, size_t nr_values);
|
fx_object *const *values,
|
||||||
|
size_t nr_values);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all object references from an fx_array, resetting the size of the array to zero.
|
* Remove all object references from an fx_array, resetting the size of the
|
||||||
* The reference counts of all objects in the array will be decremented.
|
* array to zero. The reference counts of all objects in the array will be
|
||||||
|
* decremented.
|
||||||
*
|
*
|
||||||
* @param array The fx_array to clear.
|
* @param array The fx_array to clear.
|
||||||
*/
|
*/
|
||||||
@@ -116,11 +118,12 @@ FX_API fx_status fx_array_remove(fx_array *array, size_t at);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the object at the beginning of an fx_array. The reference count
|
* Removes the object at the beginning of an fx_array. The reference count
|
||||||
* of the removed object will be decremented. The remaining objects will be moved
|
* of the removed object will be decremented. The remaining objects will be
|
||||||
* to fill the empty space created by the object's removal.
|
* moved to fill the empty space created by the object's removal.
|
||||||
*
|
*
|
||||||
* @param array The fx_array to remove the object from.
|
* @param array The fx_array to remove the object from.
|
||||||
* @return FX_SUCCESS if the object was removed, or a status code describing any error that occurred.
|
* @return FX_SUCCESS if the object was removed, or a status code describing any
|
||||||
|
* error that occurred.
|
||||||
*/
|
*/
|
||||||
FX_API fx_status fx_array_remove_front(fx_array *array);
|
FX_API fx_status fx_array_remove_front(fx_array *array);
|
||||||
|
|
||||||
@@ -129,7 +132,8 @@ FX_API fx_status fx_array_remove_front(fx_array *array);
|
|||||||
* of the removed object will be decremented.
|
* of the removed object will be decremented.
|
||||||
*
|
*
|
||||||
* @param array The fx_array to remove the object from.
|
* @param array The fx_array to remove the object from.
|
||||||
* @return FX_SUCCESS if the object was removed, or a status code describing any error that occurred.
|
* @return FX_SUCCESS if the object was removed, or a status code describing any
|
||||||
|
* error that occurred.
|
||||||
*/
|
*/
|
||||||
FX_API fx_status fx_array_remove_back(fx_array *array);
|
FX_API fx_status fx_array_remove_back(fx_array *array);
|
||||||
|
|
||||||
@@ -162,8 +166,8 @@ FX_API fx_object *fx_array_pop(fx_array *array, size_t at);
|
|||||||
FX_API fx_object *fx_array_pop_front(fx_array *array);
|
FX_API fx_object *fx_array_pop_front(fx_array *array);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the object at the end of an fx_array, and returns a pointer to it. The
|
* Removes the object at the end of an fx_array, and returns a pointer to it.
|
||||||
* reference count of the removed object will NOT be decremented. The caller
|
* The reference count of the removed object will NOT be decremented. The caller
|
||||||
* becomes the owner of the array's reference to the object.
|
* becomes the owner of the array's reference to the object.
|
||||||
*
|
*
|
||||||
* @param array The fx_array to remove the object from.
|
* @param array The fx_array to remove the object from.
|
||||||
+11
-5
@@ -1,7 +1,7 @@
|
|||||||
#ifndef FX_DS_BITBUFFER_H_
|
#ifndef FX_DS_BITBUFFER_H_
|
||||||
#define FX_DS_BITBUFFER_H_
|
#define FX_DS_BITBUFFER_H_
|
||||||
|
|
||||||
#include <fx/core/macros.h>
|
#include <fx/macros.h>
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
@@ -13,12 +13,18 @@ FX_TYPE_CLASS_DECLARATION_END(fx_bitbuffer);
|
|||||||
|
|
||||||
FX_API fx_status fx_bitbuffer_put_bit(fx_bitbuffer *buf, int bit);
|
FX_API fx_status fx_bitbuffer_put_bit(fx_bitbuffer *buf, int bit);
|
||||||
FX_API fx_status fx_bitbuffer_put_bool(fx_bitbuffer *buf, bool b);
|
FX_API fx_status fx_bitbuffer_put_bool(fx_bitbuffer *buf, bool b);
|
||||||
FX_API fx_status fx_bitbuffer_put_int(
|
FX_API fx_status
|
||||||
fx_bitbuffer *buf, uint64_t v, unsigned int nr_bits);
|
fx_bitbuffer_put_int(fx_bitbuffer *buf, uint64_t v, unsigned int nr_bits);
|
||||||
FX_API fx_status fx_bitbuffer_put_bytes(
|
FX_API fx_status fx_bitbuffer_put_bytes(
|
||||||
fx_bitbuffer *buf, const void *p, size_t len, size_t bits_per_byte);
|
fx_bitbuffer *buf,
|
||||||
|
const void *p,
|
||||||
|
size_t len,
|
||||||
|
size_t bits_per_byte);
|
||||||
FX_API fx_status fx_bitbuffer_put_string(
|
FX_API fx_status fx_bitbuffer_put_string(
|
||||||
fx_bitbuffer *buf, const char *p, size_t len, size_t bits_per_char);
|
fx_bitbuffer *buf,
|
||||||
|
const char *p,
|
||||||
|
size_t len,
|
||||||
|
size_t bits_per_char);
|
||||||
|
|
||||||
FX_DECLS_END;
|
FX_DECLS_END;
|
||||||
|
|
||||||
+6
-3
@@ -1,8 +1,8 @@
|
|||||||
#ifndef FX_DS_BITMAP_H_
|
#ifndef FX_DS_BITMAP_H_
|
||||||
#define FX_DS_BITMAP_H_
|
#define FX_DS_BITMAP_H_
|
||||||
|
|
||||||
#include <fx/core/macros.h>
|
#include <fx/macros.h>
|
||||||
#include <fx/core/misc.h>
|
#include <fx/misc.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
FX_DECLS_BEGIN;
|
||||||
@@ -21,7 +21,10 @@ FX_API fx_bitmap *fx_bitmap_create(size_t nr_bits);
|
|||||||
FX_API void fx_bitmap_set_bit(fx_bitmap *map, size_t bit);
|
FX_API void fx_bitmap_set_bit(fx_bitmap *map, size_t bit);
|
||||||
FX_API void fx_bitmap_clear_bit(fx_bitmap *map, size_t bit);
|
FX_API void fx_bitmap_clear_bit(fx_bitmap *map, size_t bit);
|
||||||
FX_API void fx_bitmap_set_range(fx_bitmap *map, size_t first_bit, size_t nbits);
|
FX_API void fx_bitmap_set_range(fx_bitmap *map, size_t first_bit, size_t nbits);
|
||||||
FX_API void fx_bitmap_clear_range(fx_bitmap *map, size_t first_bit, size_t nbits);
|
FX_API void fx_bitmap_clear_range(
|
||||||
|
fx_bitmap *map,
|
||||||
|
size_t first_bit,
|
||||||
|
size_t nbits);
|
||||||
FX_API void fx_bitmap_set_all(fx_bitmap *map);
|
FX_API void fx_bitmap_set_all(fx_bitmap *map);
|
||||||
FX_API void fx_bitmap_clear_all(fx_bitmap *map);
|
FX_API void fx_bitmap_clear_all(fx_bitmap *map);
|
||||||
|
|
||||||
+8
-5
@@ -1,7 +1,7 @@
|
|||||||
#ifndef FX_DS_BUFFER_H_
|
#ifndef FX_DS_BUFFER_H_
|
||||||
#define FX_DS_BUFFER_H_
|
#define FX_DS_BUFFER_H_
|
||||||
|
|
||||||
#include <fx/core/macros.h>
|
#include <fx/macros.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
FX_DECLS_BEGIN;
|
||||||
@@ -18,16 +18,19 @@ FX_API fx_type fx_buffer_get_type(void);
|
|||||||
FX_API fx_buffer *fx_buffer_create(size_t item_sz);
|
FX_API fx_buffer *fx_buffer_create(size_t item_sz);
|
||||||
FX_API fx_buffer *fx_buffer_create_from_bytes(const void *p, size_t len);
|
FX_API fx_buffer *fx_buffer_create_from_bytes(const void *p, size_t len);
|
||||||
FX_API fx_buffer *fx_buffer_create_from_array(
|
FX_API fx_buffer *fx_buffer_create_from_array(
|
||||||
const void *p, size_t item_sz, size_t len);
|
const void *p,
|
||||||
|
size_t item_sz,
|
||||||
|
size_t len);
|
||||||
|
|
||||||
FX_API void *fx_buffer_steal(fx_buffer *buf);
|
FX_API void *fx_buffer_steal(fx_buffer *buf);
|
||||||
FX_API fx_status fx_buffer_reserve(fx_buffer *buf, size_t capacity);
|
FX_API fx_status fx_buffer_reserve(fx_buffer *buf, size_t capacity);
|
||||||
FX_API fx_status fx_buffer_resize(fx_buffer *buf, size_t length);
|
FX_API fx_status fx_buffer_resize(fx_buffer *buf, size_t length);
|
||||||
|
|
||||||
FX_API fx_status fx_buffer_append(fx_buffer *dest, const void *p, size_t count);
|
FX_API fx_status fx_buffer_append(fx_buffer *dest, const void *p, size_t count);
|
||||||
FX_API fx_status fx_buffer_prepend(fx_buffer *dest, const void *p, size_t count);
|
FX_API fx_status
|
||||||
FX_API fx_status fx_buffer_insert(
|
fx_buffer_prepend(fx_buffer *dest, const void *p, size_t count);
|
||||||
fx_buffer *dest, const void *p, size_t count, size_t at);
|
FX_API fx_status
|
||||||
|
fx_buffer_insert(fx_buffer *dest, const void *p, size_t count, size_t at);
|
||||||
FX_API fx_status fx_buffer_remove(fx_buffer *dest, size_t at, size_t count);
|
FX_API fx_status fx_buffer_remove(fx_buffer *dest, size_t at, size_t count);
|
||||||
FX_API fx_status fx_buffer_clear(fx_buffer *buf);
|
FX_API fx_status fx_buffer_clear(fx_buffer *buf);
|
||||||
|
|
||||||
+4
-3
@@ -1,9 +1,9 @@
|
|||||||
#ifndef FX_DS_DATETIME_H_
|
#ifndef FX_DS_DATETIME_H_
|
||||||
#define FX_DS_DATETIME_H_
|
#define FX_DS_DATETIME_H_
|
||||||
|
|
||||||
#include <fx/core/macros.h>
|
|
||||||
#include <fx/core/status.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <fx/macros.h>
|
||||||
|
#include <fx/status.h>
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
@@ -24,7 +24,8 @@ FX_TYPE_DEFAULT_CONSTRUCTOR(fx_datetime, FX_TYPE_DATETIME);
|
|||||||
|
|
||||||
FX_API fx_datetime *fx_datetime_parse(fx_datetime_format format, const char *s);
|
FX_API fx_datetime *fx_datetime_parse(fx_datetime_format format, const char *s);
|
||||||
FX_API void fx_datetime_to_string(
|
FX_API void fx_datetime_to_string(
|
||||||
const fx_datetime *dt, fx_datetime_format format,
|
const fx_datetime *dt,
|
||||||
|
fx_datetime_format format,
|
||||||
FX_TYPE_FWDREF(fx_stream) * dest);
|
FX_TYPE_FWDREF(fx_stream) * dest);
|
||||||
|
|
||||||
FX_API bool fx_datetime_is_localtime(const fx_datetime *dt);
|
FX_API bool fx_datetime_is_localtime(const fx_datetime *dt);
|
||||||
+12
-10
@@ -1,12 +1,12 @@
|
|||||||
#ifndef FX_DS_DICT_H_
|
#ifndef FX_DS_DICT_H_
|
||||||
#define FX_DS_DICT_H_
|
#define FX_DS_DICT_H_
|
||||||
|
|
||||||
#include <fx/core/bst.h>
|
#include <fx/bst.h>
|
||||||
#include <fx/core/macros.h>
|
#include <fx/collections/string.h>
|
||||||
#include <fx/core/misc.h>
|
#include <fx/macros.h>
|
||||||
#include <fx/core/queue.h>
|
#include <fx/misc.h>
|
||||||
#include <fx/core/status.h>
|
#include <fx/queue.h>
|
||||||
#include <fx/ds/string.h>
|
#include <fx/status.h>
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
@@ -27,9 +27,10 @@ FX_TYPE_CLASS_DECLARATION_END(fx_dict_iterator)
|
|||||||
#define FX_DICT_ITEM(k, v) {.key = (k), .value = (v)}
|
#define FX_DICT_ITEM(k, v) {.key = (k), .value = (v)}
|
||||||
#define FX_DICT_ITEM_END {.key = NULL, .value = NULL}
|
#define FX_DICT_ITEM_END {.key = NULL, .value = NULL}
|
||||||
|
|
||||||
#define fx_dict_foreach(it, dict) \
|
#define fx_dict_foreach(it, dict) \
|
||||||
for (int z__fx_unique_name() = fx_dict_iterator_begin(dict, it); \
|
for (int z__fx_unique_name() = fx_dict_iterator_begin(dict, it); \
|
||||||
(it)->key != NULL; fx_dict_iterator_next(it))
|
(it)->key != NULL; \
|
||||||
|
fx_dict_iterator_next(it))
|
||||||
|
|
||||||
typedef struct fx_dict_item {
|
typedef struct fx_dict_item {
|
||||||
const fx_string *key;
|
const fx_string *key;
|
||||||
@@ -46,7 +47,8 @@ FX_API fx_dict *fx_dict_create_with_items(const fx_dict_item *items);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
FX_API fx_status fx_dict_put(fx_dict *dict, const char *key, fx_object *value);
|
FX_API fx_status fx_dict_put(fx_dict *dict, const char *key, fx_object *value);
|
||||||
FX_API fx_status fx_dict_put_sk(fx_dict *dict, const fx_string *key, fx_object *value);
|
FX_API fx_status
|
||||||
|
fx_dict_put_sk(fx_dict *dict, const fx_string *key, fx_object *value);
|
||||||
FX_API fx_object *fx_dict_at(const fx_dict *dict, const char *key);
|
FX_API fx_object *fx_dict_at(const fx_dict *dict, const char *key);
|
||||||
FX_API fx_object *fx_dict_at_sk(const fx_dict *dict, const fx_string *key);
|
FX_API fx_object *fx_dict_at_sk(const fx_dict *dict, const fx_string *key);
|
||||||
FX_API fx_object *fx_dict_get(fx_dict *dict, const char *key);
|
FX_API fx_object *fx_dict_get(fx_dict *dict, const char *key);
|
||||||
+20
-13
@@ -1,11 +1,11 @@
|
|||||||
#ifndef FX_DS_HASHMAP_H_
|
#ifndef FX_DS_HASHMAP_H_
|
||||||
#define FX_DS_HASHMAP_H_
|
#define FX_DS_HASHMAP_H_
|
||||||
|
|
||||||
#include <fx/core/bst.h>
|
#include <fx/bst.h>
|
||||||
#include <fx/core/macros.h>
|
#include <fx/macros.h>
|
||||||
#include <fx/core/misc.h>
|
#include <fx/misc.h>
|
||||||
#include <fx/core/queue.h>
|
#include <fx/queue.h>
|
||||||
#include <fx/core/status.h>
|
#include <fx/status.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
FX_DECLS_BEGIN;
|
||||||
@@ -27,14 +27,15 @@ FX_TYPE_CLASS_DECLARATION_END(fx_hashmap_iterator)
|
|||||||
#define FX_HASHMAP_KEY(k, ks) {.key_data = (k), .key_size = (ks)}
|
#define FX_HASHMAP_KEY(k, ks) {.key_data = (k), .key_size = (ks)}
|
||||||
#define FX_HASHMAP_VALUE(v, vs) {.value_data = (v), .value_size = (vs)}
|
#define FX_HASHMAP_VALUE(v, vs) {.value_data = (v), .value_size = (vs)}
|
||||||
|
|
||||||
#define FX_HASHMAP_ITEM(k, ks, v, vs) \
|
#define FX_HASHMAP_ITEM(k, ks, v, vs) \
|
||||||
{.key = FX_HASHMAP_KEY(k, ks), .value = FX_HASHMAP_VALUE(v, vs)}
|
{.key = FX_HASHMAP_KEY(k, ks), .value = FX_HASHMAP_VALUE(v, vs)}
|
||||||
|
|
||||||
#define FX_HASHMAP_ITEM_END {.key = {0}, .value = {0}}
|
#define FX_HASHMAP_ITEM_END {.key = {0}, .value = {0}}
|
||||||
|
|
||||||
#define fx_hashmap_foreach(it, hashmap) \
|
#define fx_hashmap_foreach(it, hashmap) \
|
||||||
for (int z__fx_unique_name() = fx_hashmap_iterator_begin(hashmap, it); \
|
for (int z__fx_unique_name() = fx_hashmap_iterator_begin(hashmap, it); \
|
||||||
(it)->key != NULL; fx_hashmap_iterator_next(it))
|
(it)->key != NULL; \
|
||||||
|
fx_hashmap_iterator_next(it))
|
||||||
|
|
||||||
typedef void (*fx_hashmap_key_destructor)(void *);
|
typedef void (*fx_hashmap_key_destructor)(void *);
|
||||||
typedef void (*fx_hashmap_value_destructor)(void *);
|
typedef void (*fx_hashmap_value_destructor)(void *);
|
||||||
@@ -63,15 +64,21 @@ FX_API fx_type fx_hashmap_get_type(void);
|
|||||||
FX_API fx_type fx_hashmap_iterator_get_type(void);
|
FX_API fx_type fx_hashmap_iterator_get_type(void);
|
||||||
|
|
||||||
FX_API fx_hashmap *fx_hashmap_create(
|
FX_API fx_hashmap *fx_hashmap_create(
|
||||||
fx_hashmap_key_destructor key_dtor, fx_hashmap_value_destructor value_dtor);
|
fx_hashmap_key_destructor key_dtor,
|
||||||
|
fx_hashmap_value_destructor value_dtor);
|
||||||
FX_API fx_hashmap *fx_hashmap_create_with_items(const fx_hashmap_item *items);
|
FX_API fx_hashmap *fx_hashmap_create_with_items(const fx_hashmap_item *items);
|
||||||
|
|
||||||
FX_API fx_status fx_hashmap_put(
|
FX_API fx_status fx_hashmap_put(
|
||||||
fx_hashmap *hashmap, const fx_hashmap_key *key, const fx_hashmap_value *value);
|
fx_hashmap *hashmap,
|
||||||
|
const fx_hashmap_key *key,
|
||||||
|
const fx_hashmap_value *value);
|
||||||
FX_API const fx_hashmap_value *fx_hashmap_get(
|
FX_API const fx_hashmap_value *fx_hashmap_get(
|
||||||
const fx_hashmap *hashmap, const fx_hashmap_key *key);
|
const fx_hashmap *hashmap,
|
||||||
|
const fx_hashmap_key *key);
|
||||||
|
|
||||||
FX_API bool fx_hashmap_has_key(const fx_hashmap *hashmap, const fx_hashmap_key *key);
|
FX_API bool fx_hashmap_has_key(
|
||||||
|
const fx_hashmap *hashmap,
|
||||||
|
const fx_hashmap_key *key);
|
||||||
FX_API size_t fx_hashmap_get_size(const fx_hashmap *hashmap);
|
FX_API size_t fx_hashmap_get_size(const fx_hashmap *hashmap);
|
||||||
FX_API bool fx_hashmap_is_empty(const fx_hashmap *hashmap);
|
FX_API bool fx_hashmap_is_empty(const fx_hashmap *hashmap);
|
||||||
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#ifndef FX_DS_LIST_H_
|
#ifndef FX_DS_LIST_H_
|
||||||
#define FX_DS_LIST_H_
|
#define FX_DS_LIST_H_
|
||||||
|
|
||||||
#include <fx/core/iterator.h>
|
#include <fx/iterator.h>
|
||||||
#include <fx/core/macros.h>
|
#include <fx/macros.h>
|
||||||
#include <fx/core/status.h>
|
#include <fx/status.h>
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
@@ -39,9 +39,13 @@ FX_API fx_list_entry *fx_list_prev(const fx_list_entry *entry);
|
|||||||
FX_API size_t fx_list_length(const fx_list *q);
|
FX_API size_t fx_list_length(const fx_list *q);
|
||||||
|
|
||||||
FX_API fx_list_entry *fx_list_insert_before(
|
FX_API fx_list_entry *fx_list_insert_before(
|
||||||
fx_list *q, void *ptr, fx_list_entry *before);
|
fx_list *q,
|
||||||
|
void *ptr,
|
||||||
|
fx_list_entry *before);
|
||||||
FX_API fx_list_entry *fx_list_insert_after(
|
FX_API fx_list_entry *fx_list_insert_after(
|
||||||
fx_list *q, void *ptr, fx_list_entry *after);
|
fx_list *q,
|
||||||
|
void *ptr,
|
||||||
|
fx_list_entry *after);
|
||||||
|
|
||||||
FX_API fx_list_entry *fx_list_push_front(fx_list *q, void *ptr);
|
FX_API fx_list_entry *fx_list_push_front(fx_list *q, void *ptr);
|
||||||
FX_API fx_list_entry *fx_list_push_back(fx_list *q, void *ptr);
|
FX_API fx_list_entry *fx_list_push_back(fx_list *q, void *ptr);
|
||||||
+4
-2
@@ -1,7 +1,7 @@
|
|||||||
#ifndef FX_DS_NUMBER_H
|
#ifndef FX_DS_NUMBER_H
|
||||||
#define FX_DS_NUMBER_H
|
#define FX_DS_NUMBER_H
|
||||||
|
|
||||||
#include <fx/core/macros.h>
|
#include <fx/macros.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
FX_DECLS_BEGIN;
|
||||||
@@ -133,7 +133,9 @@ static inline fx_number *fx_number_create_size_t(size_t value)
|
|||||||
|
|
||||||
FX_API fx_number_type fx_number_get_number_type(const fx_number *number);
|
FX_API fx_number_type fx_number_get_number_type(const fx_number *number);
|
||||||
FX_API int fx_number_get_value(
|
FX_API int fx_number_get_value(
|
||||||
const fx_number *number, fx_number_type type, void *value_ptr);
|
const fx_number *number,
|
||||||
|
fx_number_type type,
|
||||||
|
void *value_ptr);
|
||||||
|
|
||||||
static inline int8_t fx_number_get_int8(const fx_number *number)
|
static inline int8_t fx_number_get_int8(const fx_number *number)
|
||||||
{
|
{
|
||||||
+5
-5
@@ -2,11 +2,11 @@
|
|||||||
#define FX_DS_STRING_H_
|
#define FX_DS_STRING_H_
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <fx/core/encoding.h>
|
#include <fx/encoding.h>
|
||||||
#include <fx/core/iterator.h>
|
#include <fx/iterator.h>
|
||||||
#include <fx/core/macros.h>
|
#include <fx/macros.h>
|
||||||
#include <fx/core/status.h>
|
#include <fx/status.h>
|
||||||
#include <fx/core/stringstream.h>
|
#include <fx/stringstream.h>
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#ifndef FX_DS_TREE_H_
|
#ifndef FX_DS_TREE_H_
|
||||||
#define FX_DS_TREE_H_
|
#define FX_DS_TREE_H_
|
||||||
|
|
||||||
#include <fx/core/macros.h>
|
#include <fx/collections/string.h>
|
||||||
#include <fx/core/misc.h>
|
#include <fx/macros.h>
|
||||||
#include <fx/core/queue.h>
|
#include <fx/misc.h>
|
||||||
#include <fx/ds/string.h>
|
#include <fx/queue.h>
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ FX_TYPE_CLASS_DECLARATION_END(fx_tree_iterator)
|
|||||||
|
|
||||||
#define FX_TREE_NODE_INIT ((fx_tree_node) {0})
|
#define FX_TREE_NODE_INIT ((fx_tree_node) {0})
|
||||||
|
|
||||||
#define FX_TREE_CONTAINER(t, m, v) \
|
#define FX_TREE_CONTAINER(t, m, v) \
|
||||||
((void *)((v) ? (uintptr_t)(v) - (offsetof(t, m)) : 0))
|
((void *)((v) ? (uintptr_t)(v) - (offsetof(t, m)) : 0))
|
||||||
|
|
||||||
typedef struct fx_tree_node {
|
typedef struct fx_tree_node {
|
||||||
@@ -50,7 +50,8 @@ FX_API fx_iterator *fx_tree_node_begin(fx_tree_node *node);
|
|||||||
FX_API const fx_iterator *fx_tree_node_cbegin(const fx_tree_node *node);
|
FX_API const fx_iterator *fx_tree_node_cbegin(const fx_tree_node *node);
|
||||||
|
|
||||||
FX_API fx_iterator *fx_tree_node_begin_recursive(fx_tree_node *node);
|
FX_API fx_iterator *fx_tree_node_begin_recursive(fx_tree_node *node);
|
||||||
FX_API const fx_iterator *fx_tree_node_cbegin_recursive(const fx_tree_node *node);
|
FX_API const fx_iterator *fx_tree_node_cbegin_recursive(
|
||||||
|
const fx_tree_node *node);
|
||||||
|
|
||||||
FX_DECLS_END;
|
FX_DECLS_END;
|
||||||
|
|
||||||
+26
-11
@@ -1,9 +1,9 @@
|
|||||||
#ifndef FX_DS_UUID_H_
|
#ifndef FX_DS_UUID_H_
|
||||||
#define FX_DS_UUID_H_
|
#define FX_DS_UUID_H_
|
||||||
|
|
||||||
#include <fx/core/macros.h>
|
#include <fx/collections/string.h>
|
||||||
#include <fx/core/status.h>
|
#include <fx/macros.h>
|
||||||
#include <fx/ds/string.h>
|
#include <fx/status.h>
|
||||||
|
|
||||||
#define FX_UUID_NBYTES 16
|
#define FX_UUID_NBYTES 16
|
||||||
#define FX_UUID_STRING_MAX 37
|
#define FX_UUID_STRING_MAX 37
|
||||||
@@ -29,19 +29,34 @@ FX_API fx_type fx_uuid_get_type(void);
|
|||||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_uuid, FX_TYPE_UUID);
|
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_uuid, FX_TYPE_UUID);
|
||||||
|
|
||||||
FX_API fx_uuid *fx_uuid_create_from_bytes(
|
FX_API fx_uuid *fx_uuid_create_from_bytes(
|
||||||
unsigned char u00, unsigned char u01, unsigned char u02,
|
unsigned char u00,
|
||||||
unsigned char u03, unsigned char u04, unsigned char u05,
|
unsigned char u01,
|
||||||
unsigned char u06, unsigned char u07, unsigned char u08,
|
unsigned char u02,
|
||||||
unsigned char u09, unsigned char u10, unsigned char u11, unsigned char u12,
|
unsigned char u03,
|
||||||
unsigned char u13, unsigned char u14, unsigned char u15);
|
unsigned char u04,
|
||||||
FX_API fx_uuid *fx_uuid_create_from_bytev(const unsigned char bytes[FX_UUID_NBYTES]);
|
unsigned char u05,
|
||||||
|
unsigned char u06,
|
||||||
|
unsigned char u07,
|
||||||
|
unsigned char u08,
|
||||||
|
unsigned char u09,
|
||||||
|
unsigned char u10,
|
||||||
|
unsigned char u11,
|
||||||
|
unsigned char u12,
|
||||||
|
unsigned char u13,
|
||||||
|
unsigned char u14,
|
||||||
|
unsigned char u15);
|
||||||
|
FX_API fx_uuid *fx_uuid_create_from_bytev(
|
||||||
|
const unsigned char bytes[FX_UUID_NBYTES]);
|
||||||
FX_API fx_uuid *fx_uuid_create_from_uuid_bytes(const fx_uuid_bytes *bytes);
|
FX_API fx_uuid *fx_uuid_create_from_uuid_bytes(const fx_uuid_bytes *bytes);
|
||||||
FX_API fx_uuid *fx_uuid_create_from_string(const fx_string *string);
|
FX_API fx_uuid *fx_uuid_create_from_string(const fx_string *string);
|
||||||
FX_API fx_uuid *fx_uuid_create_from_cstr(const char *s);
|
FX_API fx_uuid *fx_uuid_create_from_cstr(const char *s);
|
||||||
|
|
||||||
FX_API fx_status fx_uuid_to_cstr(const fx_uuid *uuid, char out[FX_UUID_STRING_MAX]);
|
FX_API fx_status fx_uuid_to_cstr(
|
||||||
|
const fx_uuid *uuid,
|
||||||
|
char out[FX_UUID_STRING_MAX]);
|
||||||
FX_API void fx_uuid_get_bytes(
|
FX_API void fx_uuid_get_bytes(
|
||||||
const fx_uuid *uuid, unsigned char bytes[FX_UUID_NBYTES]);
|
const fx_uuid *uuid,
|
||||||
|
unsigned char bytes[FX_UUID_NBYTES]);
|
||||||
FX_API void fx_uuid_get_uuid_bytes(const fx_uuid *uuid, fx_uuid_bytes *bytes);
|
FX_API void fx_uuid_get_uuid_bytes(const fx_uuid *uuid, fx_uuid_bytes *bytes);
|
||||||
FX_API fx_uuid_bytes *fx_uuid_ptr(fx_uuid *uuid);
|
FX_API fx_uuid_bytes *fx_uuid_ptr(fx_uuid *uuid);
|
||||||
|
|
||||||
+30
-10
@@ -1,6 +1,6 @@
|
|||||||
#include <fx/core/iterator.h>
|
#include <fx/collections/list.h>
|
||||||
#include <fx/core/queue.h>
|
#include <fx/iterator.h>
|
||||||
#include <fx/ds/list.h>
|
#include <fx/queue.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -109,7 +109,9 @@ static struct fx_list_entry *make_entry(void *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct fx_list_entry *list_insert_before(
|
static struct fx_list_entry *list_insert_before(
|
||||||
struct fx_list_p *q, void *ptr, struct fx_list_entry *before)
|
struct fx_list_p *q,
|
||||||
|
void *ptr,
|
||||||
|
struct fx_list_entry *before)
|
||||||
{
|
{
|
||||||
struct fx_list_entry *entry = make_entry(ptr);
|
struct fx_list_entry *entry = make_entry(ptr);
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
@@ -122,7 +124,9 @@ static struct fx_list_entry *list_insert_before(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct fx_list_entry *list_insert_after(
|
static struct fx_list_entry *list_insert_after(
|
||||||
struct fx_list_p *q, void *ptr, struct fx_list_entry *after)
|
struct fx_list_p *q,
|
||||||
|
void *ptr,
|
||||||
|
struct fx_list_entry *after)
|
||||||
{
|
{
|
||||||
struct fx_list_entry *entry = make_entry(ptr);
|
struct fx_list_entry *entry = make_entry(ptr);
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
@@ -226,7 +230,9 @@ static fx_status list_delete_item(struct fx_list_p *q, void *ptr)
|
|||||||
return FX_SUCCESS;
|
return FX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fx_status list_delete_entry(struct fx_list_p *q, struct fx_list_entry *entry)
|
static fx_status list_delete_entry(
|
||||||
|
struct fx_list_p *q,
|
||||||
|
struct fx_list_entry *entry)
|
||||||
{
|
{
|
||||||
fx_queue_delete(&q->l_queue, &entry->e_entry);
|
fx_queue_delete(&q->l_queue, &entry->e_entry);
|
||||||
q->l_len--;
|
q->l_len--;
|
||||||
@@ -314,15 +320,29 @@ size_t fx_list_length(const fx_list *q)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct fx_list_entry *fx_list_insert_before(
|
struct fx_list_entry *fx_list_insert_before(
|
||||||
fx_list *q, void *ptr, struct fx_list_entry *before)
|
fx_list *q,
|
||||||
|
void *ptr,
|
||||||
|
struct fx_list_entry *before)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_LIST, list_insert_before, q, ptr, before);
|
FX_CLASS_DISPATCH_STATIC(
|
||||||
|
FX_TYPE_LIST,
|
||||||
|
list_insert_before,
|
||||||
|
q,
|
||||||
|
ptr,
|
||||||
|
before);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct fx_list_entry *fx_list_insert_after(
|
struct fx_list_entry *fx_list_insert_after(
|
||||||
fx_list *q, void *ptr, struct fx_list_entry *after)
|
fx_list *q,
|
||||||
|
void *ptr,
|
||||||
|
struct fx_list_entry *after)
|
||||||
{
|
{
|
||||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_LIST, list_insert_after, q, ptr, after);
|
FX_CLASS_DISPATCH_STATIC(
|
||||||
|
FX_TYPE_LIST,
|
||||||
|
list_insert_after,
|
||||||
|
q,
|
||||||
|
ptr,
|
||||||
|
after);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct fx_list_entry *fx_list_push_front(fx_list *q, void *ptr)
|
struct fx_list_entry *fx_list_push_front(fx_list *q, void *ptr)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include <fx/core/stream.h>
|
#include <fx/collections/number.h>
|
||||||
#include <fx/ds/number.h>
|
#include <fx/stream.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <fx/core/stream.h>
|
#include <fx/collections/string.h>
|
||||||
#include <fx/core/stringstream.h>
|
#include <fx/stream.h>
|
||||||
#include <fx/ds/string.h>
|
#include <fx/stringstream.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|||||||
+17
-7
@@ -1,4 +1,4 @@
|
|||||||
#include <fx/ds/tree.h>
|
#include <fx/collections/tree.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -33,7 +33,9 @@ static void tree_set_root(struct fx_tree_p *tree, struct fx_tree_node *node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct fx_tree_node *next_node(
|
static const struct fx_tree_node *next_node(
|
||||||
const struct fx_tree_node *node, bool recursive, int *depth_diff)
|
const struct fx_tree_node *node,
|
||||||
|
bool recursive,
|
||||||
|
int *depth_diff)
|
||||||
{
|
{
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -101,7 +103,8 @@ static void remove_node(struct fx_tree_node *node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void reparent_children(
|
static void reparent_children(
|
||||||
struct fx_tree_node *old_parent, struct fx_tree_node *new_parent)
|
struct fx_tree_node *old_parent,
|
||||||
|
struct fx_tree_node *new_parent)
|
||||||
{
|
{
|
||||||
struct fx_tree_node *last = NODE_FIRST_CHILD(new_parent);
|
struct fx_tree_node *last = NODE_FIRST_CHILD(new_parent);
|
||||||
while (last && NODE_NEXT_SIBLING(last)) {
|
while (last && NODE_NEXT_SIBLING(last)) {
|
||||||
@@ -132,7 +135,9 @@ void fx_tree_set_root(fx_tree *tree, struct fx_tree_node *node)
|
|||||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_TREE, tree_set_root, tree, node);
|
FX_CLASS_DISPATCH_STATIC(FX_TYPE_TREE, tree_set_root, tree, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fx_tree_node_add_child(struct fx_tree_node *parent, struct fx_tree_node *child)
|
void fx_tree_node_add_child(
|
||||||
|
struct fx_tree_node *parent,
|
||||||
|
struct fx_tree_node *child)
|
||||||
{
|
{
|
||||||
if (NODE_PARENT(child)) {
|
if (NODE_PARENT(child)) {
|
||||||
return;
|
return;
|
||||||
@@ -152,7 +157,9 @@ void fx_tree_node_add_child(struct fx_tree_node *parent, struct fx_tree_node *ch
|
|||||||
NODE_NEXT_SIBLING(cur) = child;
|
NODE_NEXT_SIBLING(cur) = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fx_tree_node_add_sibling(struct fx_tree_node *node, struct fx_tree_node *to_add)
|
void fx_tree_node_add_sibling(
|
||||||
|
struct fx_tree_node *node,
|
||||||
|
struct fx_tree_node *to_add)
|
||||||
{
|
{
|
||||||
if (NODE_PARENT(to_add) || !NODE_PARENT(node)) {
|
if (NODE_PARENT(to_add) || !NODE_PARENT(node)) {
|
||||||
return;
|
return;
|
||||||
@@ -161,7 +168,9 @@ void fx_tree_node_add_sibling(struct fx_tree_node *node, struct fx_tree_node *to
|
|||||||
fx_tree_node_add_child(NODE_PARENT(node), to_add);
|
fx_tree_node_add_child(NODE_PARENT(node), to_add);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct fx_tree_node *fx_tree_node_get_child(struct fx_tree_node *node, size_t at)
|
struct fx_tree_node *fx_tree_node_get_child(
|
||||||
|
struct fx_tree_node *node,
|
||||||
|
size_t at)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
struct fx_tree_node *cur = NODE_FIRST_CHILD(node);
|
struct fx_tree_node *cur = NODE_FIRST_CHILD(node);
|
||||||
@@ -233,7 +242,8 @@ fx_iterator *fx_tree_node_begin_recursive(struct fx_tree_node *node)
|
|||||||
return it_obj;
|
return it_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fx_iterator *fx_tree_node_cbegin_recursive(const struct fx_tree_node *node)
|
const fx_iterator *fx_tree_node_cbegin_recursive(
|
||||||
|
const struct fx_tree_node *node)
|
||||||
{
|
{
|
||||||
return fx_tree_node_begin_recursive((struct fx_tree_node *)node);
|
return fx_tree_node_begin_recursive((struct fx_tree_node *)node);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <fx/core/stringstream.h>
|
#include <fx/collections/string.h>
|
||||||
#include <fx/ds/string.h>
|
#include <fx/collections/uuid.h>
|
||||||
#include <fx/ds/uuid.h>
|
#include <fx/stringstream.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user