From: Ralph Ronnquist Date: Tue, 12 Jul 2022 10:10:46 +0000 (+1000) Subject: further camelcase fixing X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=e938f8c45fd191d96da48f65262e4efcfada7805;p=rrq%2Frrqmisc.git further camelcase fixing --- diff --git a/tests/example-hashvector.c b/tests/example-hashvector.c index 28eaeab..16e4322 100644 --- a/tests/example-hashvector.c +++ b/tests/example-hashvector.c @@ -1,6 +1,6 @@ #include #include -#include "hashvector.h" +#include "HashVector.h" typedef struct _ipslot { int family; @@ -9,7 +9,7 @@ typedef struct _ipslot { } 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) { @@ -27,27 +27,27 @@ static int voidp_tostring(void *this, void *item, char *buffer, int limit) { 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, @@ -62,15 +62,15 @@ int main(int argc,char **argv) { } 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; } diff --git a/tests/example-relation.c b/tests/example-relation.c index f4cf08c..2c76f64 100644 --- a/tests/example-relation.c +++ b/tests/example-relation.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include char *val(void* t) { @@ -24,18 +24,18 @@ void prtuple(char *pre, tuple *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 ); } } @@ -49,45 +49,45 @@ typedef union { } 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; diff --git a/tests/example-vector.c b/tests/example-vector.c index c191d2d..62e7931 100644 --- a/tests/example-vector.c +++ b/tests/example-vector.c @@ -7,7 +7,7 @@ #include #include #include -#include "vector.h" +#include "Vector.h" typedef struct _ipslot { int family; @@ -16,7 +16,7 @@ typedef struct _ipslot { } ipslot; static struct { - vector data; + Vector data; int fill; } table; @@ -99,9 +99,9 @@ static void add_entry(ipslot *tmp) { 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) { @@ -122,15 +122,15 @@ 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 ); @@ -138,24 +138,24 @@ static void dump_ipslot(const vector_index index,const void *item) { } 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; } diff --git a/tests/relationtests.c b/tests/relationtests.c index 15c23f2..7b565b6 100644 --- a/tests/relationtests.c +++ b/tests/relationtests.c @@ -1,13 +1,13 @@ /** - * This is a collection of tests of the relation functions. + * This is a collection of tests of the Relation functions. */ #include #include -#include +#include #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; @@ -24,15 +24,15 @@ static char *tuple2string(relation *r,tuple *t) { 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] ) ); @@ -40,35 +40,35 @@ static void query_report_all(relation *r,tuple *query[]) { } } -// 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] ) ); } } @@ -87,12 +87,12 @@ int main(int argc,char **argv) { 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[] = { @@ -112,14 +112,14 @@ int main(int argc,char **argv) { 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; } diff --git a/tests/vectortests.c b/tests/vectortests.c index b596cfb..44bb965 100644 --- a/tests/vectortests.c +++ b/tests/vectortests.c @@ -1,22 +1,22 @@ /** - * A sequence of tests of the vector.h functions. + * A sequence of tests of the Vector.h functions. */ #include #include -#include +#include #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; @@ -28,7 +28,7 @@ static int itemcmp(const void *a,const void *b) { } // 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; @@ -48,13 +48,13 @@ int itemfind(const void *key, const void *item) { return strncmp( a, b, (an [%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; } diff --git a/vector/HashVector.h b/vector/HashVector.h index 18f63fb..0b4a0f6 100644 --- a/vector/HashVector.h +++ b/vector/HashVector.h @@ -93,7 +93,7 @@ void *HashVector_find(HashVector *hv,void *key); * * \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. diff --git a/vector/Query.c b/vector/Query.c index 54d413b..68efa3f 100644 --- a/vector/Query.c +++ b/vector/Query.c @@ -4,7 +4,7 @@ #include #include -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 @@ -24,30 +24,28 @@ enum next_state { 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. * @@ -56,7 +54,7 @@ struct query_callbacks { * \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 @@ -67,12 +65,12 @@ struct query_callbacks { * 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; @@ -80,7 +78,7 @@ typedef struct { } 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 ); @@ -113,7 +111,7 @@ static void AssignmentQuery_assign( // 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: @@ -140,16 +138,16 @@ static int AssignmentQuery_next( 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) { @@ -159,18 +157,18 @@ query *query_assign(int arity,tuple *names,tuple *values) { .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++ ) { @@ -181,11 +179,11 @@ static void ConjunctionQuery_reclaim(query *this) { } 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; @@ -218,12 +216,12 @@ static int ConjunctionQuery_next( 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 ) ); @@ -231,26 +229,26 @@ query *query_and(int n,...) { .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++ ) { @@ -261,10 +259,10 @@ static void DisjunctionQuery_reclaim(query *this) { } 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; @@ -290,12 +288,12 @@ static int DisjunctionQuery_next( 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 ) ); @@ -303,20 +301,20 @@ query *query_or(int n,...) { .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; @@ -325,7 +323,7 @@ typedef struct { } 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 ); @@ -334,7 +332,7 @@ static void RelationQuery_reclaim(query *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; @@ -349,7 +347,7 @@ static int RelationQuery_next( // 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 ); @@ -367,16 +365,16 @@ static int RelationQuery_next( 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, @@ -385,5 +383,5 @@ query *query_Relation(Relation *r,tuple *names,tuple *values) { .values = values, .saved = 0 }; - return (query*) q; + return (Query*) q; } diff --git a/vector/Query.h b/vector/Query.h index 17bbe38..a8eb175 100644 --- a/vector/Query.h +++ b/vector/Query.h @@ -1,24 +1,24 @@ -#ifndef query_H -#define query_H +#ifndef Query_H +#define Query_H #include #include -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. * @@ -27,26 +27,17 @@ typedef struct { * \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,...); diff --git a/vector/Relation.c b/vector/Relation.c index f72f198..0b7450f 100644 --- a/vector/Relation.c +++ b/vector/Relation.c @@ -2,7 +2,7 @@ #include #include -Relation *relation_create(TupleSchema *schema) { +Relation *Relation_create(TupleSchema *schema) { Relation *r = (Relation *) malloc( sizeof( Relation ) ); (*r) = (Relation) { .content = (HashVector) { @@ -27,7 +27,7 @@ Relation *relation_create(TupleSchema *schema) { // 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* ) ); @@ -48,7 +48,7 @@ int relation_add_constraint(Relation *r,...) { } //============== 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; @@ -82,7 +82,7 @@ static int knockout_add(VectorIndex index,void *item,void *data) { 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) { @@ -120,7 +120,7 @@ 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 @@ -131,13 +131,13 @@ Vector *relation_add(Relation *r,tuple *item) { 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 ); } diff --git a/vector/Relation.h b/vector/Relation.h index b3c2be7..76c5002 100644 --- a/vector/Relation.h +++ b/vector/Relation.h @@ -1,5 +1,5 @@ -#ifndef relation_H -#define relation_H +#ifndef Relation_H +#define Relation_H #include #include @@ -43,7 +43,7 @@ typedef struct { * * \related Relation */ -extern Relation *relation_create(TupleSchema *schema); +extern Relation *Relation_create(TupleSchema *schema); /** * \brief Add a key constraint to a \ref Relation. @@ -68,10 +68,10 @@ extern Relation *relation_create(TupleSchema *schema); * \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. @@ -91,10 +91,10 @@ extern int relation_add_constraint(Relation *r,...); * * \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. @@ -104,29 +104,29 @@ extern Vector *relation_add(Relation *r,tuple *t); * \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 diff --git a/vector/TupleSchema.h b/vector/TupleSchema.h index 4f5a544..0549284 100644 --- a/vector/TupleSchema.h +++ b/vector/TupleSchema.h @@ -61,11 +61,11 @@ extern TupleSchema *TupleSchema_create(int arity,tuple *columns); 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