use only one typedef

This commit is contained in:
Sébastien Loriot 2022-04-06 13:36:39 +02:00
parent 8c48ef4bfd
commit 601b65cad2
2 changed files with 22 additions and 23 deletions

View File

@ -76,11 +76,10 @@ private:
public:
static constexpr std::size_t min_size = 32;
static constexpr std::size_t default_size = 512;
typedef chained_map_elem<T>* chained_map_item;
typedef chained_map_item item;
typedef chained_map_elem<T>* Item;
std::size_t index(chained_map_item it) const { return it->k; }
T& inf(chained_map_item it) const { return it->i; }
std::size_t index(Item it) const { return it->k; }
T& inf(Item it) const { return it->i; }
chained_map(std::size_t n = default_size, const T& d = T());
chained_map(const chained_map<T, Allocator>& D);
@ -92,14 +91,14 @@ public:
{
if(!table)
return;
for (chained_map_item item = table ; item != table_end ; ++item)
for (Item item = table ; item != table_end ; ++item)
destroy(item);
alloc.deallocate(table, table_end - table);
}
T& access(chained_map_item p, std::size_t x);
T& access(Item p, std::size_t x);
T& access(std::size_t x);
chained_map_item lookup(std::size_t x) const;
Item lookup(std::size_t x) const;
void statistics() const;
};
@ -109,7 +108,7 @@ inline T& chained_map<T, Allocator>::access(std::size_t x)
if(!table)
init_table(reserved_size);
chained_map_item p = HASH(x);
Item p = HASH(x);
if ( p->k == x ) {
return p->i;
@ -140,7 +139,7 @@ void chained_map<T, Allocator>::init_table(std::size_t n)
free = table + t;
table_end = table + t + t/2;
for (chained_map_item p = table; p < free; p++)
for (Item p = table; p < free; p++)
{ p->succ = nullptr;
p->k = nullptrKEY;
}
@ -149,7 +148,7 @@ void chained_map<T, Allocator>::init_table(std::size_t n)
template <typename T, typename Allocator>
inline void chained_map<T, Allocator>::insert(std::size_t x, T y)
{ chained_map_item q = HASH(x);
{ Item q = HASH(x);
if ( q->k == nullptrKEY ) {
q->k = x;
q->i = y;
@ -169,16 +168,16 @@ void chained_map<T, Allocator>::rehash()
chained_map_elem<T>* old_table_end = table_end;
chained_map_elem<T>* old_free = free;
chained_map_item old_table_mid = table + table_size;
Item old_table_mid = table + table_size;
init_table(2*table_size);
chained_map_item p;
Item p;
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);
{ Item q = HASH(x);
q->k = x;
q->i = p->i;
}
@ -190,16 +189,16 @@ void chained_map<T, Allocator>::rehash()
p++;
}
for (chained_map_item item = old_table ; item != old_table_end ; ++item)
for (Item item = old_table ; item != old_table_end ; ++item)
destroy(item);
alloc.deallocate(old_table, old_table_end - old_table);
}
template <typename T, typename Allocator>
T& chained_map<T, Allocator>::access(chained_map_item p, std::size_t x)
T& chained_map<T, Allocator>::access(Item p, std::size_t x)
{
chained_map_item q = p->succ;
Item q = p->succ;
while (q && q->k != x) q = q->succ;
if (q)
{
@ -240,7 +239,7 @@ chained_map<T, Allocator>::chained_map(const chained_map<T, Allocator>& D)
{
init_table(D.table_size);
for(chained_map_item p = D.table; p < D.free; p++)
for(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
@ -255,7 +254,7 @@ chained_map<T, Allocator>& chained_map<T, Allocator>::operator=(const chained_ma
init_table(D.table_size);
for(chained_map_item p = D.table; p < D.free; p++)
for(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
@ -277,7 +276,7 @@ void chained_map<T, Allocator>::clear()
if(!table)
return;
for (chained_map_item item = table ; item != table_end ; ++item)
for (Item item = table ; item != table_end ; ++item)
destroy(item);
alloc.deallocate(table, table_end - table);
@ -285,13 +284,13 @@ void chained_map<T, Allocator>::clear()
}
template <typename T, typename Allocator>
typename chained_map<T, Allocator>::chained_map_item
typename chained_map<T, Allocator>::Item
chained_map<T, Allocator>::lookup(std::size_t x) const
{
if(!table)
return nullptr;
chained_map_item p = HASH(x);
Item p = HASH(x);
while (p && p->k != x)
{ p = p->succ; }
return p;
@ -301,7 +300,7 @@ template <typename T, typename Allocator>
void chained_map<T, Allocator>::statistics() const
{ std::cout << "table_size: " << table_size <<"\n";
std::size_t n = 0;
for (chained_map_item p = table; p < table + table_size; p++)
for (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;

View File

@ -47,7 +47,7 @@ public:
private:
typedef internal::chained_map<Data, Allocator> Map;
typedef typename Map::item Item;
typedef typename Map::Item Item;
private:
Hash_function m_hash_function;