GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
unordered_set.hpp
1 /**
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 
24 #ifndef GRAPHLAB_SERIALIZE_UNORDERED_SET_HPP
25 #define GRAPHLAB_SERIALIZE_UNORDERED_SET_HPP
26 
27 #include <boost/unordered_set.hpp>
28 #include <graphlab/serialization/iarchive.hpp>
29 #include <graphlab/serialization/oarchive.hpp>
30 #include <graphlab/serialization/iterator.hpp>
31 
32 namespace graphlab {
33 namespace archive_detail {
34  /** serializes a set */
35  template <typename OutArcType, typename T>
36  struct serialize_impl<OutArcType, boost::unordered_set<T>, false > {
37  static void exec(OutArcType& oarc, const boost::unordered_set<T>& vec){
38  serialize_iterator(oarc,
39  vec.begin(), vec.end(), vec.size());
40  }
41  };
42 
43  /** deserializes a set */
44  template <typename InArcType, typename T>
45  struct deserialize_impl<InArcType, boost::unordered_set<T>, false > {
46  static void exec(InArcType& iarc, boost::unordered_set<T>& vec){
47  vec.clear();
48  // get the number of elements to deserialize
49  size_t length = 0;
50  iarc >> length;
51  // iterate through and send to the output iterator
52  for (size_t x = 0; x < length ; ++x){
53  T v;
54  iarc >> v;
55  vec.insert(v);
56  }
57  }
58  };
59 
60 } // archive_detail
61 } // graphlab
62 
63 #endif
64