+// Find the next used slot at given index or later. Returns pointer to
+// the slot. This allows for a reclaim function that may reclaim slot
+// items on the way to next used slot.
+void **vector_next_used(vector *pv,vector_index *index) {
+ if ( pv->entries == 0 || *index >= pv->size ) {
+ *index = pv->size;
+ return 0;
+ }
+ int levels = vector_levels( pv, pv->size );
+ for ( ; *index < pv->size; (*index)++ ) {
+ void **slot = vector_level_next_used(
+ pv, pv->entries, index, levels - 1, pv->size ) ;
+ if ( slot == 0 ) {
+ *index = pv->size; // reached the end of the vector
+ } else if ( *slot == 0 ) {
+ continue;
+ }
+ return slot;
+ }
+ return 0;
+}
+
+#if 1
+/**
+ * Advances a vector index to the prior used slot at or below the
+ * given level, starting from the indexed entry (inclusive) and down.
+ * The function will free any empty pages it discovers, and then
+ * update the index slots accordingly. The given index is advanced
+ * cyclically to match the found slot. The function returns a slot
+ * pointer to the used slot, if any, and 0 otherwise.
+ */
+static void **vector_level_prev_used(
+ vector *pv,
+ vector_page *page,
+ vector_index *index,
+ int level )
+{
+ void **p = (void**)&(*page)[ VECTOR_INDEX_PART( pv, index, level ) ];