* implementation assumes LE integer layout.
*/
typedef union {
- unsigned int whole;
- unsigned char level[4];
+ unsigned long whole; // 64-bit unsigned integer
+ unsigned char level[8];
} pvector_index;
/*!
* to 256^N content entries.
*/
typedef struct _pvector {
- unsigned int size; //!< Limit for the logical entries[]
+ unsigned long size; //!< Limit for the logical entries[]
pvector_page *entries; //!< Pointer to entries indexing
} pvector;
#define PV_PART(p,i) (((unsigned char*)&i)[p])
/*!
- * Function: int pvector_resize( pvector *pv,unsigned int new_size,
- * int (*reclaim)(pvector *,int,void*) )
+ * 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;
+ */
+void **pvector_next_used(
+ pvector *pv,unsigned long *index,
+ int (*reclaim)(pvector *pv,unsigned long index,void *item,void *data),
+ void *data );
+
+/*!
+ * Function: int pvector_resize(
+ * pvector *pv,unsigned long new_size,
+ * int (*reclaim)(pvector *,unsigned long,void *item,void *data),
+ * void *data )
* \param pv
* \param new_size
* \param reclaim
+ * \param data
*
* Tries to resize the given pvector to a new size. This may result in
* the introduction or removal of indexing pages, so that the leveling
* reclaim function is invoked successively for these. The reclaim
* function must, in addition to memory-managing the entry, return 0
* upon success and non-zero to veto the attempted pvector size
- * change.
+ * change. The data argument is passed on to the reclaim function.
*
* The pvector_resize function returns 0 on success, with the size
* duly changed. Otherwise the function retains the current size and
* returns -index-1 for the index of the veto-ed entry.
*/
int pvector_resize(
- pvector *pv,unsigned int new_size,
- int (*reclaim)(pvector *,int,void*) );
+ pvector *pv, unsigned long new_size,
+ int (*reclaim)(pvector *pv,unsigned long index,void *item,void *data),
+ void *data );
/*!
- * Function: void **pvector_entry(pvector *pv,unsigned int index)
+ * Function: void **pvector_entry(pvector *pv,unsigned long index)
* \param pv - the pvector record
* \param index - the slot index
*
* that slot pointers are only valid while the pvector size is
* unchanged.
*/
-extern void **pvector_entry(pvector *pv,unsigned int index);
+extern void **pvector_entry(pvector *pv,unsigned long index);
/*!
- * Function: unsigned int pvector_size(pvector *pv)
+ * Function: unsigned long pvector_size(pvector *pv)
* \param pv - the pvector record
* \returns the size of the pvector.
*/
-inline unsigned int pvector_size(pvector *pv) {
+inline unsigned long pvector_size(pvector *pv) {
return pv->size;
}
-void pvector_set(pvector *pv,unsigned int index,void *value);
+void pvector_set(pvector *pv,unsigned long index,void *value);
+
+void *pvector_get(pvector *pv,unsigned long index);
+
+void pvector_append(pvector *pv,void *value);
+
+void pvector_copy(pvector *dst,unsigned long di,
+ pvector *src,unsigned long si,unsigned long n);
+
+void pvector_dump(pvector *pv,int (*itemdump)(unsigned long ,void *));
-void *pvector_get(pvector *pv,unsigned int index);
+void pvector_qsort(pvector *pv,int (*compar)(void *,void *));
#endif