X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vector%2Frelation.h;h=c2e5293b8141425aeea418f93cf3286b7cbf20c7;hb=03eba52ca6e59fb0b3e239588bb619fedafc341b;hp=f76f1bb4fa3976bba435477c13871e6e34be13d8;hpb=2be3617b0022de55a8f2017ac8d645deda2fee5a;p=rrq%2Frrqmisc.git diff --git a/vector/relation.h b/vector/relation.h index f76f1bb..c2e5293 100644 --- a/vector/relation.h +++ b/vector/relation.h @@ -50,29 +50,28 @@ extern relation *relation_create(tupleschema *schema); * * \param r is the relation concerned. * - * \param key is the constraint \ref tupleschema. + * \param ... are the column flags indicating key (1) or value (0) + * column for all columns. * * \returns the index into the constraints \ref vector for the added * constraint. * - * This function adds a \ref hashvector with the provided \ref - * tupleschema as its item type. The \b key \ref tupleschema must be a - * clone of the \ref relation column schema with some (or all) value - * columns marked as \b 0. Such a \ref tupleschema may be obtained via - * the function \ref tupleschema_mask to clone the \ref relation - * content type (casted as \ref tupleschema*) and clear columns by - * their index. - * - * The constraint \ref hashvectors are used when tuples are added to - * the \ref relation so as to identify the already contained tuples - * that contradict the addition by means of having the same constraint - * key. The already contained tuples are then "knocked out" from the - * relation by the new addition. - * - * \see tupleschema_mask, relation_add + * This function adds a \ref hashvector with a \ref tupleschema as its + * item type cloned from the content type and then modified to + * represent the constraint. Namely that the key columns have their + * "column type" set while value columsn are reset. + * + * The \b constraint \ref hashvectors are used when \ref tuple + * "tuples" are added to the \ref relation so as to identify the + * already contained \ref tuple "tuples" that contradict the addition + * by means of having the same constraint key. The already contained + * \ref tuple "tuples" are then "knocked out" from the relation by the + * new addition. + * + * \see relation_add * \related relation */ -extern int relation_add_constraint(relation *r,tupleschema *key); +extern int relation_add_constraint(relation *r,...); /** * \brief Add the tuple to the relation. @@ -129,4 +128,37 @@ extern vector *relation_delete(relation *r,tuple *query); */ extern void *relation_next(relation *r,vector_index *index,tuple *query); +/** + * \brief Lay out a dynamic \ref relation initializer for a relation + * wth the given column "types". + * + * This defines a \ref relation intializer that creates the \ref + * tupleschema for the given columns. + * + * \note The initializer cannot be used statically. + * + * The \b content \ref hashvector is a \ref nibble_index_level variant + * with an initial size of 16 slots. + * + * The constraints \ref vector is a \ref bitpair_index_level variant + * with initial size 0. + * + * The \b content \ref hashvector \b type is set up with an allocated + * \ref tupleschema that has an allocated \ref tuple that declares the + * column "types" view the given \ref itemkeyfun pointers. Any add + * constraints will need to clone that \ref tupleschema and then clear + * the column slots for the constraint value columns, typically by + * using \ref tupleschema_mask for this. + * + * \related relation + */ +#define RELATION(...) (relation) { \ + .content = { \ + .table = { .variant = nibble_index_levels, .size=16, .entries=0 }, \ + .fill = 0, .holes = 0, \ + .type = (itemkeyfun*) TUPLESCHEMA( __VA_ARGS__ ) \ + }, \ + .constraints = { .variant = bitpair_index_levels, .size=0, .entries=0 } \ +} + #endif