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>
619 typedef std::size_t size_t;
631 std::size_t hashCode);
653 template<
class KEY_CONFIG>
663 template <
class KEY_CONFIG>
690 template <
class KEY_CONFIG,
class HASHER>
692 const HASHER& hasher,
702 std::size_t numBuckets);
716 std::size_t hashCode);
729 std::size_t hashCode);
743 std::size_t hashCode,
755 std::size_t hashCode);
778 template <
class KEY_CONFIG,
class KEY_EQUAL>
782 const KEY_EQUAL& equalityFunctor,
783 std::size_t hashCode);
807 template <
class KEY_CONFIG,
class LOOKUP_KEY,
class KEY_EQUAL>
810 const LOOKUP_KEY& key,
811 const KEY_EQUAL& equalityFunctor,
812 std::size_t hashCode);
828 template <
class KEY_CONFIG,
class HASHER>
831 const HASHER& hasher);
846 std::size_t hashCode)
859 std::size_t numBuckets)
863 return hashCode % numBuckets;
875 *
const end = bucket.
end(); end != cursor;
876 cursor = cursor->nextLink()) {
877 if (linkAddress == cursor) {
888template<
class KEY_CONFIG>
896 return static_cast<BNode *
>(link)->value();
899template<
class KEY_CONFIG>
908 BNode *node =
static_cast<BNode *
>(link);
909 return KEY_CONFIG::extractKey(node->value());
912template <
class KEY_CONFIG,
class KEY_EQUAL>
917 const KEY_EQUAL& equalityFunctor,
918 std::size_t hashCode)
923 const HashTableBucket *bucket = findBucketForHashCode(anchor, hashCode);
927 *
const end = bucket->
end();
928 end != cursor; cursor = cursor->nextLink() ) {
929 if (equalityFunctor(key, extractKey<KEY_CONFIG>(cursor))) {
937template <
class KEY_CONFIG,
class LOOKUP_KEY,
class KEY_EQUAL>
941 const LOOKUP_KEY& key,
942 const KEY_EQUAL& equalityFunctor,
943 std::size_t hashCode)
948 const HashTableBucket *bucket = findBucketForHashCode(anchor, hashCode);
952 *
const end = bucket->
end();
953 end != cursor; cursor = cursor->nextLink() ) {
954 if (equalityFunctor(key, extractKey<KEY_CONFIG>(cursor))) {
962template <
class KEY_CONFIG,
class HASHER>
965 const HASHER& hasher)
988#if !defined(BSLS_PLATFORM_CMP_MSVC)
989 Proctor(
const Proctor&);
990 Proctor& operator=(
const Proctor&);
996 : d_sourceList(sourceList)
997 , d_targetAnchor(targetAnchor)
1006 for( ; lastLink->nextLink(); lastLink = lastLink->nextLink()) {
1009 BidirectionalLinkListUtil::spliceListBeforeTarget(
1024 cursor < end; ++cursor) {
1029 Proctor enforceSingleListOnExit(&elementList, newAnchor);
1031 while (elementList) {
1033 elementList = elementList->
nextLink();
1037 hasher(extractKey<KEY_CONFIG>(nextNode)));
1041template <
class KEY_CONFIG,
class HASHER>
1043 const HASHER& hasher,
1050 if (!array || !size) {
1057 for (
size_t i = 0; i < size; ++i) {
1071 bool *bucketsUsed = (
bool *) allocator->
allocate(size);
1073 for (
size_t i = 0; i < size; ++i) {
1074 bucketsUsed[i] =
false;
1077 size_t hash = hasher(extractKey<KEY_CONFIG>(root));
1079 if (array[bucketIdx].first() != root) {
1083 bucketsUsed[bucketIdx] =
true;
1086 size_t prevBucketIdx = bucketIdx;
1088 if (cursor->previousLink() != prev) {
1092 hash = hasher(extractKey<KEY_CONFIG>(cursor));
1095 if (bucketIdx != prevBucketIdx) {
1101 if (bucketsUsed[bucketIdx]) {
1104 bucketsUsed[bucketIdx] =
true;
1109 if (array[bucketIdx].first() != cursor) {
1116 if (array[prevBucketIdx].last() != prev) {
1123 prevBucketIdx = bucketIdx;
1126 if (array[prevBucketIdx].last() != prev) {
1132 for (
size_t i = 0; i < size; ++i) {
1134 if (bucketsUsed[i]) {
Definition bslalg_bidirectionallink.h:347
BidirectionalLink * nextLink() const
Return the address of the next node linked from this node.
Definition bslalg_bidirectionallink.h:422
BidirectionalLink * previousLink() const
Return the address of the preceding node linked from this node.
Definition bslalg_bidirectionallink.h:428
Definition bslalg_bidirectionalnode.h:357
Definition bslalg_hashtableanchor.h:542
BidirectionalLink * listRootAddress() const
Return the value listRootAddress attribute of this object.
Definition bslalg_hashtableanchor.h:695
std::size_t bucketArraySize() const
Return the value of the bucketArraySize attribute of this object.
Definition bslalg_hashtableanchor.h:701
void setListRootAddress(BidirectionalLink *value)
Definition bslalg_hashtableanchor.h:678
HashTableBucket * bucketArrayAddress() const
Definition bslalg_hashtableanchor.h:707
Definition bslma_allocator.h:545
virtual void * allocate(size_type size)=0
Definition bslma_deallocatorguard.h:166
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlc_flathashmap.h:2218
Definition bslmf_conditional.h:123
Definition bslmf_integralconstant.h:261
Definition bslalg_hashtablebucket.h:297
BidirectionalLink * first() const
Definition bslalg_hashtablebucket.h:421
BidirectionalLink * end() const
Definition bslalg_hashtablebucket.h:415
BidirectionalLink * last() const
Definition bslalg_hashtablebucket.h:427
Definition bslalg_hashtableimputil.h:615
static HashTableImpUtil_ExtractKeyResult< KEY_CONFIG >::Type extractKey(BidirectionalLink *link)
Definition bslalg_hashtableimputil.h:902
static BidirectionalLink * findTransparent(const HashTableAnchor &anchor, const LOOKUP_KEY &key, const KEY_EQUAL &equalityFunctor, std::size_t hashCode)
Definition bslalg_hashtableimputil.h:939
static KEY_CONFIG::ValueType & extractValue(BidirectionalLink *link)
Definition bslalg_hashtableimputil.h:890
static bool isWellFormed(const HashTableAnchor &anchor, const HASHER &hasher, bslma::Allocator *allocator=0)
Definition bslalg_hashtableimputil.h:1042
static bool bucketContainsLink(const HashTableBucket &bucket, BidirectionalLink *linkAddress)
Definition bslalg_hashtableimputil.h:869
static void rehash(HashTableAnchor *newAnchor, BidirectionalLink *elementList, const HASHER &hasher)
Definition bslalg_hashtableimputil.h:963
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:858
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:914
static Allocator * defaultAllocator()
Definition bslma_default.h:905