- slot = vector_entry( &v, 24 );
- itemdump( 24, SLOTSTR(slot) );
-
- slot = vector_entry( &v, 25 );
- itemdump( 25, SLOTSTR(slot) );
-
- slot = vector_entry( &v, 300 );
- itemdump( 300, SLOTSTR( slot ) );
-
- //#define vector_size(pv) ((vector_index) (pv)->size)
- OUT( "vector size: %ld\n", vector_size( &v ) );
-
- // void *vector_get_set(vector *pv,vector_index index,void *value);
- item = vector_get_set( &v, 25, "another value" );
- // void *vector_get(vector *pv,vector_index index);
- OUT( "old: \"%s\", new: \"%s\"\n",
- (char*)item, (char*)vector_get( &v, 25 ) );
-
- // void vector_append(vector *pv,void *value);
- vector_append( &v, "the very last item" );
- OUT( "vector size: %ld\n", vector_size( &v ) );
- my_vector_dump( &v, itemdump );
-
- vector v2 = { 200, 0 };
- // void vector_copy(
- // vector *dst,vector_index di,
- // vector *src,vector_index si,
- // vector_index n);
- vector_copy( &v2, 20, &v, 10, 20 );
- my_vector_dump( &v2, itemdump );
-
- vector_resize( &v2, 0, itemreclaim, 0 ); // Reset vector v2
- my_vector_dump( &v2, itemdump );
-
- vector_append( &v2, "9 the very last item" );
- vector_append( &v2, "3 the very last item" );
- vector_append( &v2, "4 the very last item" );
- vector_append( &v2, "6 the very last item" );
- vector_append( &v2, "5 the very last item" );
- vector_resize( &v2, vector_size( &v2 ) + 3, 0, 0 );
- vector_append( &v2, "2 the very last item" );
- vector_append( &v2, "8 the very last item" );
- vector_append( &v2, "1 the very last item" );
- vector_append( &v2, 0 );
- vector_append( &v2, "7 the very last item" );
- vector_append( &v2, "0 the very last item" );
- my_vector_dump( &v2, itemdump );
-
- // void vector_qsort(vector *pv,int (*compar)(const void *,const void *));
- OUT( "sorted:" );
- vector_qsort( &v2, itemcmp );
- my_vector_dump( &v2, itemdump );
-
- // void vector_iterate(vector *pv,
- // vector_index start,
- // int (*itemfn)(vector_index,void *item,void *data),
- // void *data);
- OUT( "showing all slots\n" );
- vector_iterate( &v2, 4, itemiter, 0 );
-
- // void *vector_bsearch(vector *pv,vector_index *index,const void *key,
- // int (*compare)(const void *key, const void *item));
- char *pfx[5] = { "4", "9", "0", "3", "10" };
- for ( i = 0; i < ( sizeof( pfx ) / sizeof( char* ) ); i++ ) {
- char *prefix = pfx[i];
- vector_index index = 0;
- OUT( "lookup prefix \"%s\":\n", prefix );
- item = vector_bsearch( &v2, &index, prefix, itemfind );
- OUT( "[%ld] %p %s\n", index, item, ( item? (char*)item : "(null)" ) );
+ slot = vector_entry( &v, 24 );
+ itemdump( 24, SLOTSTR(slot) );
+
+ slot = vector_entry( &v, 25 );
+ itemdump( 25, SLOTSTR(slot) );
+
+ slot = vector_entry( &v, 300 );
+ itemdump( 300, SLOTSTR( slot ) );
+
+ //#define vector_size(pv) ((vector_index) (pv)->size)
+ OUT( "vector size: %ld\n", vector_size( &v ) );
+
+ // void *vector_get(vector *pv,vector_index index);
+ // void *vector_get_set(vector *pv,vector_index index,void *value);
+ item = vector_get( &v, 25 );
+ OUT( "old item 25 is %p %s\n", item, (char*)item );
+ item = "another value";
+ OUT( "new item 25 is %p %s\n", item, (char*)item );
+ item = vector_get_set( &v, 25, item );
+ OUT( "got item 25 as %p %s\n", item, (char*)item );
+ item = vector_get( &v, 25 );
+ OUT( "now item 25 is %p %s\n", item, (char*)item );
+
+ // void vector_append(vector *pv,void *value);
+ item = "the very last item";
+ OUT( "appending %p %s\n", item, (char*)item );
+ vector_append( &v, item );
+
+ OUT( "vector size: %ld\n", vector_size( &v ) );
+ my_vector_dump( &v, itemdump );
+
+ vector v2 = { variant, 200, 0 };
+ // void vector_copy(
+ // vector *dst,vector_index di,
+ // vector *src,vector_index si,
+ // vector_index n);
+ vector_copy( &v2, 20, &v, 10, 20 );
+ my_vector_dump( &v2, itemdump );
+
+ vector_resize( &v2, 0, itemreclaim, 0 ); // Reset vector v2
+ my_vector_dump( &v2, itemdump );
+
+ vector_append( &v2, "9 the very last item" );
+ vector_append( &v2, "3 the very last item" );
+ vector_append( &v2, "4 the very last item" );
+ vector_append( &v2, "6 the very last item" );
+ vector_append( &v2, "5 the very last item" );
+ vector_resize( &v2, vector_size( &v2 ) + 3, 0, 0 );
+ vector_append( &v2, "2 the very last item" );
+ vector_append( &v2, "8 the very last item" );
+ vector_append( &v2, "1 the very last item" );
+ vector_append( &v2, 0 );
+ vector_append( &v2, "7 the very last item" );
+ vector_append( &v2, "0 the very last item" );
+ my_vector_dump( &v2, itemdump );
+
+ // void vector_qsort(vector*,int (*compar)(const void *,const void *));
+ OUT( "sorted:" );
+ vector_qsort( &v2, itemcmp );
+ my_vector_dump( &v2, itemdump );
+
+ // void vector_iterate(vector *pv,
+ // vector_index start,
+ // int (*itemfn)(vector_index,void *item,void *data),
+ // void *data);
+ OUT( "showing all slots\n" );
+ vector_iterate( &v2, 4, itemiter, 0 );
+
+ // void *vector_bsearch(vector *pv,vector_index *index,const void *key,
+ // int (*compare)(const void *key, const void *item));
+ char *pfx[5] = { "4", "9", "0", "3", "10" };
+ for ( i = 0; i < ( sizeof( pfx ) / sizeof( char* ) ); i++ ) {
+ char *prefix = pfx[i];
+ vector_index index = 0;
+ OUT( "lookup prefix \"%s\":\n", prefix );
+ item = vector_bsearch( &v2, &index, prefix, itemfind );
+ OUT( "[%ld] %p %s\n", index, item,
+ ( item? (char*)item : "(null)" ) );
+ }
+
+ // Clear out the vectors
+ (void) vector_resize( &v, 0, itemreclaim, (void*)0 );
+ (void) vector_resize( &v2, 0, itemreclaim, (void*)0 );