jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
unordered_map.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2011,2012 Preferred Networks and Nippon Telegraph and Telephone Corporation.
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License version 2.1 as published by the Free Software Foundation.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 #ifndef JUBATUS_CORE_COMMON_UNORDERED_MAP_HPP_
18 #define JUBATUS_CORE_COMMON_UNORDERED_MAP_HPP_
19 
20 #include <msgpack.hpp>
21 #include "jubatus/util/data/unordered_map.h"
22 
23 // to make util::data::unordered_map serializable
24 
25 namespace msgpack {
26 
27 template<typename K, typename V, typename H, typename E, typename A>
28 inline jubatus::util::data::unordered_map<K, V, H, E, A> operator>>(
29  object o,
30  jubatus::util::data::unordered_map<K, V, H, E, A>& v) {
31  if (o.type != type::MAP) {
32  throw type_error();
33  }
34  object_kv* const p_end = o.via.map.ptr + o.via.map.size;
35  for (object_kv* p = o.via.map.ptr; p != p_end; ++p) {
36  K key;
37  p->key.convert(&key);
38  p->val.convert(&v[key]);
39  }
40  return v;
41 }
42 
43 template<typename Stream,
44  typename K,
45  typename V,
46  typename H,
47  typename E,
48  typename A>
50  packer<Stream>& o,
51  const jubatus::util::data::unordered_map<K, V, H, E, A>& v) {
52  o.pack_map(v.size());
53  typedef typename
54  jubatus::util::data::unordered_map<K, V, H, E, A>::const_iterator
55  iter_t;
56  for (iter_t it = v.begin(); it != v.end(); ++it) {
57  o.pack(it->first);
58  o.pack(it->second);
59  }
60  return o;
61 }
62 
63 } // namespace msgpack
64 
65 #endif // JUBATUS_CORE_COMMON_UNORDERED_MAP_HPP_
packer< Stream > & operator<<(packer< Stream > &o, const jubatus::core::common::byte_buffer &b)
std::vector< T > v(size)
jubatus::core::common::byte_buffer & operator>>(object o, jubatus::core::common::byte_buffer &b)