8#ifndef INCLUDED_BSLALG_HASHTABLEIMPUTIL
9#define INCLUDED_BSLALG_HASHTABLEIMPUTIL
547#include <bslscm_version.h>
566#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
577template <
class KEY_CONFIG>
594 template<
class RESULT,
class ARG>
617 typedef std::size_t size_t;
628 std::size_t hashCode);
649 template<
class KEY_CONFIG>
658 template <
class KEY_CONFIG>
685 template <
class KEY_CONFIG,
class HASHER>
687 const HASHER& hasher,
696 std::size_t numBuckets);
709 std::size_t hashCode);
721 std::size_t hashCode);
734 std::size_t hashCode,
745 std::size_t hashCode);
767 template <
class KEY_CONFIG,
class KEY_EQUAL>
771 const KEY_EQUAL& equalityFunctor,
772 std::size_t hashCode);
795 template <
class KEY_CONFIG,
class LOOKUP_KEY,
class KEY_EQUAL>
798 const LOOKUP_KEY& key,
799 const KEY_EQUAL& equalityFunctor,
800 std::size_t hashCode);
815 template <
class KEY_CONFIG,
class HASHER>
818 const HASHER& hasher);
833 std::size_t hashCode)
846 std::size_t numBuckets)
850 return hashCode % numBuckets;
862 *
const end = bucket.
end(); end != cursor;
863 cursor = cursor->nextLink()) {
864 if (linkAddress == cursor) {
875template<
class KEY_CONFIG>
883 return static_cast<BNode *
>(link)->value();
886template<
class KEY_CONFIG>
895 BNode *node =
static_cast<BNode *
>(link);
896 return KEY_CONFIG::extractKey(node->value());
899template <
class KEY_CONFIG,
class KEY_EQUAL>
904 const KEY_EQUAL& equalityFunctor,
905 std::size_t hashCode)
910 const HashTableBucket *bucket = findBucketForHashCode(anchor, hashCode);
914 *
const end = bucket->
end();
915 end != cursor; cursor = cursor->nextLink() ) {
916 if (equalityFunctor(key, extractKey<KEY_CONFIG>(cursor))) {
924template <
class KEY_CONFIG,
class LOOKUP_KEY,
class KEY_EQUAL>
928 const LOOKUP_KEY& key,
929 const KEY_EQUAL& equalityFunctor,
930 std::size_t hashCode)
935 const HashTableBucket *bucket = findBucketForHashCode(anchor, hashCode);
939 *
const end = bucket->
end();
940 end != cursor; cursor = cursor->nextLink() ) {
941 if (equalityFunctor(key, extractKey<KEY_CONFIG>(cursor))) {
949template <
class KEY_CONFIG,
class HASHER>
952 const HASHER& hasher)
974#if !defined(BSLS_PLATFORM_CMP_MSVC)
975 Proctor(
const Proctor&);
976 Proctor& operator=(
const Proctor&);
982 : d_sourceList(sourceList)
983 , d_targetAnchor(targetAnchor)
992 for( ; lastLink->nextLink(); lastLink = lastLink->nextLink()) {
995 BidirectionalLinkListUtil::spliceListBeforeTarget(
1010 cursor < end; ++cursor) {
1015 Proctor enforceSingleListOnExit(&elementList, newAnchor);
1017 while (elementList) {
1019 elementList = elementList->
nextLink();
1023 hasher(extractKey<KEY_CONFIG>(nextNode)));
1027template <
class KEY_CONFIG,
class HASHER>
1029 const HASHER& hasher,
1036 if (!array || !size) {
1043 for (
size_t i = 0; i < size; ++i) {
1057 bool *bucketsUsed = (
bool *) allocator->
allocate(size);
1059 for (
size_t i = 0; i < size; ++i) {
1060 bucketsUsed[i] =
false;
1063 size_t hash = hasher(extractKey<KEY_CONFIG>(root));
1065 if (array[bucketIdx].first() != root) {
1069 bucketsUsed[bucketIdx] =
true;
1072 size_t prevBucketIdx = bucketIdx;
1074 if (cursor->previousLink() != prev) {
1078 hash = hasher(extractKey<KEY_CONFIG>(cursor));
1081 if (bucketIdx != prevBucketIdx) {
1087 if (bucketsUsed[bucketIdx]) {
1090 bucketsUsed[bucketIdx] =
true;
1095 if (array[bucketIdx].first() != cursor) {
1102 if (array[prevBucketIdx].last() != prev) {
1109 prevBucketIdx = bucketIdx;
1112 if (array[prevBucketIdx].last() != prev) {
1118 for (
size_t i = 0; i < size; ++i) {
1120 if (bucketsUsed[i]) {
Definition bslalg_bidirectionallink.h:346
BidirectionalLink * nextLink() const
Return the address of the next node linked from this node.
Definition bslalg_bidirectionallink.h:421
BidirectionalLink * previousLink() const
Return the address of the preceding node linked from this node.
Definition bslalg_bidirectionallink.h:427
Definition bslalg_bidirectionalnode.h:357
Definition bslalg_hashtableanchor.h:541
BidirectionalLink * listRootAddress() const
Return the value listRootAddress attribute of this object.
Definition bslalg_hashtableanchor.h:708
std::size_t bucketArraySize() const
Return the value of the bucketArraySize attribute of this object.
Definition bslalg_hashtableanchor.h:714
void setListRootAddress(BidirectionalLink *value)
Definition bslalg_hashtableanchor.h:691
HashTableBucket * bucketArrayAddress() const
Definition bslalg_hashtableanchor.h:720
Definition bslma_allocator.h:457
virtual void * allocate(size_type size)=0
Definition bslma_deallocatorguard.h:166
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlc_flathashmap.h:1805
Definition bslmf_conditional.h:120
Definition bslmf_integralconstant.h:244
Definition bslalg_hashtablebucket.h:297
BidirectionalLink * first() const
Definition bslalg_hashtablebucket.h:418
BidirectionalLink * end() const
Definition bslalg_hashtablebucket.h:412
BidirectionalLink * last() const
Definition bslalg_hashtablebucket.h:424
Definition bslalg_hashtableimputil.h:613
static HashTableImpUtil_ExtractKeyResult< KEY_CONFIG >::Type extractKey(BidirectionalLink *link)
Definition bslalg_hashtableimputil.h:889
static BidirectionalLink * findTransparent(const HashTableAnchor &anchor, const LOOKUP_KEY &key, const KEY_EQUAL &equalityFunctor, std::size_t hashCode)
Definition bslalg_hashtableimputil.h:926
static KEY_CONFIG::ValueType & extractValue(BidirectionalLink *link)
Definition bslalg_hashtableimputil.h:877
static bool isWellFormed(const HashTableAnchor &anchor, const HASHER &hasher, bslma::Allocator *allocator=0)
Definition bslalg_hashtableimputil.h:1028
static bool bucketContainsLink(const HashTableBucket &bucket, BidirectionalLink *linkAddress)
Definition bslalg_hashtableimputil.h:856
static void rehash(HashTableAnchor *newAnchor, BidirectionalLink *elementList, const HASHER &hasher)
Definition bslalg_hashtableimputil.h:950
static void insertAtFrontOfBucket(HashTableAnchor *anchor, BidirectionalLink *link, std::size_t hashCode)
static void remove(HashTableAnchor *anchor, BidirectionalLink *link, std::size_t hashCode)
static void insertAtPosition(HashTableAnchor *anchor, BidirectionalLink *link, std::size_t hashCode, BidirectionalLink *position)
static void insertAtBackOfBucket(HashTableAnchor *anchor, BidirectionalLink *link, std::size_t hashCode)
static std::size_t computeBucketIndex(std::size_t hashCode, std::size_t numBuckets)
Definition bslalg_hashtableimputil.h:845
static BidirectionalLink * find(const HashTableAnchor &anchor, typename HashTableImpUtil_ExtractKeyResult< KEY_CONFIG >::Type key, const KEY_EQUAL &equalityFunctor, std::size_t hashCode)
Definition bslalg_hashtableimputil.h:901
static Allocator * defaultAllocator()
Definition bslma_default.h:889