From: Ralph Ronnquist Date: Fri, 8 Jul 2022 05:16:12 +0000 (+1000) Subject: reworked hasing with "query" X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=e887b2e80a665a45b411a0d9fd832f96a1a4f893;hp=a4e15c51ff79f329b6069f0b645af48507375438;p=rrq%2Frrqmisc.git reworked hasing with "query" --- diff --git a/vector/tupleitem.c b/vector/tupleitem.c index c63e3ec..ad13267 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;