X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vector%2Fvector.h;h=62e119529ce01adc98bd48935b33d9cf467d5755;hb=a0be49ff8fda77c328424c09d6d0ad4a9f7e8f66;hp=d84c08c1f8222603d8490015732b435f7bfa8ffc;hpb=d8c1ccad095640b40192055bff9ad37e98216970;p=rrq%2Frrqmisc.git diff --git a/vector/vector.h b/vector/vector.h index d84c08c..62e1195 100644 --- a/vector/vector.h +++ b/vector/vector.h @@ -6,11 +6,13 @@ * of index pages. The indexing is done using "unsigned long" indexes. */ +#ifndef VECTOR_LEVEL_BITS /*! * Macro: VECTOR_LEVEL_BITS * This defines the number of bits in the indexing bit field. */ -#define VECTOR_LEVEL_BITS 4 +#define VECTOR_LEVEL_BITS 8 +#endif /*! * Type: vector_index @@ -60,15 +62,14 @@ typedef struct _vector { } vector; /*! - * Find the next used slot at given index or later. With a reclaim - * function, it will be invoked for verifying that the item is - * actually in use, in which case it returns 1. Otherwise it should - * reclaim any memory for the item and return 0; + * Find the nearest used (non-null) slot at given or higher index. */ -void **vector_next_used( - vector *pv,vector_index *index, - int (*reclaim)(vector *pv,vector_index index,void *item,void *data), - void *data ); +extern void **vector_next_used(vector *pv,vector_index *index); + +/*! + * Find the nearest used (non-null) slot at given or lower index. + */ +extern void **vector_prev_used(vector *pv,vector_index *index); /*! * Function: int vector_resize( @@ -98,7 +99,7 @@ void **vector_next_used( * duly changed. Otherwise the function retains the current size and * returns -index-1 for the index of the veto-ed entry. */ -int vector_resize( +extern int vector_resize( vector *pv, vector_index new_size, int (*reclaim)(vector *pv,vector_index index,void *item,void *data), void *data ); @@ -118,30 +119,51 @@ int vector_resize( extern void **vector_entry(vector *pv,vector_index index); /*! - * Function: vector_index vector_size(vector *pv) - * \param pv - the vector record + * Macro: vector_size(v) + * \param v - the vector record * \returns the size of the vector. */ -inline vector_index vector_size(vector *pv) { - return pv->size; -} +#define vector_size(pv) ((vector_index) (pv)->size) -void vector_set(vector *pv,vector_index index,void *value); +extern void vector_set(vector *pv,vector_index index,void *value); -void *vector_get(vector *pv,vector_index index); +// Set value at index but return the old value +extern void *vector_get_set(vector *pv,vector_index index,void *value); -void vector_append(vector *pv,void *value); +extern void *vector_get(vector *pv,vector_index index); -void vector_copy(vector *dst,vector_index di, - vector *src,vector_index si,vector_index n); +extern void vector_append(vector *pv,void *value); -void vector_dump(vector *pv, - int (*itemdump)(const vector_index ,const void *)); +extern void vector_copy( + vector *dst,vector_index di, + vector *src,vector_index si, + vector_index n); -void vector_qsort(vector *pv,int (*compar)(const void *,const void *)); +/** + * Invoking the itemdup function for all used (non-null) slots. + */ +extern void vector_dump( + vector *pv, + void (*itemdump)(const vector_index ,const void *)); + +extern void vector_qsort(vector *pv,int (*compar)(const void *,const void *)); -void vector_iterate(vector *pv, - int (*itemfn)(vector_index,void*,void*), - void*); +/*! + * Function: void vector_iterate(vector *pv, + * vector_index start, + * int (*itemfn)(vector_index,void*,void*), + * void*); + * + * Steps through the vector item by item invoking the given function + * for each. Continues stepping while the item function returns 0. + */ +extern void vector_iterate( + vector *pv, vector_index start, + int (*itemfn)(vector_index,void *item,void *data), + void *data); + +extern void *vector_bsearch( + vector *pv, vector_index *index, const void *key, + int (*compare)(const void *key, const void *item)); #endif