added hawk_arr_itr_t, hawk_val_arr_itr_t and functions for them
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
33
lib/arr.c
33
lib/arr.c
@ -33,7 +33,6 @@
|
||||
#define keeper_t hawk_arr_keeper_t
|
||||
#define walker_t hawk_arr_walker_t
|
||||
|
||||
|
||||
#define TOB(arr,len) ((len)*(arr)->scale)
|
||||
#define DPTR(slot) ((slot)->val.ptr)
|
||||
#define DLEN(slot) ((slot)->val.len)
|
||||
@ -482,6 +481,38 @@ void hawk_arr_clear (hawk_arr_t* arr)
|
||||
arr->tally = 0;
|
||||
}
|
||||
|
||||
hawk_ptl_t* hawk_arr_getfirstelem (hawk_arr_t* arr, hawk_arr_itr_t* itr)
|
||||
{
|
||||
hawk_oow_t i;
|
||||
|
||||
for (i = 0; i < arr->size; i++)
|
||||
{
|
||||
if (arr->slot[i])
|
||||
{
|
||||
itr->idx = i;
|
||||
return &arr->slot[i]->val;
|
||||
}
|
||||
}
|
||||
|
||||
return HAWK_NULL;
|
||||
}
|
||||
|
||||
hawk_ptl_t* hawk_arr_getnextelem (hawk_arr_t* arr, hawk_arr_itr_t* itr)
|
||||
{
|
||||
hawk_oow_t i;
|
||||
|
||||
for (i = itr->idx + 1; i < arr->size; i++)
|
||||
{
|
||||
if (arr->slot[i])
|
||||
{
|
||||
itr->idx = i;
|
||||
return &arr->slot[i]->val;
|
||||
}
|
||||
}
|
||||
|
||||
return HAWK_NULL;
|
||||
}
|
||||
|
||||
hawk_oow_t hawk_arr_walk (hawk_arr_t* arr, walker_t walker, void* ctx)
|
||||
{
|
||||
hawk_arr_walk_t w = HAWK_ARR_WALK_FORWARD;
|
||||
|
||||
@ -134,7 +134,6 @@ typedef hawk_oow_t (*hawk_arr_sizer_t) (
|
||||
hawk_oow_t hint /**< sizing hint */
|
||||
);
|
||||
|
||||
|
||||
typedef struct hawk_arr_style_t hawk_arr_style_t;
|
||||
|
||||
struct hawk_arr_style_t
|
||||
@ -160,6 +159,12 @@ enum hawk_arr_style_kind_t
|
||||
|
||||
typedef enum hawk_arr_style_kind_t hawk_arr_style_kind_t;
|
||||
|
||||
struct hawk_arr_itr_t
|
||||
{
|
||||
hawk_oow_t idx;
|
||||
};
|
||||
|
||||
typedef struct hawk_arr_itr_t hawk_arr_itr_t;
|
||||
|
||||
typedef hawk_arr_walk_t (*hawk_arr_walker_t) (
|
||||
hawk_arr_t* arr /* array */,
|
||||
@ -346,6 +351,23 @@ HAWK_EXPORT void hawk_arr_clear (
|
||||
hawk_arr_t* arr
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_arr_getfirstelem() function returns the pointer to the first element holder
|
||||
* in an array.
|
||||
*/
|
||||
HAWK_EXPORT hawk_ptl_t* hawk_arr_getfirstelem (
|
||||
hawk_arr_t* arr, /**< array */
|
||||
hawk_arr_itr_t* itr /**< iterator*/
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_arr_getnextelem() function returns the pointer to the next element holder.
|
||||
*/
|
||||
HAWK_EXPORT hawk_ptl_t* hawk_arr_getnextelem (
|
||||
hawk_arr_t* arr, /**< array */
|
||||
hawk_arr_itr_t* itr /**< iterator*/
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_arr_walk() function calls the \a walker function for each
|
||||
* element in the array beginning from the first. The \a walker function
|
||||
@ -356,7 +378,7 @@ HAWK_EXPORT void hawk_arr_clear (
|
||||
HAWK_EXPORT hawk_oow_t hawk_arr_walk (
|
||||
hawk_arr_t* arr,
|
||||
hawk_arr_walker_t walker,
|
||||
void* ctx
|
||||
void* ctx
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
23
lib/hawk.h
23
lib/hawk.h
@ -371,7 +371,6 @@ typedef hawk_map_itr_t hawk_val_map_itr_t;
|
||||
*/
|
||||
#define HAWK_VAL_MAP_ITR_VAL(itr) ((const hawk_val_t*)HAWK_MAP_VPTR((itr)->pair))
|
||||
|
||||
|
||||
/**
|
||||
* The hawk_val_map_data_type_t type defines the type of
|
||||
* map value data for the #hawk_val_map_data_t structure.
|
||||
@ -405,6 +404,16 @@ struct hawk_val_map_data_t
|
||||
|
||||
typedef struct hawk_val_map_data_t hawk_val_map_data_t;
|
||||
|
||||
/**
|
||||
* The hawk_val_arr_itr_t type defines the iterator to array value fields.
|
||||
*/
|
||||
typedef struct hawk_val_arr_itr_t hawk_val_arr_itr_t;
|
||||
|
||||
struct hawk_val_arr_itr_t
|
||||
{
|
||||
hawk_arr_itr_t itr;
|
||||
hawk_ptl_t elem;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
@ -3378,6 +3387,18 @@ HAWK_EXPORT hawk_ooi_t hawk_rtx_getarrvaltally (
|
||||
hawk_val_t* arr
|
||||
);
|
||||
|
||||
HAWK_EXPORT hawk_val_arr_itr_t* hawk_rtx_getfirstarrvalitr (
|
||||
hawk_rtx_t* rtx,
|
||||
hawk_val_t* arr,
|
||||
hawk_val_arr_itr_t* itr
|
||||
);
|
||||
|
||||
HAWK_EXPORT hawk_val_arr_itr_t* hawk_rtx_getnextarrvalitr (
|
||||
hawk_rtx_t* rtx,
|
||||
hawk_val_t* arr,
|
||||
hawk_val_arr_itr_t* itr
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_rtx_makerefval() function creates a reference value.
|
||||
* \return value on success, #HAWK_NULL on failure
|
||||
|
||||
@ -361,6 +361,7 @@ static int fnc_array (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
tmp = hawk_rtx_makearrval(rtx, ((nargs > 0)? nargs: -1));
|
||||
if (HAWK_UNLIKELY(!tmp)) return -1; /* hard failure */
|
||||
|
||||
/* 1-based. leave the first slot unassigned */
|
||||
for (i = 0; i < nargs; i++)
|
||||
{
|
||||
if (HAWK_UNLIKELY(hawk_rtx_setarrvalfld(rtx, tmp, i + 1, hawk_rtx_getarg(rtx, i)) == HAWK_NULL))
|
||||
|
||||
@ -516,7 +516,7 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t*
|
||||
* for example, `hawk -v RS=separator -f script f1.txt f2.txt`
|
||||
* the console handler is invoked over all the specified files.
|
||||
* if `separator` is not found when the end of `f1.txt` is reached,
|
||||
* `f2.txt` is opened and read. When the handler returns the
|
||||
* `f2.txt` is opened and read. When the handler returns the
|
||||
* first part of the second file, it must indicate this special
|
||||
* condition. if it's not indicated, it goes on without breaking
|
||||
* the record at the end of the first file.
|
||||
|
||||
Reference in New Issue
Block a user