jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
jubatus::core::common::key_manager Class Reference

#include <key_manager.hpp>

Collaboration diagram for jubatus::core::common::key_manager:
Collaboration graph

Public Types

enum  { NOTFOUND = 0xFFFFFFFFFFFFFFFFLLU }
 

Public Member Functions

void clear ()
 
void delete_key (const std::string &name)
 
std::vector< std::string > get_all_id2key () const
 
uint64_t get_id (const std::string &key)
 
uint64_t get_id_const (const std::string &key) const
 
const std::string & get_key (const uint64_t id) const
 
uint64_t get_max_id () const
 
void init_by_id2key (const std::vector< std::string > &id2key)
 
 key_manager ()
 
 MSGPACK_DEFINE (key2id_, id2key_, next_id_)
 
bool set_key (const std::string &key)
 
size_t size () const
 
void swap (key_manager &km)
 

Private Member Functions

uint64_t append_key (const std::string &key)
 

Private Attributes

util::data::unordered_map< uint64_t, std::string > id2key_
 
util::data::unordered_map< std::string, uint64_t > key2id_
 
uint64_t next_id_
 

Friends

std::ostream & operator<< (std::ostream &os, const key_manager &km)
 

Detailed Description

Definition at line 34 of file key_manager.hpp.

Member Enumeration Documentation

anonymous enum
Enumerator
NOTFOUND 

Definition at line 36 of file key_manager.hpp.

36  {
37  NOTFOUND = 0xFFFFFFFFFFFFFFFFLLU
38  };

Constructor & Destructor Documentation

jubatus::core::common::key_manager::key_manager ( )

Definition at line 35 of file key_manager.cpp.

36  : next_id_(0llu) {
37 }

Member Function Documentation

uint64_t jubatus::core::common::key_manager::append_key ( const std::string &  key)
private

Definition at line 39 of file key_manager.cpp.

References id2key_, JUBATUS_ASSERT_EQ, key2id_, and next_id_.

Referenced by get_id(), and set_key().

39  {
40  JUBATUS_ASSERT_EQ(true, // must not exist
41  key2id_.end() == key2id_.find(key),
42  "existing key appended");
43  key2id_[key] = next_id_;
44  id2key_[next_id_] = key;
45  return next_id_++;
46 }
#define JUBATUS_ASSERT_EQ(a, b, messages)
Definition: assert.hpp:63
util::data::unordered_map< uint64_t, std::string > id2key_
Definition: key_manager.hpp:84
util::data::unordered_map< std::string, uint64_t > key2id_
Definition: key_manager.hpp:83

Here is the caller graph for this function:

void jubatus::core::common::key_manager::clear ( )

Definition at line 98 of file key_manager.cpp.

References id2key_, key2id_, next_id_, and swap().

Referenced by jubatus::core::storage::lsh_index_storage::clear().

98  {
99  jubatus::util::data::unordered_map<std::string, uint64_t>().swap(key2id_);
100  jubatus::util::data::unordered_map<uint64_t, std::string>().swap(id2key_);
101  next_id_ = 0u;
102 }
util::data::unordered_map< uint64_t, std::string > id2key_
Definition: key_manager.hpp:84
util::data::unordered_map< std::string, uint64_t > key2id_
Definition: key_manager.hpp:83

Here is the call graph for this function:

Here is the caller graph for this function:

void jubatus::core::common::key_manager::delete_key ( const std::string &  name)

Definition at line 115 of file key_manager.cpp.

References get_id_const(), id2key_, key2id_, and NOTFOUND.

Referenced by jubatus::core::storage::local_storage::delete_label_nolock(), and jubatus::core::storage::local_storage_mixture::delete_label_nolock().

115  {
116  const uint64_t id = get_id_const(name);
117  if (id != NOTFOUND) {
118  key2id_.erase(name);
119  id2key_.erase(id);
120  }
121 }
uint64_t get_id_const(const std::string &key) const
Definition: key_manager.cpp:67
util::data::unordered_map< uint64_t, std::string > id2key_
Definition: key_manager.hpp:84
util::data::unordered_map< std::string, uint64_t > key2id_
Definition: key_manager.hpp:83

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< std::string > jubatus::core::common::key_manager::get_all_id2key ( ) const

Definition at line 87 of file key_manager.cpp.

References id2key_.

Referenced by jubatus::core::storage::local_storage::get_labels(), jubatus::core::storage::local_storage_mixture::get_labels(), jubatus::core::storage::local_storage_mixture::inp(), and jubatus::core::storage::local_storage::inp().

87  {
88  std::vector<std::string> ret;
89  ret.reserve(id2key_.size());
90  for (unordered_map<uint64_t, string>::const_iterator it = id2key_.begin();
91  it != id2key_.end();
92  ++it) {
93  ret.push_back(it->second);
94  }
95  return ret;
96 }
util::data::unordered_map< uint64_t, std::string > id2key_
Definition: key_manager.hpp:84

Here is the caller graph for this function:

uint64_t jubatus::core::common::key_manager::get_id ( const std::string &  key)

Definition at line 48 of file key_manager.cpp.

References append_key(), and key2id_.

