Skip to content

Commit 69bd26a

Browse files
committed
add new test + fix perfect forwarding
1 parent 38d439a commit 69bd26a

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

ExcaliburHash/ExcaliburHash.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ template <typename TKey, typename TValue, unsigned kNumInlineItems = 1, typename
9696
: m_key(std::move(other))
9797
{
9898
}
99+
99100
[[nodiscard]] inline bool isValid() const noexcept { return TKeyInfo::isValid(m_key); }
100101
[[nodiscard]] inline bool isEmpty() const noexcept { return TKeyInfo::isEqual(TKeyInfo::getEmpty(), m_key); }
101102
[[nodiscard]] inline bool isTombstone() const noexcept { return TKeyInfo::isEqual(TKeyInfo::getTombstone(), m_key); }
@@ -739,7 +740,7 @@ template <typename TKey, typename TValue, unsigned kNumInlineItems = 1, typename
739740
// i.e.
740741
// auto it = table.find("key");
741742
// table.emplace("another_key", it->second); // <--- when hash table grows it->second will point to a memory we are about to free
742-
std::pair<IteratorKV, bool> it = emplaceToExisting(size_t(numBucketsNew), key, args...);
743+
std::pair<IteratorKV, bool> it = emplaceToExisting(size_t(numBucketsNew), std::forward<TK>(key), std::forward<Args>(args)...);
743744

744745
reinsert(size_t(numBucketsNew), item, enditem);
745746

@@ -766,9 +767,9 @@ template <typename TKey, typename TValue, unsigned kNumInlineItems = 1, typename
766767
const uint32_t numBucketsThreshold = shr(numBuckets, 1u) + 1;
767768
if (EXLBR_LIKELY(m_numElements < numBucketsThreshold))
768769
{
769-
return emplaceToExisting(numBuckets, key, args...);
770+
return emplaceToExisting(numBuckets, std::forward<TK>(key), std::forward<Args>(args)...);
770771
}
771-
return emplaceReallocate(std::max(numBuckets * 2, 64u), key, args...);
772+
return emplaceReallocate(std::max(numBuckets * 2, 64u), std::forward<TK>(key), std::forward<Args>(args)...);
772773
}
773774

774775
[[nodiscard]] inline ConstIteratorKV find(const TKey& key) const noexcept

ExcaliburHashTest06.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,25 @@ TEST(SmFlatHashMap, Rehash)
4444
EXPECT_EQ(ht.getNumTombstones(), uint32_t(0));
4545
}
4646

47+
48+
49+
TEST(SmFlatHashMap, TestTmp)
50+
{
51+
class StringInternStringData
52+
{
53+
public:
54+
inline StringInternStringData()
55+
: refCount(0), string()
56+
{ }
57+
58+
inline StringInternStringData(const std::string &string)
59+
: refCount(1), string(string)
60+
{ }
61+
62+
int64_t refCount;
63+
std::string string;
64+
};
65+
66+
Excalibur::HashTable<std::string, std::unique_ptr<StringInternStringData>> exMap;
67+
auto inserted = exMap.emplace(std::string("test"), std::make_unique<StringInternStringData>("test"));
68+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
if exist ./codecov_report/ (rd /S /Q ./codecov_report/)
22
rem Install OpenCppCoverage from here https://github.com/OpenCppCoverage/OpenCppCoverage/releases
3-
OpenCppCoverage.exe --export_type html:codecov_report --stop_on_assert --sources ExcaliburHashTest*.* --sources ExcaliburHash.h --excluded_sources *googletest* --modules *.exe -- .\build2019\Debug\ExcaliburHashTest.exe
3+
OpenCppCoverage.exe --export_type html:codecov_report --stop_on_assert --sources ExcaliburHashTest*.* --sources ExcaliburHash.h --excluded_sources *googletest* --modules *.exe -- .\build2022\Debug\ExcaliburHashTest.exe

gen_vs19.cmd

Lines changed: 0 additions & 10 deletions
This file was deleted.

gen_vs19_x86.cmd

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)