50 static_assert(
sizeof(
Key) == 1,
"Key must be of size 1 byte.");
58 auto key = PerfectHashStrToKey(keyStr);
59 if (key == OtherKey) {
60 const std::string *result = getSingleOtherKey(keyStr);
65 return getSingleOrNone(key);
69 CHECK(key != OtherKey && key != NoneKey);
79 CHECK(AllowDuplicates);
80 auto key = PerfectHashStrToKey(keyStr);
81 if (key == OtherKey) {
82 addOtherKeyToIndex(keyStr, value);
89 CHECK(AllowDuplicates && key != OtherKey && key != NoneKey);
90 addKeyToIndex(key, value);
98 auto key = PerfectHashStrToKey(keyStr);
99 if (key == OtherKey) {
100 setOtherKey(keyStr,
value);
107 CHECK(key != OtherKey && key != NoneKey);
116 auto key = PerfectHashStrToKey(keyStr);
117 if (key == OtherKey) {
118 return removeOtherKey(keyStr);
124 CHECK(key != OtherKey && key != NoneKey);
125 return removeKey(key);
129 return keys_.size() - noneKeyCount_;
141 const Key*
data = keys_.data();
143 auto offset = searchForKey(key, data);
145 if (AllowDuplicates && searchForKey(key, ++data) != -1) {
148 return &values_[offset];
154 size_t searchIndex = 0;
155 auto index = searchForOtherKey(keyStr, searchIndex);
157 if (AllowDuplicates && searchForOtherKey(keyStr, ++searchIndex) != -1) {
160 return &values_[index];
166 const Key*
data = keys_.data();
168 std::ptrdiff_t offset;
170 offset = searchForKey(key, data);
173 replaceKeyAtIndex(offset, key, value);
174 if (AllowDuplicates) {
180 removeAtIndex(offset);
186 addKeyToIndex(key, value);
191 size_t searchIndex = 0;
192 while (searchForOtherKey(keyStr, searchIndex) != -1) {
194 replaceOtherKeyAtIndex(searchIndex, keyStr, value);
195 if (AllowDuplicates) {
201 removeAtIndex(otherKeyNamesKeysIndex_[searchIndex]);
206 addOtherKeyToIndex(keyStr, value);
211 const Key*
data = keys_.data();
212 bool anyRemoved =
false;
213 std::ptrdiff_t offset;
215 offset = searchForKey(key, data);
217 removeAtIndex(offset);
219 if (!AllowDuplicates) {
228 bool anyRemoved =
false;
229 size_t searchIndex = 0;
230 while (searchForOtherKey(keyStr, searchIndex) != -1) {
231 removeAtIndex(otherKeyNamesKeysIndex_[searchIndex]);
233 if (!AllowDuplicates) {
248 (
void*)
data, key, keys_.size() - (data - keys_.data()));
250 return data - keys_.data();
256 const std::string &keyStr,
size_t &startIndex)
const {
257 while (startIndex < otherKeyNamesKeysIndex_.size()) {
259 if (keys_[otherKeyNamesKeysIndex_[startIndex]] == OtherKey) {
260 if (CaseInsensitive) {
265 return otherKeyNamesKeysIndex_[startIndex];
268 if (otherKeyNames_[startIndex] == keyStr) {
269 return otherKeyNamesKeysIndex_[startIndex];
280 keys_.push_back(key);
281 values_.emplace_back(value);
284 keys_.push_back(OtherKey);
285 otherKeyNames_.emplace_back(keyStr);
286 otherKeyNamesKeysIndex_.push_back(keys_.size() - 1);
287 values_.emplace_back(value);
293 values_[index] =
value;
297 otherKeyNames_[namesIndex] = keyStr;
298 values_[otherKeyNamesKeysIndex_[namesIndex]] =
value;
303 CHECK(keys_[index] != NoneKey);
304 if (keys_[index] == OtherKey) {
307 keys_[index] = NoneKey;
340 size_t otherKeyCount_{0};
341 size_t noneKeyCount_{0};
bool removeOtherKey(const std::string &keyStr)
bool caseInsensitiveEqual(folly::StringPiece s, folly::StringPiece t)
internal::KeyMatcher< M > Key(M inner_matcher)
void add(Key key, const std::string &value)
std::ptrdiff_t searchForOtherKey(const std::string &keyStr, size_t &startIndex) const
folly::fbvector< std::string > otherKeyNames_
const std::string * getSingleKey(Key key) const
folly::fbvector< std::string > values_
const std::string * getSingleOtherKey(const std::string &keyStr) const
std::ptrdiff_t searchForKey(Key key, const Key *&data) const
folly::Optional< std::string > getSingleOrNone(Key key) const
void setOtherKey(const std::string &keyStr, const std::string &value)
void replaceKeyAtIndex(std::ptrdiff_t index, Key key, const std::string &value)
void addOtherKeyToIndex(const std::string &keyStr, const std::string &value)
void removeAtIndex(std::ptrdiff_t index)
void add(const std::string &keyStr, const std::string &value)
static const char *const value
folly::Optional< std::string > getSingleOrNone(const std::string &keyStr) const
void addKeyToIndex(Key key, const std::string &value)
void setKey(Key key, const std::string &value)
folly::fbvector< size_t > otherKeyNamesKeysIndex_
void replaceOtherKeyAtIndex(size_t namesIndex, const std::string &keyStr, const std::string &value)
static constexpr uint64_t data[1]
folly::fbvector< Key > keys_