Horizon Official Technical Documentation
LockedLookupTable< Key, Value, Hash > Class Template Reference

#include <LockedLookupTable.hpp>

Classes

class  bucket_type
 

Public Types

typedef Key key_type
 
typedef Value mapped_type
 
typedef Hash hash_type
 

Public Member Functions

 LockedLookupTable (unsigned num_buckets=19, const Hash &hasher_=Hash())
 
 LockedLookupTable (const LockedLookupTable &other)=delete
 
LockedLookupTableoperator= (const LockedLookupTable &other)=delete
 
Value const & operator[] (Key &k)
 
Value at (Key const &key, Value const &default_value=Value()) const
 
void insert (const Key &key, const Value &value)
 
void erase (const Key &key)
 
std::map< Key, Value > get_map () const
 
int max_collisions ()
 
std::size_t size ()
 
void clear ()
 

Private Member Functions

bucket_typeget_bucket (Key const &key) const
 

Private Attributes

std::vector< std::unique_ptr< bucket_type > > _buckets
 
Hash hasher
 

Member Typedef Documentation

◆ hash_type

template<typename Key , typename Value , typename Hash = std::hash<Key>>
typedef Hash LockedLookupTable< Key, Value, Hash >::hash_type

◆ key_type

template<typename Key , typename Value , typename Hash = std::hash<Key>>
typedef Key LockedLookupTable< Key, Value, Hash >::key_type

◆ mapped_type

template<typename Key , typename Value , typename Hash = std::hash<Key>>
typedef Value LockedLookupTable< Key, Value, Hash >::mapped_type

Constructor & Destructor Documentation

◆ LockedLookupTable() [1/2]

template<typename Key , typename Value , typename Hash = std::hash<Key>>
LockedLookupTable< Key, Value, Hash >::LockedLookupTable ( unsigned  num_buckets = 19,
const Hash &  hasher_ = Hash() 
)
inline
52 : _buckets(num_buckets), hasher(hasher_)
53 {
54 for (unsigned i = 0; i < num_buckets; ++i)
55 _buckets[i].reset(new bucket_type);
56 }
Hash hasher
Definition: LockedLookupTable.hpp:122
std::vector< std::unique_ptr< bucket_type > > _buckets
Definition: LockedLookupTable.hpp:121

References LockedLookupTable< Key, Value, Hash >::_buckets.

◆ LockedLookupTable() [2/2]

template<typename Key , typename Value , typename Hash = std::hash<Key>>
LockedLookupTable< Key, Value, Hash >::LockedLookupTable ( const LockedLookupTable< Key, Value, Hash > &  other)
delete

Member Function Documentation

◆ at()

template<typename Key , typename Value , typename Hash = std::hash<Key>>
Value LockedLookupTable< Key, Value, Hash >::at ( Key const &  key,
Value const &  default_value = Value() 
) const
inline
64 {
65 return get_bucket(key).at(key, default_value);
66 }
Value at(Key const &key, Value const &default_value)
Definition: LockedLookupTable.hpp:138
bucket_type & get_bucket(Key const &key) const
Definition: LockedLookupTable.hpp:124

References LockedLookupTable< Key, Value, Hash >::bucket_type::at(), and LockedLookupTable< Key, Value, Hash >::get_bucket().

Referenced by BOOST_AUTO_TEST_CASE(), Horizon::Zone::NPCComponent::contact_npc_for_player(), Horizon::Auth::PacketLengthTable::get_hpacket_info(), Horizon::Char::PacketLengthTable::get_hpacket_info(), Horizon::Zone::PacketLengthTable::get_hpacket_info(), Horizon::Zone::ItemDatabase::get_item_by_id(), Horizon::Zone::ItemDatabase::get_item_by_key_name(), Horizon::Zone::MonsterDatabase::get_monster_by_id(), Horizon::Zone::MonsterDatabase::get_monster_by_name(), Horizon::Zone::MonsterDatabase::get_monster_skill_by_id(), Horizon::Zone::GameLogicProcess::MonsterSpawnAgent::get_monster_spawn_info(), Horizon::Zone::NPCComponent::get_npc_from_db(), Horizon::Zone::SkillDatabase::get_skill_by_id(), Horizon::Zone::SkillDatabase::get_skill_by_name(), Horizon::Zone::SkillDatabase::get_skill_tree_by_job_id(), Horizon::Zone::ExpDatabase::get_status_point(), Horizon::Auth::PacketLengthTable::get_tpacket_info(), Horizon::Char::PacketLengthTable::get_tpacket_info(), Horizon::Zone::PacketLengthTable::get_tpacket_info(), Horizon::Zone::ItemDatabase::get_weapon_attribute_modifier(), Horizon::Zone::ItemDatabase::get_weapon_target_size_modifier(), Horizon::Zone::ExpDatabase::load_group(), LockedLookupTable< Key, Value, Hash >::operator[](), and Horizon::Zone::NPCComponent::sync_functions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear()

