unordered_set.hpp 837 Bytes
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1 2 3 4 5 6 7
/*
 * (C) 2017 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */
#ifndef __THALLIUM_UNORDERED_SET_SERIALIZATION_HPP
#define __THALLIUM_UNORDERED_SET_SERIALIZATION_HPP
8 9 10 11 12 13 14

#include <utility>
#include <unordered_set>

namespace thallium {

template<class A, typename V, class Hash, class Pred, class Alloc>
15
inline void save(A& ar, std::unordered_set<V,Hash,Pred,Alloc>& s) {
16 17 18 19 20
    size_t size = s.size();
    ar.write(&size);
    for(auto& elem : s) {
        ar & elem;
    }
21 22 23
}

template<class A, typename V, class Hash, class Pred, class Alloc>
24
inline void load(A& ar, std::unordered_set<V,Hash,Pred,Alloc>& s) {
25 26 27 28 29 30 31 32 33
    size_t size;
    ar.read(&size);
    s.clear();
    s.reserve(size);
    for(unsigned int i=0; i<size; i++) {
        V item;;
        ar & item;
        s.insert(std::move(item));
    }
34 35 36 37 38
}

}

#endif