From: Ralph Ronnquist Date: Fri, 1 Jul 2022 07:28:16 +0000 (+1000) Subject: debugged: working X-Git-Tag: 0.1 X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=183905767f8b512dd030c3432595fc6d2c702a41;p=rrq%2Frrqmisc.git debugged: working --- diff --git a/tests/vectortests.c b/tests/vectortests.c index 6f8cdbd..f85f7cc 100644 --- a/tests/vectortests.c +++ b/tests/vectortests.c @@ -6,7 +6,12 @@ #include #include -#define OUT(...) fprintf( stderr, __VA_ARGS__ ) +static int LINE; + +#define max(a,b) ((a>b)?a:b) +#define OUT(...) { \ + fprintf( stderr, __VA_ARGS__ ); \ +} // dump an item; return 0 to stop static void itemdump(const vector_index index,const void *slot) { diff --git a/vector/vector.c b/vector/vector.c index a9c6b63..6f44a64 100644 --- a/vector/vector.c +++ b/vector/vector.c @@ -44,7 +44,7 @@ unsigned long VECTOR_INDEX_PART(vector *pv,vector_index *index, int level) { return pp->a; } case 1: { - nibble *pp = (nibble*)(px + ( level / 2 )); + nibble *pp = (nibble*)( px + ( level / 2 ) ); switch ( level & 1 ) { case 0: return pp->a; case 1: return pp->b; @@ -52,7 +52,7 @@ unsigned long VECTOR_INDEX_PART(vector *pv,vector_index *index, int level) { break; } case 2: { - bitpair *pp = (bitpair*)(px + ( level / 4 )); + bitpair *pp = (bitpair*)( px + ( level / 4 ) ); switch ( level & 3 ) { case 0: return pp->a; case 1: return pp->b; @@ -90,7 +90,7 @@ static unsigned long VECTOR_INDEX_PART_INC( } case 2: { bitpair *pp = (bitpair*)( px + level / 4 ); - switch ( level & 0xf ) { + switch ( level & 3 ) { case 0: return ++(pp->a); case 1: return ++(pp->b); case 2: return ++(pp->c); @@ -150,7 +150,14 @@ static void VECTOR_INDEX_FIRST(vector *pv,vector_index *index, int level) { // Set index to last value for all index parts at level and lower. static void VECTOR_INDEX_LAST(vector *pv,vector_index *index, int level) { - (*index) |= ONES >> ( 64 - VECTOR_BITS[ pv->variant ] * level ); + static unsigned long ones[] = { 255, 15, 3 }; + unsigned long x = ones[ pv->variant ]; + while ( level-- ) { + (*index) |= x; + x <<= VECTOR_BITS[ pv->variant ]; + } + // 255, 25, 3 + //(*index) |= ONES >> ( 64 - ( VECTOR_BITS[ pv->variant ] * level ) ); } // Return number of slots for a vector variant. @@ -209,7 +216,7 @@ static void **vector_level_next_used( // If the page *p is all empty, so can/should be reclaimed. } else { if ( level > 0 ) { - VECTOR_INDEX_FIRST( pv, index, level ); + VECTOR_INDEX_FIRST( pv, index, level - 1 ); } } if ( VECTOR_INDEX_PART_INC( pv, index, level ) == 0 ) { @@ -604,14 +611,11 @@ void vector_iterate(vector *pv, { vector_index index = start; while ( index < pv->size ) { - void **slot = vector_next_used( pv, &index ); - if ( slot == 0 ) { - break; - } int end = VECTOR_SLOTS( pv ); int i = index & ( end - 1 ); - for ( ; i < end && index < pv->size; i++, index++, slot++ ) { - if ( itemfn( index, *slot, data ) ) { + for ( ; i < end && index < pv->size; i++, index++ ) { + void **slot = vector_access( pv, index, 0, 0 ); + if ( slot && itemfn( index, *slot, data ) ) { return; } }