| 1779 | |
| 1780 | template<typename T> |
| 1781 | void apply_symbol_table_operations( |
| 1782 | std::vector<std::pair<std::string, T>> & initial_elements, |
| 1783 | std::vector<symbol_table_operation<T>> & pending_operations) |
| 1784 | { |
| 1785 | auto lower_bound = [&initial_elements](std::string const & str) { |
| 1786 | return std::lower_bound( |
| 1787 | initial_elements.begin(), |
| 1788 | initial_elements.end(), |
| 1789 | str, |
| 1790 | [](auto const & a, auto b) { |
| 1791 | return a.first < b; |
| 1792 | }); |
| 1793 | }; |
| 1794 | |
| 1795 | for (auto & op : pending_operations) { |
| 1796 | if (op.kind_ == symbol_table_op::insert) { |
| 1797 | auto it = lower_bound(op.key_); |
| 1798 | if (it == initial_elements.end() || |
| 1799 | it->first != op.key_) { |
| 1800 | initial_elements.insert( |
| 1801 | it, |
| 1802 | std::pair<std::string, T>( |
| 1803 | std::move(op.key_), std::move(*op.value_))); |
| 1804 | } else { |
| 1805 | it->second = std::move(*op.value_); |
| 1806 | } |
| 1807 | } else if (op.kind_ == symbol_table_op::erase) { |
| 1808 | auto it = lower_bound(op.key_); |
| 1809 | if (it != initial_elements.end() && it->first == op.key_) |
| 1810 | initial_elements.erase(it); |
| 1811 | } else { |
| 1812 | initial_elements.clear(); |
| 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | pending_operations.clear(); |
| 1817 | } |
| 1818 | |
| 1819 | template<typename Context, typename T> |
| 1820 | auto get_trie( |