jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
lsh_vector.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 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_STORAGE_LSH_VECTOR_HPP_
18 #define JUBATUS_CORE_STORAGE_LSH_VECTOR_HPP_
19 
20 #include <stdint.h>
21 #include <ostream>
22 #include <utility>
23 #include <vector>
24 #include "jubatus/util/data/unordered_map.h"
25 
26 namespace jubatus {
27 namespace core {
28 namespace storage {
29 
30 class lsh_vector {
31  public:
32  lsh_vector();
33  lsh_vector(const lsh_vector& lv);
34  explicit lsh_vector(size_t len);
35  explicit lsh_vector(const std::vector<int>& v);
36  ~lsh_vector();
37 
38  bool operator==(const lsh_vector& lv) const;
39  bool operator!=(const lsh_vector& lv) const;
40 
41  int get(size_t pos) const;
42  void set(size_t pos, int value);
43  void push_back(int value);
44 
45  void resize_and_clear(size_t sz);
46  size_t size() const;
47 
48  lsh_vector slice(size_t from, size_t len) const;
49  lsh_vector cut(size_t from, size_t len) const;
50 
51  void debug_print(std::ostream& os) const;
52 
53  void swap(lsh_vector& lv);
54 
55  private:
56  friend class jubatus::util::data::hash<lsh_vector>;
57 
58  std::vector<int> values_;
59 };
60 
61 inline void swap(lsh_vector& l, lsh_vector& r) { // NOLINT
62  l.swap(r);
63 }
64 
65 inline std::ostream& operator<<(std::ostream& os, const lsh_vector& lv) {
66  lv.debug_print(os);
67  return os;
68 }
69 
70 } // namespace storage
71 } // namespace core
72 
73 namespace util {
74 namespace data {
75 
76 template<>
78  public:
79  uint64_t operator()(const jubatus::core::storage::lsh_vector& lv) const {
80  const char* p = reinterpret_cast<const char*>(&lv.values_[0]);
81  const size_t len = lv.size() * sizeof(lv.values_[0]);
82  const char* const end = p + len;
83 
84  uint64_t x = 14695981039346656037ull;
85  while (p != end) {
86  x *= 1099511628211ull;
87  x ^= static_cast<uint64_t>(*p++);
88  }
89  return x;
90  }
91 };
92 
93 } // namespace data
94 } // namespace util
95 } // namespace jubatus
96 
97 #endif // JUBATUS_CORE_STORAGE_LSH_VECTOR_HPP_
lsh_vector slice(size_t from, size_t len) const
Definition: lsh_vector.cpp:78
bool operator==(const lsh_vector &lv) const
Definition: lsh_vector.cpp:48
void debug_print(std::ostream &os) const
Definition: lsh_vector.cpp:100
lsh_vector cut(size_t from, size_t len) const
Definition: lsh_vector.cpp:88
uint64_t operator()(const jubatus::core::storage::lsh_vector &lv) const
Definition: lsh_vector.hpp:79
void swap(lsh_vector &l, lsh_vector &r)
Definition: lsh_vector.hpp:61
void set(size_t pos, int value)
Definition: lsh_vector.cpp:60
std::vector< T > v(size)
std::ostream & operator<<(std::ostream &os, const version &v)
Definition: version.cpp:24
bool operator!=(const lsh_vector &lv) const
Definition: lsh_vector.cpp:52