mirror of
https://github.com/pocoproject/poco.git
synced 2025-05-29 23:42:39 +02:00
trunk/branch integration: hash buckets
This commit is contained in:
parent
59d2f5af8b
commit
072d98fee4
@ -364,13 +364,16 @@ public:
|
|||||||
/// pair(iterator, true) with iterator
|
/// pair(iterator, true) with iterator
|
||||||
/// pointing to the new element is returned.
|
/// pointing to the new element is returned.
|
||||||
{
|
{
|
||||||
split();
|
std::size_t hash = _hash(value);
|
||||||
std::size_t addr = bucketAddress(value);
|
std::size_t addr = bucketAddressForHash(hash);
|
||||||
BucketVecIterator it(_buckets.begin() + addr);
|
BucketVecIterator it(_buckets.begin() + addr);
|
||||||
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
||||||
if (buckIt == it->end())
|
if (buckIt == it->end())
|
||||||
{
|
{
|
||||||
buckIt = it->insert(buckIt, value);
|
split();
|
||||||
|
addr = bucketAddressForHash(hash);
|
||||||
|
it = _buckets.begin() + addr;
|
||||||
|
buckIt = it->insert(it->end(), value);
|
||||||
++_size;
|
++_size;
|
||||||
return std::make_pair(Iterator(it, _buckets.end(), buckIt), true);
|
return std::make_pair(Iterator(it, _buckets.end(), buckIt), true);
|
||||||
}
|
}
|
||||||
@ -417,6 +420,12 @@ public:
|
|||||||
return _size == 0;
|
return _size == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::size_t buckets() const
|
||||||
|
/// Returns the number of allocated buckets.
|
||||||
|
{
|
||||||
|
return _buckets.size();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::size_t bucketAddress(const Value& value) const
|
std::size_t bucketAddress(const Value& value) const
|
||||||
{
|
{
|
||||||
@ -427,6 +436,14 @@ protected:
|
|||||||
return n % (2*_front);
|
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()
|
void split()
|
||||||
{
|
{
|
||||||
if (_split == _front)
|
if (_split == _front)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user