Referenced by jubatus::core::storage::local_storage_mixture::bulk_update(), jubatus::core::storage::local_storage::bulk_update(), jubatus::core::storage::inverted_index_storage::put_diff(), jubatus::core::storage::local_storage::register_label(), jubatus::core::storage::local_storage_mixture::register_label(), jubatus::core::storage::sparse_matrix_storage::set(), jubatus::core::storage::inverted_index_storage::set(), jubatus::core::storage::local_storage::set(), jubatus::core::storage::local_storage_mixture::set2_nolock(), jubatus::core::storage::local_storage::set2_nolock(), jubatus::core::storage::local_storage_mixture::set3_nolock(), jubatus::core::storage::local_storage::set3_nolock(), jubatus::core::storage::local_storage_mixture::set_average_and_clear_diff(), jubatus::core::storage::lsh_index_storage::set_mixed_row(), jubatus::core::storage::local_storage_mixture::set_nolock(), jubatus::core::storage::local_storage::set_nolock(), jubatus::core::storage::sparse_matrix_storage::set_row(), jubatus::core::storage::lsh_index_storage::set_row(), jubatus::core::storage::local_storage_mixture::update(), and jubatus::core::storage::local_storage::update().

48  {
49  cit it = key2id_.find(key);
50  if (it != key2id_.end()) {
51  return it->second;
52  }
53  // TODO(beam2d): Make it exception safe.
54  return append_key(key);
55 }
unordered_map< string, uint64_t >::const_iterator cit
Definition: key_manager.cpp:33
util::data::unordered_map< std::string, uint64_t > key2id_
Definition: key_manager.hpp:83
uint64_t append_key(const std::string &key)
Definition: key_manager.cpp:39

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t jubatus::core::common::key_manager::get_id_const ( const std::string &  key) const
const string & jubatus::core::common::key_manager::get_key ( const uint64_t  id) const
uint64_t jubatus::core::common::key_manager::get_max_id ( ) const

Definition at line 123 of file key_manager.cpp.

References next_id_.

Referenced by jubatus::core::storage::inverted_index_storage::calc_scores().

123  {
124  return next_id_ - 1;
125 }

Here is the caller graph for this function:

void jubatus::core::common::key_manager::init_by_id2key ( const std::vector< std::string > &  id2key)

Definition at line 104 of file key_manager.cpp.

References id2key_, key2id_, and next_id_.

104  {
105  key2id_.clear();
106  id2key_.clear();
107 
108  for (size_t i = 0; i < id2key.size(); ++i) {
109  key2id_[id2key[i]] = i;
110  id2key_[i] = id2key[i];
111  }
112  next_id_ = id2key.size();
113 }
util::data::unordered_map< uint64_t, std::string > id2key_
Definition: key_manager.hpp:84
util::data::unordered_map< std::string, uint64_t > key2id_
Definition: key_manager.hpp:83
jubatus::core::common::key_manager::MSGPACK_DEFINE ( key2id_  ,
id2key_  ,
next_id_   
)
bool jubatus::core::common::key_manager::set_key ( const std::string &  key)

Definition at line 57 of file key_manager.cpp.

References append_key(), and key2id_.

Referenced by jubatus::core::storage::local_storage::set_label(), and jubatus::core::storage::local_storage_mixture::set_label().

57  {
58  cit it = key2id_.find(key);
59  if (it != key2id_.end()) {
60  return false;
61  }
62  // TODO(kumagi): Make it exception safe.
63  append_key(key);
64  return true;
65 }
unordered_map< string, uint64_t >::const_iterator cit
Definition: key_manager.cpp:33
util::data::unordered_map< std::string, uint64_t > key2id_
Definition: key_manager.hpp:83
uint64_t append_key(const std::string &key)
Definition: key_manager.cpp:39

Here is the call graph for this function:

Here is the caller graph for this function:

size_t jubatus::core::common::key_manager::size ( ) const
inline

Definition at line 50 of file key_manager.hpp.

References key2id_.

Referenced by jubatus::core::storage::local_storage_mixture::get_status(), and jubatus::core::storage::local_storage::get_status().

50  {
51  return key2id_.size();
52  }
util::data::unordered_map< std::string, uint64_t > key2id_
Definition: key_manager.hpp:83

Here is the caller graph for this function:

void jubatus::core::common::key_manager::swap ( key_manager km)
inline

Definition at line 45 of file key_manager.hpp.

References id2key_, and key2id_.

Referenced by jubatus::core::storage::inverted_index_storage::clear(), jubatus::core::storage::sparse_matrix_storage::clear(), clear(), jubatus::core::storage::local_storage::clear(), jubatus::core::storage::local_storage_mixture::clear(), and jubatus::core::common::swap().

45  {
46  key2id_.swap(km.key2id_);
47  id2key_.swap(km.id2key_);
48  }
util::data::unordered_map< uint64_t, std::string > id2key_
Definition: key_manager.hpp:84
util::data::unordered_map< std::string, uint64_t > key2id_
Definition: key_manager.hpp:83

Here is the caller graph for this function:

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const key_manager km 
)
friend

Definition at line 66 of file key_manager.hpp.

66  {
67  typedef jubatus::util::data::unordered_map<std::string, uint64_t> key2id_t;
68  os << "[";
69  for (key2id_t::const_iterator it = km.key2id_.begin();
70  it != km.key2id_.end();
71  ++it) {
72  os << it->first << ":" << it->second << ", ";
73  }
74  os << "]";
75  return os;
76  }

Member Data Documentation

util::data::unordered_map<uint64_t, std::string> jubatus::core::common::key_manager::id2key_
private
util::data::unordered_map<std::string, uint64_t> jubatus::core::common::key_manager::key2id_
private
uint64_t jubatus::core::common::key_manager::next_id_
private

Definition at line 82 of file key_manager.hpp.

Referenced by append_key(), clear(), get_max_id(), and init_by_id2key().


The documentation for this class was generated from the following files: