From e059d68e94e45e1b517e49b5d4d03ad3c08884f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 6 Apr 2022 12:02:12 +0200 Subject: [PATCH] use the first element in the table before 0 was used as a sentinel for checking if an element was used, so table[0] could not be used. --- Hash_map/include/CGAL/Tools/chained_map.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Hash_map/include/CGAL/Tools/chained_map.h b/Hash_map/include/CGAL/Tools/chained_map.h index 38cb5e506d7..621de07d425 100644 --- a/Hash_map/include/CGAL/Tools/chained_map.h +++ b/Hash_map/include/CGAL/Tools/chained_map.h @@ -37,8 +37,7 @@ class chained_map_elem template class chained_map { - static constexpr std::size_t nullptrKEY = 0; - static constexpr std::size_t NONnullptrKEY = 1; + static constexpr std::size_t nullptrKEY = (std::numeric_limits::max)(); chained_map_elem* table; chained_map_elem* table_end; @@ -146,7 +145,6 @@ void chained_map::init_table(std::size_t n) { p->succ = nullptr; p->k = nullptrKEY; } - table->k = NONnullptrKEY; } @@ -178,7 +176,7 @@ void chained_map::rehash() chained_map_item p; - for(p = old_table + 1; p < old_table_mid; p++) // the first element is never used (nullptrKEY vs NONnullptrKEY) + for(p = old_table; p < old_table_mid; p++) { std::size_t x = p->k; if ( x != nullptrKEY ) // list p is non-empty { chained_map_item q = HASH(x); @@ -243,7 +241,7 @@ chained_map::chained_map(const chained_map& D) { init_table(D.table_size); - for(chained_map_item p = D.table + 1; p < D.free; p++) + for(chained_map_item p = D.table; p < D.free; p++) { if (p->k != nullptrKEY || p >= D.table + D.table_size) { insert(p->k,p->i); //D.copy_inf(p->i); // see chapter Implementation @@ -263,7 +261,7 @@ chained_map& chained_map::operator=(const chained_ma init_table(D.table_size); - for(chained_map_item p = D.table + 1; p < D.free; p++) + for(chained_map_item p = D.table; p < D.free; p++) { if (p->k != nullptrKEY || p >= D.table + D.table_size) { insert(p->k,p->i); //copy_inf(p->i); // see chapter Implementation @@ -285,7 +283,7 @@ void chained_map::clear_entries() if(!table) return; - for(chained_map_item p = table + 1; p < free; p++) + for(chained_map_item p = table; p < free; p++) if (p->k != nullptrKEY || p >= table + table_size) p->i = T(); } @@ -322,7 +320,7 @@ template void chained_map::statistics() const { std::cout << "table_size: " << table_size <<"\n"; std::size_t n = 0; - for (chained_map_item p = table + 1; p < table + table_size; p++) + for (chained_map_item p = table; p < table + table_size; p++) if (p ->k != nullptrKEY) n++; std::size_t used_in_overflow = free - (table + table_size ); n += used_in_overflow;