X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vector%2Ftupleitem.c;h=55328c5446624abda6224bc07993acfcaacdc0c9;hb=2be3617b0022de55a8f2017ac8d645deda2fee5a;hp=c63e3ec1072bb3544af68f74fa39e46a7840b412;hpb=e7cfb732dbf345432b0832c32b99b17a1741b206;p=rrq%2Frrqmisc.git diff --git a/vector/tupleitem.c b/vector/tupleitem.c index c63e3ec..55328c5 100644 --- a/vector/tupleitem.c +++ b/vector/tupleitem.c @@ -26,11 +26,15 @@ static unsigned long tupleitem_hashcode(void *this,void *key) { tupleschema *def = (tupleschema *) this; tuple *kp = (tuple*) key; int i = 0; - unsigned long value = 0; + unsigned long value = 5381; for ( ; i < def->arity; i++ ) { if ( COLUMN[i] ) { value <<= 3; - value += COLUMN[i]->hashcode( COLUMN[i], (*kp)[i] ); + if ( (*kp)[i] ) { + value += COLUMN[i]->hashcode( COLUMN[i], (*kp)[i] ); + } else { + value += 17; + } } } return value; @@ -46,15 +50,10 @@ static int tupleitem_haskey(void *this,void *item,void *key) { tuple *tp = (tuple*) item; int i = 0; for ( ; i < def->arity; i++ ) { - if ( COLUMN[i] == 0 ) { - if ( (*kp)[i] && (*tp)[i] != (*kp)[i] ) { + if ( COLUMN[i] && (*kp)[i] ) { + if ( COLUMN[i]->haskey( COLUMN[i], (*tp)[i], (*kp)[i] ) == 0 ) { return 0; } - continue; - } - if ( (*kp)[i] && - COLUMN[i]->haskey( COLUMN[i], (*tp)[i], (*kp)[i] ) == 0 ) { - return 0; } } return 1; @@ -113,15 +112,17 @@ tuple *tuple_create(int arity,...) { return t; } +itemkeyfun tupleschema_callbacks = { + .hashcode = tupleitem_hashcode, + .haskey = tupleitem_haskey, + .itemkey = tupleitem_itemkey, + .releasekey = tupleitem_releasekey +}; + tupleschema *tupleschema_create(int arity,tuple *columns) { tupleschema *ts = (tupleschema*) malloc( sizeof( tupleschema ) ); (*ts) = (tupleschema) { - .base = { - .hashcode = tupleitem_hashcode, - .haskey = tupleitem_haskey, - .itemkey = tupleitem_itemkey, - .releasekey = tupleitem_releasekey - }, + .base = tupleschema_callbacks, .arity = arity, .columns = (itemkeyfun**) columns };