insert a new string into dictionary, return its insertion order
| 37 | |
| 38 | // insert a new string into dictionary, return its insertion order |
| 39 | size_t SortedStringDictionary::insert(const char* str, size_t len) { |
| 40 | size_t index = keyToIndex_.size(); |
| 41 | |
| 42 | auto it = keyToIndex_.find(std::string_view{str, len}); |
| 43 | if (it != keyToIndex_.end()) { |
| 44 | return it->second; |
| 45 | } else { |
| 46 | auto s = Arena::Create<std::string>(arena_.get(), str, len); |
| 47 | keyToIndex_.emplace(std::string_view{s->data(), s->length()}, index); |
| 48 | totalLength_ += len; |
| 49 | return index; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // reserve space for dictionary entries |
| 54 | void SortedStringDictionary::reserve(size_t size) { |