16 #ifndef IMPALA_UTIL_CONTAINER_UTIL_H
17 #define IMPALA_UTIL_CONTAINER_UTIL_H
20 #include <boost/unordered_map.hpp>
23 #include "gen-cpp/Types_types.h"
29 inline std::size_t
hash_value(
const TNetworkAddress& host_port) {
31 HashUtil::Hash(host_port.hostname.c_str(), host_port.hostname.length(), 0);
32 return HashUtil::Hash(&host_port.port,
sizeof(host_port.port), hash);
41 const TNetworkAddress*
const& p2)
const {
42 return p1->hostname == p2->hostname && p1->port == p2->port;
50 template <
typename K,
typename V>
51 V*
FindOrInsert(std::map<K,V>* m,
const K& key,
const V& default_val) {
52 typename std::map<K,V>::iterator it = m->find(key);
54 it = m->insert(std::make_pair(key, default_val)).first;
59 template <
typename K,
typename V>
60 V*
FindOrInsert(boost::unordered_map<K,V>* m,
const K& key,
const V& default_val) {
61 typename boost::unordered_map<K,V>::iterator it = m->find(key);
63 it = m->insert(std::make_pair(key, default_val)).first;
72 template <
typename K,
typename V>
73 const V&
FindWithDefault(
const std::map<K, V>& m,
const K& key,
const V& default_val) {
74 typename std::map<K,V>::const_iterator it = m.find(key);
75 if (it == m.end())
return default_val;
79 template <
typename K,
typename V>
81 const V& default_val) {
82 typename boost::unordered_map<K,V>::const_iterator it = m.find(key);
83 if (it == m.end())
return default_val;
89 template<
typename K,
typename V>
91 for (
typename std::map<K, V>::const_iterator src_it = src.begin();
92 src_it != src.end(); ++src_it) {
93 typename std::map<K, V>::iterator dst_it = dst->find(src_it->first);
94 if (dst_it == dst->end()) {
95 (*dst)[src_it->first] = src_it->second;
97 dst_it->second += src_it->second;
const StringSearch UrlParser::hash_search & hash
std::size_t hash_value(const Decimal4Value &v)
This function must be called 'hash_value' to be picked up by boost.
V * FindOrInsert(std::map< K, V > *m, const K &key, const V &default_val)
static uint32_t Hash(const void *data, int32_t bytes, uint32_t seed)
const V & FindWithDefault(const std::map< K, V > &m, const K &key, const V &default_val)
size_t operator()(const TNetworkAddress *const &p) const
bool operator()(const TNetworkAddress *const &p1, const TNetworkAddress *const &p2) const
void MergeMapValues(const std::map< K, V > &src, std::map< K, V > *dst)