trunk/branch integration: hash buckets

This commit is contained in:
Marian Krivos 2011-08-22 18:17:23 +00:00
parent 59d2f5af8b
commit 072d98fee4

View File

@ -364,13 +364,16 @@ public:
/// pair(iterator, true) with iterator
/// pointing to the new element is returned.
{
split();
std::size_t addr = bucketAddress(value);
std::size_t hash = _hash(value);
std::size_t addr = bucketAddressForHash(hash);
BucketVecIterator it(_buckets.begin() + addr);
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
if (buckIt == it->end())
{
buckIt = it->insert(buckIt, value);
split();
addr = bucketAddressForHash(hash);
it = _buckets.begin() + addr;
buckIt = it->insert(it->end(), value);
++_size;
return std::make_pair(Iterator(it, _buckets.end(), buckIt), true);
}
@ -417,6 +420,12 @@ public:
return _size == 0;
}
std::size_t buckets() const
/// Returns the number of allocated buckets.
{
return _buckets.size();
}
protected:
std::size_t bucketAddress(const Value& value) const
{
@ -427,6 +436,14 @@ protected:
return n % (2*_front);
}
std::size_t bucketAddressForHash(std::size_t hash)
{
if (hash % _front >= _split)
return hash % _front;
else
return hash % (2*_front);
}
void split()
{
if (_split == _front)