| 722 | } |
| 723 | |
| 724 | static std::pair<ValueType*, bool> insert_recurse( |
| 725 | NodePtr* insertNode, uint64_t hash, int hashPos, |
| 726 | HighsHashTableEntry<K, V>& entry) { |
| 727 | switch (insertNode->getType()) { |
| 728 | case kEmpty: { |
| 729 | if (hashPos == kMaxDepth) { |
| 730 | ListLeaf* leaf = new ListLeaf(std::move(entry)); |
| 731 | *insertNode = leaf; |
| 732 | return std::make_pair(&leaf->first.entry.value(), true); |
| 733 | } else { |
| 734 | InnerLeaf<1>* leaf = new InnerLeaf<1>; |
| 735 | *insertNode = leaf; |
| 736 | return leaf->insert_entry(hash, hashPos, entry); |
| 737 | } |
| 738 | } |
| 739 | case kListLeaf: { |
| 740 | ListLeaf* leaf = insertNode->getListLeaf(); |
| 741 | ListNode* iter = &leaf->first; |
| 742 | while (true) { |
| 743 | // check for existing key |
| 744 | if (iter->entry.key() == entry.key()) |
| 745 | return std::make_pair(&iter->entry.value(), false); |
| 746 | |
| 747 | if (iter->next == nullptr) { |
| 748 | // reached the end of the list and key is not duplicate, so insert |
| 749 | iter->next = new ListNode(std::move(entry)); |
| 750 | ++leaf->count; |
| 751 | return std::make_pair(&iter->next->entry.value(), true); |
| 752 | } |
| 753 | iter = iter->next; |
| 754 | } |
| 755 | |
| 756 | break; |
| 757 | } |
| 758 | case kInnerLeafSizeClass1: |
| 759 | return insert_into_leaf(insertNode, |
| 760 | insertNode->getInnerLeafSizeClass1(), hash, |
| 761 | hashPos, entry); |
| 762 | break; |
| 763 | case kInnerLeafSizeClass2: |
| 764 | return insert_into_leaf(insertNode, |
| 765 | insertNode->getInnerLeafSizeClass2(), hash, |
| 766 | hashPos, entry); |
| 767 | break; |
| 768 | case kInnerLeafSizeClass3: |
| 769 | return insert_into_leaf(insertNode, |
| 770 | insertNode->getInnerLeafSizeClass3(), hash, |
| 771 | hashPos, entry); |
| 772 | break; |
| 773 | case kInnerLeafSizeClass4: { |
| 774 | InnerLeaf<4>* leaf = insertNode->getInnerLeafSizeClass4(); |
| 775 | if (leaf->size < InnerLeaf<4>::capacity()) |
| 776 | return leaf->insert_entry(hash, hashPos, entry); |
| 777 | |
| 778 | auto existingEntry = leaf->find_entry(hash, hashPos, entry.key()); |
| 779 | if (existingEntry) return std::make_pair(existingEntry, false); |
| 780 | Occupation occupation = leaf->occupation; |
| 781 |
nothing calls this directly
no test coverage detected