forked from boostorg/unordered
		
	Implement merge
This commit is contained in:
		@@ -3840,6 +3840,30 @@ struct table_impl : boost::unordered::detail::table<Types>
 | 
			
		||||
        return iterator(pos);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    template <typename Types2> void merge_impl(table_impl<Types2>& other)
 | 
			
		||||
    {
 | 
			
		||||
        if (other.size_) {
 | 
			
		||||
            link_pointer prev = other.get_previous_start();
 | 
			
		||||
 | 
			
		||||
            while (prev->next_) {
 | 
			
		||||
                node_pointer n = other.next_node(prev);
 | 
			
		||||
                const_key_type& k = this->get_key(n->value());
 | 
			
		||||
                std::size_t key_hash = this->hash(k);
 | 
			
		||||
                node_pointer pos = this->find_node(key_hash, k);
 | 
			
		||||
 | 
			
		||||
                if (pos) {
 | 
			
		||||
                    prev = n;
 | 
			
		||||
                } else {
 | 
			
		||||
                    this->reserve_for_insert(this->size_ + 1);
 | 
			
		||||
                    prev->next_ = n->next_;
 | 
			
		||||
                    --other.size_;
 | 
			
		||||
                    other.fix_bucket(other.hash_to_bucket(n->hash_), prev);
 | 
			
		||||
                    this->add_node(n, key_hash);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ////////////////////////////////////////////////////////////////////////
 | 
			
		||||
    // Insert range methods
 | 
			
		||||
    //
 | 
			
		||||
 
 | 
			
		||||
@@ -617,6 +617,17 @@ template <class K, class T, class H, class P, class A> class unordered_map
 | 
			
		||||
    void clear();
 | 
			
		||||
    void swap(unordered_map&);
 | 
			
		||||
 | 
			
		||||
    template <typename H2, typename P2>
 | 
			
		||||
    void merge(boost::unordered_map<K, T, H2, P2, A>& source);
 | 
			
		||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
 | 
			
		||||
    template <typename H2, typename P2>
 | 
			
		||||
    void merge(boost::unordered_map<K, T, H2, P2, A>&& source);
 | 
			
		||||
#endif
 | 
			
		||||
    // template <typename H2, typename P2>
 | 
			
		||||
    // void merge(boost::unordered_multimap<K,T,H2,P2,A>& source);
 | 
			
		||||
    // template <typename H2, typename P2>
 | 
			
		||||
    // void merge(boost::unordered_multimap<K,T,H2,P2,A>&& source);
 | 
			
		||||
 | 
			
		||||
    // observers
 | 
			
		||||
 | 
			
		||||
    hasher hash_function() const;
 | 
			
		||||
@@ -1055,6 +1066,17 @@ template <class K, class T, class H, class P, class A> class unordered_multimap
 | 
			
		||||
    void clear();
 | 
			
		||||
    void swap(unordered_multimap&);
 | 
			
		||||
 | 
			
		||||
    template <typename H2, typename P2>
 | 
			
		||||
    void merge(boost::unordered_multimap<K, T, H2, P2, A>& source);
 | 
			
		||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
 | 
			
		||||
    template <typename H2, typename P2>
 | 
			
		||||
    void merge(boost::unordered_multimap<K, T, H2, P2, A>&& source);
 | 
			
		||||
#endif
 | 
			
		||||
    // template <typename H2, typename P2>
 | 
			
		||||
    // void merge(boost::unordered_map<K,T,H2,P2,A>& source);
 | 
			
		||||
    // template <typename H2, typename P2>
 | 
			
		||||
    // void merge(boost::unordered_map<K,T,H2,P2,A>&& source);
 | 
			
		||||
 | 
			
		||||
    // observers
 | 
			
		||||
 | 
			
		||||
    hasher hash_function() const;
 | 
			
		||||
@@ -1356,6 +1378,24 @@ void unordered_map<K, T, H, P, A>::swap(unordered_map& other)
 | 
			
		||||
    table_.swap(other.table_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class K, class T, class H, class P, class A>
 | 
			
		||||
template <typename H2, typename P2>
 | 
			
		||||
void unordered_map<K, T, H, P, A>::merge(
 | 
			
		||||
    boost::unordered_map<K, T, H2, P2, A>& source)
 | 
			
		||||
{
 | 
			
		||||
    table_.merge_impl(source.table_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
 | 
			
		||||
template <class K, class T, class H, class P, class A>
 | 
			
		||||
template <typename H2, typename P2>
 | 
			
		||||
void unordered_map<K, T, H, P, A>::merge(
 | 
			
		||||
    boost::unordered_map<K, T, H2, P2, A>&& source)
 | 
			
		||||
{
 | 
			
		||||
    table_.merge_impl(source.table_);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// observers
 | 
			
		||||
 | 
			
		||||
template <class K, class T, class H, class P, class A>
 | 
			
		||||
@@ -1756,6 +1796,28 @@ unordered_multimap<K, T, H, P, A>::key_eq() const
 | 
			
		||||
    return table_.key_eq();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class K, class T, class H, class P, class A>
 | 
			
		||||
template <typename H2, typename P2>
 | 
			
		||||
void unordered_multimap<K, T, H, P, A>::merge(
 | 
			
		||||
    boost::unordered_multimap<K, T, H2, P2, A>& source)
 | 
			
		||||
{
 | 
			
		||||
    while (!source.empty()) {
 | 
			
		||||
        insert(source.extract(source.begin()));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
 | 
			
		||||
template <class K, class T, class H, class P, class A>
 | 
			
		||||
template <typename H2, typename P2>
 | 
			
		||||
void unordered_multimap<K, T, H, P, A>::merge(
 | 
			
		||||
    boost::unordered_multimap<K, T, H2, P2, A>&& source)
 | 
			
		||||
{
 | 
			
		||||
    while (!source.empty()) {
 | 
			
		||||
        insert(source.extract(source.begin()));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// lookup
 | 
			
		||||
 | 
			
		||||
template <class K, class T, class H, class P, class A>
 | 
			
		||||
 
 | 
			
		||||
@@ -391,6 +391,17 @@ template <class T, class H, class P, class A> class unordered_set
 | 
			
		||||
    void clear();
 | 
			
		||||
    void swap(unordered_set&);
 | 
			
		||||
 | 
			
		||||
    template <typename H2, typename P2>
 | 
			
		||||
    void merge(boost::unordered_set<T, H2, P2, A>& source);
 | 
			
		||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
 | 
			
		||||
    template <typename H2, typename P2>
 | 
			
		||||
    void merge(boost::unordered_set<T, H2, P2, A>&& source);
 | 
			
		||||
#endif
 | 
			
		||||
    // template <typename H2, typename P2>
 | 
			
		||||
    // void merge(boost::unordered_multiset<T,H2,P2,A>& source);
 | 
			
		||||
    // template <typename H2, typename P2>
 | 
			
		||||
    // void merge(boost::unordered_multiset<T,H2,P2,A>&& source);
 | 
			
		||||
 | 
			
		||||
    // observers
 | 
			
		||||
 | 
			
		||||
    hasher hash_function() const;
 | 
			
		||||
@@ -817,6 +828,17 @@ template <class T, class H, class P, class A> class unordered_multiset
 | 
			
		||||
    void clear();
 | 
			
		||||
    void swap(unordered_multiset&);
 | 
			
		||||
 | 
			
		||||
    template <typename H2, typename P2>
 | 
			
		||||
    void merge(boost::unordered_multiset<T, H2, P2, A>& source);
 | 
			
		||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
 | 
			
		||||
    template <typename H2, typename P2>
 | 
			
		||||
    void merge(boost::unordered_multiset<T, H2, P2, A>&& source);
 | 
			
		||||
#endif
 | 
			
		||||
    // template <typename H2, typename P2>
 | 
			
		||||
    // void merge(boost::unordered_set<T,H2,P2,A>& source);
 | 
			
		||||
    // template <typename H2, typename P2>
 | 
			
		||||
    // void merge(boost::unordered_set<T,H2,P2,A>&& source);
 | 
			
		||||
 | 
			
		||||
    // observers
 | 
			
		||||
 | 
			
		||||
    hasher hash_function() const;
 | 
			
		||||
@@ -1123,6 +1145,24 @@ unordered_set<T, H, P, A>::key_eq() const
 | 
			
		||||
    return table_.key_eq();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class T, class H, class P, class A>
 | 
			
		||||
template <typename H2, typename P2>
 | 
			
		||||
void unordered_set<T, H, P, A>::merge(
 | 
			
		||||
    boost::unordered_set<T, H2, P2, A>& source)
 | 
			
		||||
{
 | 
			
		||||
    table_.merge_impl(source.table_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
 | 
			
		||||
template <class T, class H, class P, class A>
 | 
			
		||||
template <typename H2, typename P2>
 | 
			
		||||
void unordered_set<T, H, P, A>::merge(
 | 
			
		||||
    boost::unordered_set<T, H2, P2, A>&& source)
 | 
			
		||||
{
 | 
			
		||||
    table_.merge_impl(source.table_);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// lookup
 | 
			
		||||
 | 
			
		||||
template <class T, class H, class P, class A>
 | 
			
		||||
@@ -1460,6 +1500,28 @@ unordered_multiset<T, H, P, A>::key_eq() const
 | 
			
		||||
    return table_.key_eq();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class T, class H, class P, class A>
 | 
			
		||||
template <typename H2, typename P2>
 | 
			
		||||
void unordered_multiset<T, H, P, A>::merge(
 | 
			
		||||
    boost::unordered_multiset<T, H2, P2, A>& source)
 | 
			
		||||
{
 | 
			
		||||
    while (!source.empty()) {
 | 
			
		||||
        insert(source.extract(source.begin()));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
 | 
			
		||||
template <class T, class H, class P, class A>
 | 
			
		||||
template <typename H2, typename P2>
 | 
			
		||||
void unordered_multiset<T, H, P, A>::merge(
 | 
			
		||||
    boost::unordered_multiset<T, H2, P2, A>&& source)
 | 
			
		||||
{
 | 
			
		||||
    while (!source.empty()) {
 | 
			
		||||
        insert(source.extract(source.begin()));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// lookup
 | 
			
		||||
 | 
			
		||||
template <class T, class H, class P, class A>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user