#include <stdlib.h>
#include <string.h>
-#include "hashvector.h"
+#include "HashVector.h"
typedef struct _ipslot {
int family;
} ipslot;
static unsigned long voidp_hashcode(void *this,void *key) {
- return hashvector_hashcode( key, sizeof( ipslot ) );
+ return HashVector_hashcode( key, sizeof( ipslot ) );
}
static void* voidp_itemkey(void *this,void *item) {
return snprintf( buffer, limit, "%p", item );
}
-static int shrink(vector *pv,unsigned long index,void *item,void *data) {
+static int shrink(Vector *pv,unsigned long index,void *item,void *data) {
if ( item ) {
if ( item == HV_HOLE ) {
- ((hashvector*) data)->holes--;
+ ((HashVector*) data)->holes--;
} else {
free( item );
- ((hashvector*) data)->fill--;
+ ((HashVector*) data)->fill--;
}
}
return 0;
}
int main(int argc,char **argv) {
- itemkeyfun voidpfun = {
+ ItemKeyFun voidpfun = {
.hashcode = voidp_hashcode,
.itemkey = voidp_itemkey,
.haskey = voidp_haskey,
.releasekey = voidp_releasekey,
.tostring = voidp_tostring
};
- hashvector hv = {
+ HashVector hv = {
.table = { 1, 4, 0 },
.fill = 0,
.holes = 0,
}
item->family = i;
memcpy( item->data, "10.10.10.1", 10 );
- hashvector_add( &hv, item );
+ HashVector_add( &hv, item );
}
for ( i = 256; i < 260; i++ ) {
- vector_index index = i;
- void ** slot = vector_next_used( &hv.table, &index );
+ VectorIndex index = i;
+ void ** slot = Vector_next_used( &hv.table, &index );
if ( slot && *slot != HV_HOLE ) {
- hashvector_delete( &hv, *slot );
+ HashVector_delete( &hv, *slot );
}
}
- vector_resize( &hv.table, 256, shrink, &hv );
+ Vector_resize( &hv.table, 256, shrink, &hv );
return 0;
}
#include <stdlib.h>
#include <stdio.h>
-#include <relation.h>
+#include <Relation.h>
#include <stringitem.h>
char *val(void* t) {
}
}
-void prdropout(const vector_index index,const void *t) {
+void prdropout(const VectorIndex index,const void *t) {
prtuple( ".. ", (tuple*)t );
}
-void add_relation(relation *r,char *p,char *c) {
+void add_Relation(Relation *r,char *p,char *c) {
tuple *t = tuple_create( 2, p, c);
prtuple( "Adding: ", t );
- vector *dropped = relation_add( r, t );
+ Vector *dropped = Relation_add( r, t );
if ( dropped ) {
fprintf( stderr, "Knockout %ld tuples\n", dropped->size );
- vector_dump( dropped, prdropout );
- vector_resize( dropped, 0, 0, 0 );
+ Vector_dump( dropped, prdropout );
+ Vector_resize( dropped, 0, 0, 0 );
free( dropped );
}
}
} tuple2;
int main(int argc,char **argv) {
- relation *rltn2 = relation_create(
- tupleschema_create(
+ Relation *rltn2 = Relation_create(
+ TupleSchema_create(
2, tuple_create( 2, (void*) &stringitem, (void*) &stringitem ) ) );
- relation_add_constraint( rltn2, 0, 1 );
- add_relation( rltn2, "benton", "holly" );
- add_relation( rltn2, "benton", "molly");
- add_relation( rltn2, "gully", "holly");
- add_relation( rltn2, "gully", "vanitha");
- vector_index index = 0;
+ Relation_add_constraint( rltn2, 0, 1 );
+ add_Relation( rltn2, "benton", "holly" );
+ add_Relation( rltn2, "benton", "molly");
+ add_Relation( rltn2, "gully", "holly");
+ add_Relation( rltn2, "gully", "vanitha");
+ VectorIndex index = 0;
tuple2 q1 = {{ "benton", 0 }};
tuple *t;
prtuple( "Simple query: ", &q1.tup );
for ( ; index < rltn2->content.table.size; index++ ) {
- t = relation_next( rltn2, &index, &q1.tup );
+ t = Relation_next( rltn2, &index, &q1.tup );
prtuple( ".. ", t );
}
// Test null query
fprintf( stderr, "Null query: (null)\n" );
for ( index = 0 ; index < rltn2->content.table.size; index++ ) {
- t = relation_next( rltn2, &index, 0 );
+ t = Relation_next( rltn2, &index, 0 );
prtuple( ".. ", t );
}
// Test Generic query
q1 = (tuple2) {{ 0, 0 }};
prtuple( "Generic query: ", &q1.tup );
for ( index = 0 ; index < rltn2->content.table.size; index++ ) {
- t = relation_next( rltn2, &index, &q1.tup );
+ t = Relation_next( rltn2, &index, &q1.tup );
prtuple( ".. ", t );
}
// Test deletion
q1 = (tuple2) {{ "gully", 0 }};
prtuple( "Deletion query: ", &q1.tup );
- vector *deleted = relation_delete( rltn2, &q1.tup );
+ Vector *deleted = Relation_delete( rltn2, &q1.tup );
for ( index = 0 ; index < rltn2->content.table.size; index++ ) {
- t = relation_next( rltn2, &index, 0 );
+ t = Relation_next( rltn2, &index, 0 );
prtuple( ".. ", t );
}
for ( index = 0 ; index < deleted->size; index++ ) {
- tuple **p = (tuple**) vector_next_used( deleted, &index );
+ tuple **p = (tuple**) Vector_next_used( deleted, &index );
prtuple( "** ", p? *p : 0 );
}
return 0;
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
-#include "vector.h"
+#include "Vector.h"
typedef struct _ipslot {
int family;
} ipslot;
static struct {
- vector data;
+ Vector data;
int fill;
} table;
ipslot *p = (ipslot *) malloc( sizeof( ipslot ) );
memmove( p, tmp, sizeof( ipslot ) );
if ( table.data.size == table.fill ) {
- (void) vector_resize( &table.data, table.fill + 256, 0, 0 );
+ (void) Vector_resize( &table.data, table.fill + 256, 0, 0 );
}
- vector_set( &table.data, table.fill++, p );
+ Vector_set( &table.data, table.fill++, p );
}
static void load_file(const char *filename) {
}
}
-static int int_reclaim(vector *pv,unsigned long index,void *item,void *data) {
+static int int_reclaim(Vector *pv,unsigned long index,void *item,void *data) {
return 0;
}
-static void dumpitem(const vector_index index,const void *item) {
+static void dumpitem(const VectorIndex index,const void *item) {
fprintf( stdout, "[%ld] %p\n", index, item );
}
-static void dump_ipslot(const vector_index index,const void *item) {
+static void dump_ipslot(const VectorIndex index,const void *item) {
static char buffer[100];
ipslot *ip = (ipslot*) item;
const char *p = inet_ntop( ip->family, ip->data, buffer, 100 );
}
int main(int argc,char **argv) {
- vector test = { 0 };
- vector_resize( &test, 100, 0, 0 );
- vector_set( &test, 5, (void*) 500 );
- vector_set( &test, 55, (void*) 600 );
- vector_resize( &test, 300, 0, 0 );
- vector_set( &test, 55, (void*) 650 );
- vector_resize( &test, 30000, 0, 0 );
- vector_set( &test, 22255, (void*) 26 );
- vector_dump( &test, dumpitem );
- vector_resize( &test, 100, int_reclaim, 0 );
- vector_set( &test, 5, (void*) 2 );
- vector_dump( &test, dumpitem );
+ Vector test = { 0 };
+ Vector_resize( &test, 100, 0, 0 );
+ Vector_set( &test, 5, (void*) 500 );
+ Vector_set( &test, 55, (void*) 600 );
+ Vector_resize( &test, 300, 0, 0 );
+ Vector_set( &test, 55, (void*) 650 );
+ Vector_resize( &test, 30000, 0, 0 );
+ Vector_set( &test, 22255, (void*) 26 );
+ Vector_dump( &test, dumpitem );
+ Vector_resize( &test, 100, int_reclaim, 0 );
+ Vector_set( &test, 5, (void*) 2 );
+ Vector_dump( &test, dumpitem );
int i;
for ( i = 1; i < argc; i++ ) {
load_file( argv[ i ] );
}
- vector_dump( &table.data, dump_ipslot );
+ Vector_dump( &table.data, dump_ipslot );
return 0;
}
/**
- * This is a collection of tests of the relation functions.
+ * This is a collection of tests of the Relation functions.
*/
#include <stdlib.h>
#include <stringitem.h>
-#include <relation.h>
+#include <Relation.h>
#define SIZE(x) (sizeof(x)/sizeof(void*))
-static char *tuple2string(relation *r,tuple *t) {
+static char *tuple2string(Relation *r,tuple *t) {
#define LIMIT 10000
static char tmp[10][ LIMIT ];
static int i = 0;
return tmp[i++];
}
-static void query_report(relation *r,tuple *query) {
- vector_index i;
+static void query_report(Relation *r,tuple *query) {
+ VectorIndex i;
for ( i = 0; i < r->content.table.size; i++ ) {
- tuple *t = hashvector_next( &r->content, &i, query );
+ tuple *t = HashVector_next( &r->content, &i, query );
fprintf( stderr, "check %s\n", tuple2string( r, t ) );
}
}
-static void query_report_all(relation *r,tuple *query[]) {
+static void query_report_all(Relation *r,tuple *query[]) {
int j;
for ( j = 0; query[j]; j++ ) {
fprintf( stderr, "query %s\n", tuple2string( r, query[j] ) );
}
}
-// Report any knocked out tuples from relation_add or relation_delete
-// This will also clear and free the result vector.
-static void knockout_report(relation *r,vector *v) {
- vector_index i;
+// Report any knocked out tuples from Relation_add or Relation_delete
+// This will also clear and free the result Vector.
+static void knockout_report(Relation *r,Vector *v) {
+ VectorIndex i;
if ( v ) {
for ( i = 0; i < v->size; i++ ) {
- tuple **t = (tuple **) vector_next_used( v, &i );
+ tuple **t = (tuple **) Vector_next_used( v, &i );
fprintf( stderr, "knock %s\n", tuple2string( r, t? *t : 0 ) );
}
- vector_resize( v, 0, vector_clear_any, 0 );
+ Vector_resize( v, 0, Vector_clear_any, 0 );
free( v );
}
}
// Test addition with several tuples, terminated by 0
-static void test_relation_add(relation *r,tuple *query[]) {
+static void test_Relation_add(Relation *r,tuple *query[]) {
int j;
for ( j = 0; query[j]; j++ ) {
fprintf( stderr, "add %s\n", tuple2string( r, query[j] ) );
- knockout_report( r, relation_add( r, query[j] ) );
+ knockout_report( r, Relation_add( r, query[j] ) );
}
}
// Test deletion with several queries, terminated by 0
-static void test_relation_delete(relation *r,tuple *query[]) {
+static void test_Relation_delete(Relation *r,tuple *query[]) {
int j;
for ( j = 0; query[j]; j++ ) {
fprintf( stderr, "delete %s\n", tuple2string( r, query[j] ) );
- knockout_report( r, relation_delete( r, query[j] ) );
+ knockout_report( r, Relation_delete( r, query[j] ) );
}
}
TUPLE( 0, "d" ),
0
};
- relation rel2 = RELATION( &stringitem, &stringitem );
+ Relation rel2 = RELATION( &stringitem, &stringitem );
- test_relation_add( &rel2, data2 );
+ test_Relation_add( &rel2, data2 );
query_report( &rel2, 0 );
query_report_all( &rel2, query2 );
- test_relation_delete( &rel2, query2 );
+ test_Relation_delete( &rel2, query2 );
// AxBxC
tuple *data3[] = {
TUPLE( "f", "b", "d" ),
0
};
- relation rel3 = RELATION( &stringitem, &stringitem, &stringitem );
- relation_add_constraint( &rel3, 1, 1, 0 ); // AxB -> C
- relation_add_constraint( &rel3, 1, 0, 1 ); // AxC -> B
+ Relation rel3 = RELATION( &stringitem, &stringitem, &stringitem );
+ Relation_add_constraint( &rel3, 1, 1, 0 ); // AxB -> C
+ Relation_add_constraint( &rel3, 1, 0, 1 ); // AxC -> B
- test_relation_add( &rel3, data3 );
+ test_Relation_add( &rel3, data3 );
query_report( &rel3, 0 );
query_report_all( &rel3, query3 );
- test_relation_delete( &rel3, query3 );
+ test_Relation_delete( &rel3, query3 );
return 0;
}
/**
- * A sequence of tests of the vector.h functions.
+ * A sequence of tests of the Vector.h functions.
*/
#include <stdio.h>
#include <string.h>
-#include <vector.h>
+#include <Vector.h>
#define OUT(...) fprintf( stderr, __VA_ARGS__ )
// dump an item; return 0 to stop
-static void itemdump(const vector_index index,const void *slot) {
+static void itemdump(const VectorIndex index,const void *slot) {
if ( slot ) {
OUT ( "[%ld] %s\n", index, (const char*) slot );
}
}
// pretend-reclaim item and return data (as int)
-static int itemreclaim(vector *pv,vector_index index,void *item,void *data) {
+static int itemreclaim(Vector *pv,VectorIndex index,void *item,void *data) {
int r = data? 1 : 0;
OUT( "reclaim [%ld] (%p) => %d\n", index, item, r );
return r;
}
// Iterator function
-static int itemiter(vector_index index,void *item,void *data) {
+static int itemiter(VectorIndex index,void *item,void *data) {
char *s = "";
if ( item ) {
s = (char*) item;
return strncmp( a, b, (an<bn)? an : bn );
}
-// Dump a vector with a header line
-static void my_vector_dump(
- vector *vp,
- void (*itemdump)(const vector_index index,const void *slot) )
+// Dump a Vector with a header line
+static void my_Vector_dump(
+ Vector *vp,
+ void (*itemdump)(const VectorIndex index,const void *slot) )
{
- OUT( "vector %p has %ld slots\n", vp, vector_size(vp) );
- vector_dump( vp, itemdump );
+ OUT( "Vector %p has %ld slots\n", vp, Vector_size(vp) );
+ Vector_dump( vp, itemdump );
}
static char *item25 = "this is first item";
int variant = 0;
for ( ; variant < 4; variant++ ) {
OUT( "variant = %d ========================\n", variant );
- vector v = { variant, 100, 0 }; // Create an empty vector of 100 slots.
+ Vector v = { variant, 100, 0 }; // Create an empty Vector of 100 slots.
//OUT( "VECTOR_LEVEL_BITS = %d\n", VECTOR_LEVEL_BITS );
- //OUT( "sizeof( vector_index ) = %ld\n", sizeof( vector_index ) );
+ //OUT( "sizeof( VectorIndex ) = %ld\n", sizeof( VectorIndex ) );
//OUT( "VECTOR_INDEX_BITS - %ld\n", VECTOR_INDEX_BITS );
//OUT( "VECTOR_INDEX_FIELDS = %ld\n", VECTOR_INDEX_FIELDS );
OUT( "VECTOR_SLOTS = %ld\n", VECTOR_SLOTS( &v ) );
- // OUT( "sizeof( vector_page ) = %ld\n", sizeof( vector_page ) );
- OUT( "sizeof( vector ) = %ld\n", sizeof( vector ) );
+ // OUT( "sizeof( Vector_page ) = %ld\n", sizeof( Vector_page ) );
+ OUT( "sizeof( Vector ) = %ld\n", sizeof( Vector ) );
void ** slot;
void *item;
int i;
- OUT( "vector v has 100 empty slots\n" );
+ OUT( "Vector v has 100 empty slots\n" );
- // void vector_dump(vector *pv,
- // int (*itemdump)(const vector_index ,const void *));
- // void **vector_next_used(vector *pv,vector_index *index);
- my_vector_dump( &v, itemdump );
+ // void Vector_dump(Vector *pv,
+ // int (*itemdump)(const VectorIndex ,const void *));
+ // void **Vector_next_used(Vector *pv,VectorIndex *index);
+ my_Vector_dump( &v, itemdump );
- //void vector_set(vector *pv,vector_index index,void *value);
+ //void Vector_set(Vector *pv,VectorIndex index,void *value);
item = item25;
- vector_set( &v, 25, item );
+ Vector_set( &v, 25, item );
OUT( "assigned 25 to %p %s\n", item, (char*)item );
- // void **vector_prev_used(vector *pv,vector_index *index);
+ // void **Vector_prev_used(Vector *pv,VectorIndex *index);
int t0[6] = { 0, 25, 50, 99, 100, 1000 };
- OUT( "vector_next_used:\n" );
+ OUT( "Vector_next_used:\n" );
for ( i = 0; i < 6; i++ ) {
- vector_index index = t0[i];
- slot = vector_next_used( &v, &index );
+ VectorIndex index = t0[i];
+ slot = Vector_next_used( &v, &index );
OUT( " [%d] => [%ld] %p\n", t0[i], index, slot? *slot : 0 );
}
- OUT( "vector_prev_used:\n" );
+ OUT( "Vector_prev_used:\n" );
for ( i = 0; i < 6; i++ ) {
- vector_index index = t0[i];
- slot = vector_prev_used( &v, &index );
+ VectorIndex index = t0[i];
+ slot = Vector_prev_used( &v, &index );
OUT( " [%d] => [%ld] %p\n", t0[i], index, slot? *slot : 0 );
}
item = item75;
- vector_set( &v, 75, item );
+ Vector_set( &v, 75, item );
OUT( "assigned 75 to %p %s\n", item, (char*)item );
- my_vector_dump( &v, itemdump );
+ my_Vector_dump( &v, itemdump );
- OUT( "vector_next_used:\n" );
+ OUT( "Vector_next_used:\n" );
for ( i = 0; i < 6; i++ ) {
- vector_index index = t0[i];
- slot = vector_next_used( &v, &index );
+ VectorIndex index = t0[i];
+ slot = Vector_next_used( &v, &index );
OUT( " [%d] => [%ld] %p\n", t0[i], index, slot? *slot : 0 );
}
- OUT( "vector_prev_used:\n" );
+ OUT( "Vector_prev_used:\n" );
for ( i = 0; i < 6; i++ ) {
- vector_index index = t0[i];
- slot = vector_prev_used( &v, &index );
+ VectorIndex index = t0[i];
+ slot = Vector_prev_used( &v, &index );
OUT( " [%d] => [%ld] %p\n", t0[i], index, slot? *slot : 0 );
}
- OUT( "shrinking the vector:\n" );
- // int vector_resize(
- // vector *pv, vector_index new_size,
- // int (*reclaim)(vector *pv,vector_index index,
+ OUT( "shrinking the Vector:\n" );
+ // int Vector_resize(
+ // Vector *pv, VectorIndex new_size,
+ // int (*reclaim)(Vector *pv,VectorIndex index,
// void *item, void *data),
// void *data );
- i = vector_resize( &v, 50, itemreclaim, (void*)1 );
+ i = Vector_resize( &v, 50, itemreclaim, (void*)1 );
OUT( "shrink to 50 (reclaim refused) = %d\n", i );
- i = vector_resize( &v, 50, itemreclaim, (void*)0 );
+ i = Vector_resize( &v, 50, itemreclaim, (void*)0 );
OUT( "shrink to 50 (accept reclaim) = %d\n", i );
- i = vector_resize( &v, 508, 0, 0 );
+ i = Vector_resize( &v, 508, 0, 0 );
OUT( "grow to 508 (no reclaim) = %d\n", i );
- // void **vector_entry(vector *pv,vector_index index);
+ // void **Vector_entry(Vector *pv,VectorIndex index);
#define SLOTSTR(slot) (slot? ((*slot)? *slot : "(nil)") : "(unassigned)" )
- slot = vector_entry( &v, 24 );
+ slot = Vector_entry( &v, 24 );
itemdump( 24, SLOTSTR(slot) );
- slot = vector_entry( &v, 25 );
+ slot = Vector_entry( &v, 25 );
itemdump( 25, SLOTSTR(slot) );
- slot = vector_entry( &v, 300 );
+ 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 ) );
+ //#define Vector_size(pv) ((VectorIndex) (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 );
+ // void *Vector_get(Vector *pv,VectorIndex index);
+ // void *Vector_get_set(Vector *pv,VectorIndex 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 );
+ item = Vector_get_set( &v, 25, item );
OUT( "got item 25 as %p %s\n", item, (char*)item );
- item = vector_get( &v, 25 );
+ item = Vector_get( &v, 25 );
OUT( "now item 25 is %p %s\n", item, (char*)item );
- // void vector_append(vector *pv,void *value);
+ // 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 *));
+ 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,VectorIndex di,
+ // Vector *src,VectorIndex si,
+ // VectorIndex 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 );
+ 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 Vector_iterate(Vector *pv,
+ // VectorIndex start,
+ // int (*itemfn)(VectorIndex,void *item,void *data),
// void *data);
OUT( "showing slots from 4 to 12\n" );
- vector_iterate( &v2, 4, itemiter, 0 );
+ Vector_iterate( &v2, 4, itemiter, 0 );
- // void *vector_bsearch(vector *pv,vector_index *index,const void *key,
+ // void *Vector_bsearch(Vector *pv,VectorIndex *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;
+ VectorIndex index = 0;
OUT( "lookup prefix \"%s\":\n", prefix );
- item = vector_bsearch( &v2, &index, prefix, itemfind );
+ 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 );
+ // Clear out the Vectors
+ (void) Vector_resize( &v, 0, itemreclaim, (void*)0 );
+ (void) Vector_resize( &v2, 0, itemreclaim, (void*)0 );
}
return 0;
}
*
* \param index is a pointer to the index to advance.
* \
- * \param key is the query key
+ * \param key is the Query key
*
* \returns the next matching item, or \b 0 if none, with the index
* updated.
#include <Query.h>
#include <BindingTable.h>
-enum next_state {
+enum NextState {
/**
* This state tells the "next" function that it should capture the
* incoming BindingTable state and provide the initial Binding of
restore
};
-//enum compound_state { reset, started, ended };
-
/**
- * A struct query_callbacks record defines the callbacks for a
- * specific query type.
+ * A struct Query_callbacks record defines the callbacks for a
+ * specific Query type.
*/
-struct query_callbacks {
+struct QueryCallbacks {
/**
- * \brief Callback function to reclaim the query memory for a
- * given query.
+ * \brief Callback function to reclaim the Query memory for a
+ * given Query.
*
- * \param this is the specific \ref query concerned.
+ * \param this is the specific \ref Query concerned.
*
* Ground queries recalim their own state memory. Composite
* queries first propagate the reclaim call to its components, and
* thereafter reclaim their local state memory.
*/
- void (*reclaim)(query *this);
- void (*start)(query *this,BindingTable *bt,enum next_state s);
+ void (*reclaim)(Query *this);
+ void (*start)(Query *this,BindingTable *bt,enum NextState s);
/**
* \brief Callback function to update the Binding table with a
* succession of alternative bindings.
*
- * \param this is the specific \ref query concerned.
+ * \param this is the specific \ref Query concerned.
*
* \param bt is the Binding table to set bindings in.
*
* \returns 1 if a new Binding is provided and 0 otherwise.
*
* This function is called repeatedly for successively obtaining
- * the alternative bindings that satisfy the query. The "initial"
+ * the alternative bindings that satisfy the Query. The "initial"
* state sub-command tells the function to capture the incoming
* BindingTable state so that the function can later restore it
* upon the "restore" sub-command. Upon the "initial" command, the
* return 1 after any successful Binding setup, and return 0 when
* it cannot setup any (more) Binding.
*/
- int (*next)(query *this,BindingTable *bt,enum next_state state);
+ int (*next)(Query *this,BindingTable *bt,enum NextState state);
};
/* ==================== AssignmentQuery ==================== */
typedef struct {
- struct query_callbacks *def;
+ struct QueryCallbacks *def;
int arity;
tuple *names;
tuple *values;
} AssignmentQuery;
// Release any memory.
-static void AssignmentQuery_reclaim(query *this) {
+static void AssignmentQuery_reclaim(Query *this) {
AssignmentQuery *q = (AssignmentQuery*) this;
free( q->saved );
free( this );
// Make names have given values and return 1. If any name has a
// different value then return 0. Values are strings.
static int AssignmentQuery_next(
- query *this,BindingTable *bt,enum next_state state) {
+ Query *this,BindingTable *bt,enum NextState state) {
AssignmentQuery *q = (AssignmentQuery*) this;
switch ( state ) {
case initial:
return 0;
}
-static struct query_callbacks AssignmentQuery_def = {
+static struct QueryCallbacks AssignmentQuery_def = {
.reclaim = AssignmentQuery_reclaim,
.next = AssignmentQuery_next
};
/**
- * Return a query object representing an assignment of one or more
+ * Return a Query object representing an assignment of one or more
* variables.
*/
-query *query_assign(int arity,tuple *names,tuple *values) {
+Query *Query_assign(int arity,tuple *names,tuple *values) {
AssignmentQuery *q = (AssignmentQuery*)
malloc( sizeof( AssignmentQuery ) );
(*q) = (AssignmentQuery) {
.values = values,
.saved = 0
};
- return (query*) q;
+ return (Query*) q;
}
/* ==================== conjunction ==================== */
typedef struct {
- struct query_callbacks *def;
+ struct QueryCallbacks *def;
int active;
int size;
- query **conjuncts;
+ Query **conjuncts;
} ConjunctionQuery;
-static void ConjunctionQuery_reclaim(query *this) {
+static void ConjunctionQuery_reclaim(Query *this) {
ConjunctionQuery *q = (ConjunctionQuery*) this;
int i;
for ( i = 0; i < q->size; i++ ) {
}
static int ConjunctionQuery_next(
- query *this,BindingTable *bt,enum next_state state)
+ Query *this,BindingTable *bt,enum NextState state)
{
ConjunctionQuery *q = (ConjunctionQuery*) this;
int i = q->size - 1;
- enum next_state s = subsequent;
+ enum NextState s = subsequent;
switch ( state ) {
case initial:
q->active = 1;
return 0;
}
-static struct query_callbacks ConjunctionQuery_def = {
+static struct QueryCallbacks ConjunctionQuery_def = {
.reclaim = ConjunctionQuery_reclaim,
.next = ConjunctionQuery_next
};
-query *query_and(int n,...) {
+Query *Query_and(int n,...) {
va_list args;
ConjunctionQuery *q = (ConjunctionQuery *)
malloc( sizeof( ConjunctionQuery ) );
.def = &ConjunctionQuery_def,
.active = 0,
.size = n,
- .conjuncts = (query**) malloc( n * sizeof( query* ) )
+ .conjuncts = (Query**) malloc( n * sizeof( Query* ) )
};
int i;
va_start( args, n );
for ( i = 0; i < n; i++ ) {
- q->conjuncts[i] = va_arg( args, query* );
+ q->conjuncts[i] = va_arg( args, Query* );
}
va_end( args );
- return (query*) q;
+ return (Query*) q;
}
/* ==================== disjunction ==================== */
typedef struct {
- struct query_callbacks *def;
+ struct QueryCallbacks *def;
int index;
int size;
- query **disjuncts;
+ Query **disjuncts;
} DisjunctionQuery;
-static void DisjunctionQuery_reclaim(query *this) {
+static void DisjunctionQuery_reclaim(Query *this) {
DisjunctionQuery *q = (DisjunctionQuery*) this;
int i;
for ( i = 0; i < q->size; i++ ) {
}
static int DisjunctionQuery_next(
- query *this,BindingTable *bt,enum next_state state) {
+ Query *this,BindingTable *bt,enum NextState state) {
DisjunctionQuery *q = (DisjunctionQuery*) this;
int i = q->index;
- enum next_state s = subsequent;
+ enum NextState s = subsequent;
switch ( state ) {
case initial:
i = 0;
return 0;
}
-static struct query_callbacks DisjunctionQuery_def = {
+static struct QueryCallbacks DisjunctionQuery_def = {
.reclaim = DisjunctionQuery_reclaim,
.next = DisjunctionQuery_next,
};
-query *query_or(int n,...) {
+Query *Query_or(int n,...) {
va_list args;
DisjunctionQuery *q = (DisjunctionQuery *)
malloc( sizeof( DisjunctionQuery ) );
.def = &DisjunctionQuery_def,
.index = -1,
.size = n,
- .disjuncts = (query**) malloc( n * sizeof( query* ) ),
+ .disjuncts = (Query**) malloc( n * sizeof( Query* ) ),
};
int i;
va_start( args, n );
for ( i = 0; i < n; i++ ) {
- q->disjuncts[i] = va_arg( args, query* );
+ q->disjuncts[i] = va_arg( args, Query* );
}
va_end( args );
- return (query*) q;
+ return (Query*) q;
}
/* ==================== Relation access ==================== */
typedef struct {
- struct query_callbacks *def;
+ struct QueryCallbacks *def;
Relation *rel;
VectorIndex index;
tuple *names;
} RelationQuery;
// Release any memory.
-static void RelationQuery_reclaim(query *this) {
+static void RelationQuery_reclaim(Query *this) {
RelationQuery *q = (RelationQuery*) this;
free( q->saved );
free( this );
// Make names have given values and return 1. If any name has a
// different value then return 0. Values are strings.
static int RelationQuery_next(
- query *this,BindingTable *bt,enum next_state state) {
+ Query *this,BindingTable *bt,enum NextState state) {
RelationQuery *q = (RelationQuery*) this;
int arity = ((TupleSchema*) q->rel->content.type)->arity;
VectorIndex index = q->index + 1;
// Fall through
case subsequent:
for ( ; index < q->rel->content.table.size; index++ ) {
- tuple *values = relation_next( q->rel, &index, q->values );
+ tuple *values = Relation_next( q->rel, &index, q->values );
if ( values ) {
q->index = index;
AssignmentQuery_assign( bt, arity, q->names, values, 1 );
return 0;
}
-static struct query_callbacks RelationQuery_def = {
+static struct QueryCallbacks RelationQuery_def = {
.reclaim = RelationQuery_reclaim,
.next = RelationQuery_next
};
/**
- * Return a query object representing an Relation of one or more
+ * Return a Query object representing an Relation of one or more
* variables.
*/
-query *query_Relation(Relation *r,tuple *names,tuple *values) {
+Query *Query_Relation(Relation *r,tuple *names,tuple *values) {
RelationQuery *q = (RelationQuery*) malloc( sizeof( RelationQuery ) );
(*q) = (RelationQuery) {
.def = &RelationQuery_def,
.values = values,
.saved = 0
};
- return (query*) q;
+ return (Query*) q;
}
-#ifndef query_H
-#define query_H
+#ifndef Query_H
+#define Query_H
#include <TupleSchema.h>
#include <Relation.h>
-struct query_callbacks;
+struct QueryCallbacks;
/**
- * A query is an implementation of a generic ABI over relations. It's
+ * A Query is an implementation of a generic ABI over relations. It's
* more or less a "virtual Relation" representing a logical composite
* access of actual relations, and as such its active part is held in
- * a separate \ref querytype record similar to how \ref ItemKeyFun
+ * a separate \ref Querytype record similar to how \ref ItemKeyFun
* records define valye types.
*/
typedef struct {
- struct query_callbacks *def;
-} query;
+ struct QueryCallbacks *def;
+} Query;
/**
- * \brief Creates an assignment query.
+ * \brief Creates an assignment Query.
*
* \param arity is the assignment tuple arity.
*
* \param values is the (void*) values to asign.
*
* The two tuples must have the same arity for assigning names[i] to
- * values[i]. This query makes the given names have the given values,
+ * values[i]. This Query makes the given names have the given values,
* once for each (*next) call following a (*reset) call.
*
- * \related query
+ * \related Query
*/
-extern query *query_assign(int arity,tuple *names,tuple *values);
-
-
-
-typedef struct {
- query base;
- Relation *r;
- tuple *names;
- tuple *query;
-} lookup_query;
+extern Query *Query_assign(int arity,tuple *names,tuple *values);
/**
- * \brief Create a lookup_query record for lookup data in a Relation.
+ * \brief Create a lookup_Query record for lookup data in a Relation.
*/
-extern query *query_lookup(Relation *r,...);
+extern Query *Query_lookup(Relation *r,...);
#include <stdlib.h>
#include <Relation.h>
-Relation *relation_create(TupleSchema *schema) {
+Relation *Relation_create(TupleSchema *schema) {
Relation *r = (Relation *) malloc( sizeof( Relation ) );
(*r) = (Relation) {
.content = (HashVector) {
// Add an indexing HashVector to the Relation using the given column
// flags with 1 indicating key column and 0 indicating value column.
-int relation_add_constraint(Relation *r,...) {
+int Relation_add_constraint(Relation *r,...) {
va_list ap;
TupleSchema *ts = (TupleSchema *) r->content.type;
tuple *columns = (tuple*) calloc( ts->arity, sizeof( void* ) );
}
//============== Adding an item =============
-// Iteration context for adding or querying a Relation
+// Iteration context for adding or Querying a Relation
typedef struct {
Relation *rel;
HashVector knockouts;
return 0;
}
-// Find and remove all collisions for a query, unless "add" is
+// Find and remove all collisions for a Query, unless "add" is
// non-zero in which case the function aborts if there is any match in
// the main content.
static int knockout_clear(Knockout *this,Relation *r,tuple *item,int add) {
// add a tuple to a Relation and return a Vector of knocked out
// tuples, if any, or 0 otherwise.
-Vector *relation_add(Relation *r,tuple *item) {
+Vector *Relation_add(Relation *r,tuple *item) {
Knockout data;
if ( knockout_clear( &data, r, item, 1 ) ) {
// Add the new tuple
return 0;
}
-Vector *relation_delete(Relation *r,tuple *item) {
+Vector *Relation_delete(Relation *r,tuple *item) {
Knockout data;
(void) knockout_clear( &data, r, item, 0 );
return HashVector_contents( &data.knockouts, single_index_level, 0 );
}
-void *relation_next(Relation *r,VectorIndex *index,tuple *query) {
- return HashVector_next( &r->content, index, query );
+void *Relation_next(Relation *r,VectorIndex *index,tuple *Query) {
+ return HashVector_next( &r->content, index, Query );
}
-#ifndef relation_H
-#define relation_H
+#ifndef Relation_H
+#define Relation_H
#include <HashVector.h>
#include <TupleSchema.h>
*
* \related Relation
*/
-extern Relation *relation_create(TupleSchema *schema);
+extern Relation *Relation_create(TupleSchema *schema);
/**
* \brief Add a key constraint to a \ref Relation.
* \ref tuple "tuples" are then "knocked out" from the Relation by the
* new addition.
*
- * \see relation_add
+ * \see Relation_add
* \related Relation
*/
-extern int relation_add_constraint(Relation *r,...);
+extern int Relation_add_constraint(Relation *r,...);
/**
* \brief Add the tuple to the Relation.
*
* \related Relation
*/
-extern Vector *relation_add(Relation *r,tuple *t);
+extern Vector *Relation_add(Relation *r,tuple *t);
/**
- * \brief Delete all tuples matching to the query \ref tuple fromt the
+ * \brief Delete all tuples matching to the Query \ref tuple fromt the
* \ref Relation.
*
* \param r is the \ref Relation concerned.
* \returns a \Vector Vector of all knocked out tuples, i.e. the
* same-key tuples, if any, contained in the Relation
*
- * Note that deletion uses a "query" tuple, which means that some
+ * Note that deletion uses a "Query" tuple, which means that some
* columns may be null to mark that them match to any value.
*
* \related Relation
*/
-extern Vector *relation_delete(Relation *r,tuple *query);
+extern Vector *Relation_delete(Relation *r,tuple *Query);
/**
* \brief Return the next \ref tuple in the \ref Relation that matches
- * to the query \ref tuple, at or after the index.
+ * to the Query \ref tuple, at or after the index.
*
* \param r is the \ref Relation concerned.
*
* \param index is a pointer to the \ref Vector index to update.
*
- * \param query is a query \tuple tuple for selection of certain
+ * \param Query is a Query \tuple tuple for selection of certain
* column values.
*
* \returns any such matching \tuple tuple and an updateed *index.
*
* \related Relation
*/
-extern void *relation_next(Relation *r,VectorIndex *index,tuple *query);
+extern void *Relation_next(Relation *r,VectorIndex *index,tuple *Query);
/**
* \brief Lay out a dynamic \ref Relation initializer for a Relation
extern TupleSchema *TupleSchema_mask(TupleSchema *schema,...);
/**
- * \brief Return 1/0 to indicate whether the query matches the item.
+ * \brief Return 1/0 to indicate whether the Query matches the item.
*
* \related TupleSchema
*/
-extern int TupleSchema_match(TupleSchema *def,tuple *query,tuple *item);
+extern int TupleSchema_match(TupleSchema *def,tuple *Query,tuple *item);
/**
* \brief Generic macro to determine the number of expressions in a