+int pvector_reclaim_any(pvector *pv,unsigned long ix,void *item,void *data) {
+ free( item );
+ return 0;
+}
+
+void pvector_append(pvector *pv,void *value) {
+ pvector_resize( pv, pv->size + 1, 0, 0 );
+ pvector_set( pv, pv->size - 1, value );
+}
+
+// copy block of n items from src[si] to dst[di]
+// no efficiency hacks
+void pvector_copy(pvector *dst,unsigned long di,
+ pvector *src,unsigned long si,unsigned long n) {
+ if ( dst != src || di < si ) {
+ while ( n-- != 0 ) {
+ pvector_set( dst, di++, pvector_get( src, si++ ) );
+ }
+ } else if ( di > si ){
+ di += n - 1;
+ si += n - 1;
+ while ( n-- != 0 ) {
+ pvector_set( dst, di--, pvector_get( src, si-- ) );
+ }
+ }
+}
+
+void pvector_dump(pvector *pv,int (*itemdump)(unsigned long,void *)) {
+ unsigned long index = 0;
+ for ( ; index < pv->size; index++ ) {
+ void **slot = pvector_next_used( pv, &index, 0, 0 );
+ if ( slot == 0 ) {
+ break;
+ }
+ itemdump( index, *slot );
+ }
+}
+
+//// Quicksort
+
+// Returns 1 for "in order", 0 for equal, and -1 for "wrong order"
+typedef int (*comparfn)(void *,void *);
+
+static void pvector_qsort_part(
+ pvector *pv,comparfn compar,
+ unsigned long low,unsigned long high)
+{
+ if ( low >= high ) {
+ return;
+ }
+ unsigned long lo = low;
+ unsigned long m = high - 1;
+
+ if ( lo >= m ) {
+ return;
+ }
+
+ unsigned long hi = m - 1;
+ void **mp = pvector_entry( pv, m );
+ void **lop, **hip;
+ for ( ;; ) {
+ // Find index of first item "above" mp scanning from lo and up
+ for ( ; lo < m; lo++ ) {
+ lop = pvector_entry( pv, lo );
+ if ( compar( *lop, *mp ) < 0 ) {
+ break;
+ }
+ }
+ // if lo == m, then lop is wrong!!
+ // Find index of first item "below" mp scanning from hi and down
+ for ( ; hi > lo; hi-- ) {
+ hip = pvector_entry( pv, hi );
+ if ( compar( *mp, *hip ) < 0 ) {
+ break;
+ }
+ }
+ if ( lo >= hi ) {
+ if ( lo < m ) {
+ void *x = *lop;
+ *lop = *mp;
+ *mp = x;
+ m = lo;
+ }
+ break;
+ }
+ void *x = *lop;
+ *lop = *hip;
+ *hip = x;
+ }
+ pvector_qsort_part( pv, compar, low, m );
+ pvector_qsort_part( pv, compar, m+1, high );
+}
+
+void pvector_qsort(pvector *pv,int (*compar)(void *,void *)) {
+ pvector_qsort_part( pv, compar, 0, pv->size );
+}