| 689 | |
| 690 | template <typename Func1, typename Func2> |
| 691 | Status GetOrInsert(const void* data, builder_offset_type length, Func1&& on_found, |
| 692 | Func2&& on_not_found, int32_t* out_memo_index) { |
| 693 | hash_t h = ComputeStringHash<0>(data, length); |
| 694 | auto p = Lookup(h, data, length); |
| 695 | int32_t memo_index; |
| 696 | if (p.second) { |
| 697 | memo_index = p.first->payload.memo_index; |
| 698 | on_found(memo_index); |
| 699 | } else { |
| 700 | memo_index = size(); |
| 701 | // Insert string value |
| 702 | RETURN_NOT_OK(binary_builder_.Append(static_cast<const char*>(data), length)); |
| 703 | // Insert hash entry |
| 704 | RETURN_NOT_OK( |
| 705 | hash_table_.Insert(const_cast<HashTableEntry*>(p.first), h, {memo_index})); |
| 706 | |
| 707 | on_not_found(memo_index); |
| 708 | } |
| 709 | *out_memo_index = memo_index; |
| 710 | return Status::OK(); |
| 711 | } |
| 712 | |
| 713 | template <typename Func1, typename Func2> |
| 714 | Status GetOrInsert(std::string_view value, Func1&& on_found, Func2&& on_not_found, |
no test coverage detected