mirror of https://github.com/CGAL/cgal
use only one typedef
This commit is contained in:
parent
8c48ef4bfd
commit
601b65cad2
|
|
@ -76,11 +76,10 @@ private:
|
||||||
public:
|
public:
|
||||||
static constexpr std::size_t min_size = 32;
|
static constexpr std::size_t min_size = 32;
|
||||||
static constexpr std::size_t default_size = 512;
|
static constexpr std::size_t default_size = 512;
|
||||||
typedef chained_map_elem<T>* chained_map_item;
|
typedef chained_map_elem<T>* Item;
|
||||||
typedef chained_map_item item;
|
|
||||||
|
|
||||||
std::size_t index(chained_map_item it) const { return it->k; }
|
std::size_t index(Item it) const { return it->k; }
|
||||||
T& inf(chained_map_item it) const { return it->i; }
|
T& inf(Item it) const { return it->i; }
|
||||||
|
|
||||||
chained_map(std::size_t n = default_size, const T& d = T());
|
chained_map(std::size_t n = default_size, const T& d = T());
|
||||||
chained_map(const chained_map<T, Allocator>& D);
|
chained_map(const chained_map<T, Allocator>& D);
|
||||||
|
|
@ -92,14 +91,14 @@ public:
|
||||||
{
|
{
|
||||||
if(!table)
|
if(!table)
|
||||||
return;
|
return;
|
||||||
for (chained_map_item item = table ; item != table_end ; ++item)
|
for (Item item = table ; item != table_end ; ++item)
|
||||||
destroy(item);
|
destroy(item);
|
||||||
alloc.deallocate(table, table_end - table);
|
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);
|
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;
|
void statistics() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -109,7 +108,7 @@ inline T& chained_map<T, Allocator>::access(std::size_t x)
|
||||||
if(!table)
|
if(!table)
|
||||||
init_table(reserved_size);
|
init_table(reserved_size);
|
||||||
|
|
||||||
chained_map_item p = HASH(x);
|
Item p = HASH(x);
|
||||||
|
|
||||||
if ( p->k == x ) {
|
if ( p->k == x ) {
|
||||||
return p->i;
|
return p->i;
|
||||||
|
|
@ -140,7 +139,7 @@ void chained_map<T, Allocator>::init_table(std::size_t n)
|
||||||
free = table + t;
|
free = table + t;
|
||||||
table_end = table + t + t/2;
|
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->succ = nullptr;
|
||||||
p->k = nullptrKEY;
|
p->k = nullptrKEY;
|
||||||
}
|
}
|
||||||
|
|
@ -149,7 +148,7 @@ void chained_map<T, Allocator>::init_table(std::size_t n)
|
||||||
|
|
||||||
template <typename T, typename Allocator>
|
template <typename T, typename Allocator>
|
||||||
inline void chained_map<T, Allocator>::insert(std::size_t x, T y)
|
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 ) {
|
if ( q->k == nullptrKEY ) {
|
||||||
q->k = x;
|
q->k = x;
|
||||||
q->i = y;
|
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_table_end = table_end;
|
||||||
chained_map_elem<T>* old_free = free;
|
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);
|
init_table(2*table_size);
|
||||||
|
|
||||||
chained_map_item p;
|
Item p;
|
||||||
|
|
||||||
for(p = old_table; p < old_table_mid; p++)
|
for(p = old_table; p < old_table_mid; p++)
|
||||||
{ std::size_t x = p->k;
|
{ std::size_t x = p->k;
|
||||||
if ( x != nullptrKEY ) // list p is non-empty
|
if ( x != nullptrKEY ) // list p is non-empty
|
||||||
{ chained_map_item q = HASH(x);
|
{ Item q = HASH(x);
|
||||||
q->k = x;
|
q->k = x;
|
||||||
q->i = p->i;
|
q->i = p->i;
|
||||||
}
|
}
|
||||||
|
|
@ -190,16 +189,16 @@ void chained_map<T, Allocator>::rehash()
|
||||||
p++;
|
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);
|
destroy(item);
|
||||||
alloc.deallocate(old_table, old_table_end - old_table);
|
alloc.deallocate(old_table, old_table_end - old_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T, typename Allocator>
|
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;
|
while (q && q->k != x) q = q->succ;
|
||||||
if (q)
|
if (q)
|
||||||
{
|
{
|
||||||
|
|
@ -240,7 +239,7 @@ chained_map<T, Allocator>::chained_map(const chained_map<T, Allocator>& D)
|
||||||
{
|
{
|
||||||
init_table(D.table_size);
|
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)
|
{ if (p->k != nullptrKEY || p >= D.table + D.table_size)
|
||||||
{ insert(p->k,p->i);
|
{ insert(p->k,p->i);
|
||||||
//D.copy_inf(p->i); // see chapter Implementation
|
//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);
|
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)
|
{ if (p->k != nullptrKEY || p >= D.table + D.table_size)
|
||||||
{ insert(p->k,p->i);
|
{ insert(p->k,p->i);
|
||||||
//copy_inf(p->i); // see chapter Implementation
|
//copy_inf(p->i); // see chapter Implementation
|
||||||
|
|
@ -277,7 +276,7 @@ void chained_map<T, Allocator>::clear()
|
||||||
if(!table)
|
if(!table)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (chained_map_item item = table ; item != table_end ; ++item)
|
for (Item item = table ; item != table_end ; ++item)
|
||||||
destroy(item);
|
destroy(item);
|
||||||
alloc.deallocate(table, table_end - table);
|
alloc.deallocate(table, table_end - table);
|
||||||
|
|
||||||
|
|
@ -285,13 +284,13 @@ void chained_map<T, Allocator>::clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename Allocator>
|
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
|
chained_map<T, Allocator>::lookup(std::size_t x) const
|
||||||
{
|
{
|
||||||
if(!table)
|
if(!table)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
chained_map_item p = HASH(x);
|
Item p = HASH(x);
|
||||||
while (p && p->k != x)
|
while (p && p->k != x)
|
||||||
{ p = p->succ; }
|
{ p = p->succ; }
|
||||||
return p;
|
return p;
|
||||||
|
|
@ -301,7 +300,7 @@ template <typename T, typename Allocator>
|
||||||
void chained_map<T, Allocator>::statistics() const
|
void chained_map<T, Allocator>::statistics() const
|
||||||
{ std::cout << "table_size: " << table_size <<"\n";
|
{ std::cout << "table_size: " << table_size <<"\n";
|
||||||
std::size_t n = 0;
|
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++;
|
if (p ->k != nullptrKEY) n++;
|
||||||
std::size_t used_in_overflow = free - (table + table_size );
|
std::size_t used_in_overflow = free - (table + table_size );
|
||||||
n += used_in_overflow;
|
n += used_in_overflow;
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef internal::chained_map<Data, Allocator> Map;
|
typedef internal::chained_map<Data, Allocator> Map;
|
||||||
typedef typename Map::item Item;
|
typedef typename Map::Item Item;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Hash_function m_hash_function;
|
Hash_function m_hash_function;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue