15 using namespace folly;
33 static const Key TOtherKey = OtherKey;
34 static const Key TNoneKey = NoneKey;
35 static const bool TAllowDuplicates = AllowDuplicates;
36 static const bool TCaseInsensitive = CaseInsensitive;
42 return PerfectHashStrToKey(name);
45 static const uint8_t TKeyCommonOffset = KeyCommonOffset;
65 typedef testing::Types<
70 HTTPCommonHeaders::hash,
74 HTTPCommonHeaders::num_header_codes>,
79 HTTPCommonHeaders::hash,
83 HTTPCommonHeaders::num_header_codes>,
88 HTTPCommonHeaders::hash,
92 HTTPCommonHeaders::num_header_codes>,
97 HTTPCommonHeaders::hash,
101 HTTPCommonHeaders::num_header_codes>
106 typedef typename TypeParam::TKey
Key;
111 auto numInserted = TypeParam::TNumKeys - TypeParam::TKeyCommonOffset;
112 for (
uint64_t j = TypeParam::TKeyCommonOffset; j < TypeParam::TNumKeys; ++j) {
113 this->testMap_.set(static_cast<Key>(j), std::to_string(j));
115 EXPECT_EQ(this->testMap_.size(), numInserted);
119 Key key =
static_cast<Key
>(TypeParam::TKeyCommonOffset);
120 this->testMap_.set(key, std::to_string(TypeParam::TKeyCommonOffset));
121 EXPECT_EQ(this->testMap_.size(), numInserted);
125 if (TypeParam::TAllowDuplicates) {
126 this->testMap_.add(key, std::to_string(TypeParam::TKeyCommonOffset));
127 EXPECT_EQ(this->testMap_.size(), numInserted + 1);
132 this->testMap_.remove(key);
133 EXPECT_EQ(this->testMap_.size(), --numInserted);
136 for (
uint64_t j = TypeParam::TKeyCommonOffset + 1;
137 j < TypeParam::TNumKeys; ++j) {
138 key =
static_cast<Key
>(j);
139 auto optional = this->testMap_.getSingleOrNone(key);
141 ASSERT_EQ(optional.value(), std::to_string(j));
149 int numInserted = 10;
151 for (
int num = 0; num < numInserted; ++num) {
152 val = std::to_string(num);
153 this->testMap_.set(val, val);
155 EXPECT_EQ(this->testMap_.size(), numInserted);
159 this->testMap_.set(val, val);
160 EXPECT_EQ(this->testMap_.size(), numInserted);
164 if (TypeParam::TAllowDuplicates) {
165 this->testMap_.add(val, val);
166 EXPECT_EQ(this->testMap_.size(), numInserted + 1);
171 this->testMap_.remove(val);
172 EXPECT_EQ(this->testMap_.size(), --numInserted);
175 for (
int num = 0; num < numInserted; ++num) {
176 val = std::to_string(num);
177 auto optional = this->testMap_.getSingleOrNone(val);
192 this->testMap_.set(testString, testString);
194 auto currentCount = this->testMap_.size();
196 if (TypeParam::TCaseInsensitive) {
197 optional = this->testMap_.getSingleOrNone(modTestString);
201 this->testMap_.set(modTestString, modTestString);
202 EXPECT_EQ(this->testMap_.size(), currentCount);
204 optional = this->testMap_.getSingleOrNone(testString);
206 ASSERT_EQ(optional.value(), modTestString);
208 this->testMap_.set(modTestString, modTestString);
209 EXPECT_EQ(this->testMap_.size(), ++currentCount);
211 this->testMap_.set(testString, testString);
212 EXPECT_EQ(this->testMap_.size(), currentCount);
214 optional = this->testMap_.getSingleOrNone(testString);
218 optional = this->testMap_.getSingleOrNone(modTestString);
220 ASSERT_EQ(optional.value(), modTestString);
223 if (TypeParam::TAllowDuplicates) {
225 this->testMap_.add(addModTestString, addModTestString);
226 optional = this->testMap_.getSingleOrNone(testString);
227 if (TypeParam::TCaseInsensitive) {
static Key Hash(const std::string &name)
#define ASSERT_EQ(val1, val2)
#define EXPECT_EQ(val1, val2)
internal::KeyMatcher< M > Key(M inner_matcher)
FOLLY_CPP14_CONSTEXPR bool has_value() const noexcept
TYPED_TEST_CASE(SynchronizedTest, SynchronizedTestTypes)
—— Concurrent Priority Queue Implementation ——
PerfectIndexMap< typename T::TKey, T::TOtherKey, T::TNoneKey, T::Hash, T::TAllowDuplicates, T::TCaseInsensitive > testMap_
testing::Types< PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, false, true, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes >, PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, true, true, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes >, PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, true, false, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes >, PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, false, false, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes > > TestTypes
TYPED_TEST(SynchronizedTest, Basic)
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept
#define EXPECT_TRUE(condition)
const uint8_t HTTPHeaderCodeCommonOffset
FOLLY_CPP14_CONSTEXPR const Value & value() const &
#define EXPECT_FALSE(condition)
#define ASSERT_TRUE(condition)