template<typename Key , typename Value , typename Hash = std::hash<Key>>
void LockedLookupTable< Key, Value, Hash >::clear ( )
inline
113 {
114 for (unsigned i = 0; i < _buckets.size(); ++i) {
115 boost::unique_lock<boost::shared_mutex> lock(_buckets[i]->_mutex);
116 _buckets[i]->data.clear();
117 }
118 }

References LockedLookupTable< Key, Value, Hash >::_buckets.

Referenced by Horizon::Zone::GameLogicProcess::MonsterSpawnAgent::clear_monster_spawn_info().

+ Here is the caller graph for this function:

◆ erase()

template<typename Key , typename Value , typename Hash = std::hash<Key>>
void LockedLookupTable< Key, Value, Hash >::erase ( const Key &  key)
inline
74 {
75 get_bucket(key).erase(key);
76 }
void erase(Key const &key)
Definition: LockedLookupTable.hpp:156

References LockedLookupTable< Key, Value, Hash >::bucket_type::erase(), and LockedLookupTable< Key, Value, Hash >::get_bucket().

Referenced by BOOST_AUTO_TEST_CASE(), and Horizon::Zone::ExpDatabase::load_group().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_bucket()

template<typename Key , typename Value , typename Hash = std::hash<Key>>
bucket_type & LockedLookupTable< Key, Value, Hash >::get_bucket ( Key const &  key) const
inlineprivate
125 {
126 const std::size_t bucket_index = hasher(key) % _buckets.size();
127 return *_buckets[bucket_index];
128 }

References LockedLookupTable< Key, Value, Hash >::_buckets, and LockedLookupTable< Key, Value, Hash >::hasher.

Referenced by LockedLookupTable< Key, Value, Hash >::at(), LockedLookupTable< Key, Value, Hash >::erase(), and LockedLookupTable< Key, Value, Hash >::insert().

+ Here is the caller graph for this function:

◆ get_map()

template<typename Key , typename Value , typename Hash = std::hash<Key>>
std::map< Key, Value > LockedLookupTable< Key, Value, Hash >::get_map ( ) const
inline
79 {
80 std::map<Key, Value> res;
81
82 for (unsigned i = 0; i < _buckets.size(); ++i) {
83 boost::unique_lock<boost::shared_mutex> lock(_buckets[i]->_mutex);
84 for (typename bucket_type::bucket_iterator it = _buckets[i]->data.begin();
85 it != _buckets[i]->data.end();
86 ++it) {
87 res.insert(*it);
88 }
89 }
90
91 return res;
92 }
bucket_data::iterator bucket_iterator
Definition: LockedLookupTable.hpp:136

References LockedLookupTable< Key, Value, Hash >::_buckets.

Referenced by BOOST_AUTO_TEST_CASE().

+ Here is the caller graph for this function:

◆ insert()

◆ max_collisions()

template<typename Key , typename Value , typename Hash = std::hash<Key>>
int LockedLookupTable< Key, Value, Hash >::max_collisions ( )
inline
94{ return _buckets[0]->data.size() ? _buckets[0]->data.size() - 1 : 0; }

References LockedLookupTable< Key, Value, Hash >::_buckets.

Referenced by BOOST_AUTO_TEST_CASE(), and Horizon::Zone::ItemDatabase::load().

+ Here is the caller graph for this function:

◆ operator=()

template<typename Key , typename Value , typename Hash = std::hash<Key>>
LockedLookupTable & LockedLookupTable< Key, Value, Hash >::operator= ( const LockedLookupTable< Key, Value, Hash > &  other)
delete

◆ operator[]()

template<typename Key , typename Value , typename Hash = std::hash<Key>>
Value const & LockedLookupTable< Key, Value, Hash >::operator[] ( Key &  k)
inline
61{ at(k); }
Value at(Key const &key, Value const &default_value=Value()) const
Definition: LockedLookupTable.hpp:63

References LockedLookupTable< Key, Value, Hash >::at().

+ Here is the call graph for this function:

◆ size()

template<typename Key , typename Value , typename Hash = std::hash<Key>>
std::size_t LockedLookupTable< Key, Value, Hash >::size ( )
inline
97 {
98 std::size_t count = 0;
99
100 for (unsigned i = 0; i < _buckets.size(); ++i) {
101 boost::unique_lock<boost::shared_mutex> lock(_buckets[i]->_mutex);
102 for (typename bucket_type::bucket_iterator it = _buckets[i]->data.begin();
103 it != _buckets[i]->data.end();
104 ++it) {
105 count++;
106 }
107 }
108
109 return count;
110 }
size_t count(GridTypeListContainer< SPECIFIC_TYPE > const &elements, SPECIFIC_TYPE *)
Definition: GridReferenceContainer.hpp:100

References LockedLookupTable< Key, Value, Hash >::_buckets, and GridTypeListIterator::count().

Referenced by BOOST_AUTO_TEST_CASE(), Horizon::Zone::ExpDatabase::get_status_point(), and Horizon::Zone::ItemDatabase::load_items().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _buckets

◆ hasher

template<typename Key , typename Value , typename Hash = std::hash<Key>>
Hash LockedLookupTable< Key, Value, Hash >::hasher
private

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