* 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
* Macro: VECTOR_INDEX_BITS
* This defines the number of bits of a vector index
*/
-#define VECTOR_INDEX_BITS sizeof( vector_index )
+#define VECTOR_INDEX_BITS ( sizeof( vector_index ) * 8 )
/*!
* Macro: VECTOR_INDEX_FIELDS
*/
typedef void* vector_page[ VECTOR_SLOTS ];
-/*!
- * Type: vector_field
- * This is VECTOR_LEVEL_BITS size bit field
- */
-typedef struct { int bits:VECTOR_LEVEL_BITS; } vector_field;
-
-/*!
- * Type: vector_indexing
- *
- * A vector index is ether viewed in whole as an VECTOR_INDEX_BITS wide
- * unsigned, or in levels as a packed array of vector_field index
- * parts. This implementation assumes LE integer layout.
- */
-typedef union {
- vector_index whole; // as a whole
- vector_field level[ VECTOR_INDEX_FIELDS ]; // qua bits fields
-} vector_indexing;
-
-// The indexing part for level part p in index i
-#define VECTOR_INDEX_PART(i,p) (((vector_indexing*)(i))->level[ p ].bits)
-
/*!
* Type: 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(
* 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 );
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)
+
+extern void vector_set(vector *pv,vector_index index,void *value);
-void vector_set(vector *pv,vector_index index,void *value);
+// Set value at index but return the old value
+extern void *vector_get_set(vector *pv,vector_index index,void *value);
-void *vector_get(vector *pv,vector_index index);
+extern void *vector_get(vector *pv,vector_index index);
-void vector_append(vector *pv,void *value);
+extern void vector_append(vector *pv,void *value);
-void vector_copy(vector *dst,vector_index di,
- vector *src,vector_index si,vector_index n);
+extern void vector_copy(
+ vector *dst,vector_index di,
+ vector *src,vector_index si,
+ vector_index n);
-void vector_dump(vector *pv,
- int (*itemdump)(const vector_index ,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 *));
-void vector_qsort(vector *pv,int (*compar)(const void *,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