| 440 | |
| 441 | template <typename Value, typename Func1, typename Func2> |
| 442 | Status GetOrInsert(Value&& v, Func1&& on_found, Func2&& on_not_found, |
| 443 | int32_t* out_memo_index) { |
| 444 | const Scalar value(std::forward<Value>(v)); |
| 445 | auto cmp_func = [value](const Payload* payload) -> bool { |
| 446 | return ScalarHelper<Scalar, 0>::CompareScalars(value, payload->value); |
| 447 | }; |
| 448 | hash_t h = ComputeHash(value); |
| 449 | auto p = hash_table_.Lookup(h, cmp_func); |
| 450 | int32_t memo_index; |
| 451 | if (p.second) { |
| 452 | memo_index = p.first->payload.memo_index; |
| 453 | on_found(memo_index); |
| 454 | } else { |
| 455 | memo_index = size(); |
| 456 | RETURN_NOT_OK(hash_table_.Insert(p.first, h, {value, memo_index})); |
| 457 | on_not_found(memo_index); |
| 458 | } |
| 459 | *out_memo_index = memo_index; |
| 460 | return Status::OK(); |
| 461 | } |
| 462 | |
| 463 | template <typename Value> |
| 464 | Status GetOrInsert(Value&& value, int32_t* out_memo_index) { |