unordered_map.hpp 974 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_MAP_SERIALIZATION_HPP
#define __THALLIUM_UNORDERED_MAP_SERIALIZATION_HPP
8

9 10 11 12 13 14
#include <thallium/config.hpp>

#ifdef THALLIUM_USE_CEREAL
    #include <cereal/types/unordered_map.hpp>
#else

15 16 17 18 19
#include <unordered_map>

namespace thallium {

template<class A, typename K, typename V, class Hash, class Pred, class Alloc>
20
inline void save(A& ar, std::unordered_map<K,V,Hash,Pred,Alloc>& m) {
21 22 23 24 25 26
    size_t size = m.size();
    ar.write(&size);
    for(auto& elem : m) {
        ar & elem.first;
        ar & elem.second;
    }
27 28 29
}

template<class A, typename K, typename V, class Hash, class Pred, class Alloc>
30
inline void load(A& ar, std::unordered_map<K,V,Hash,Pred,Alloc>& m) {
31 32 33 34 35 36 37 38 39
    size_t size;
    ar.read(&size);
    m.clear();
    m.reserve(size);
    for(unsigned int i=0; i<size; i++) {
        K k;
        ar & k;
        ar & m[k];
    }
40 41 42 43 44
}

}

#endif
45
#endif