Commit 11c15b0b authored by Tiago Peixoto's avatar Tiago Peixoto

Replace unordered_map/set for gt_hash_map/set whenever possible

parent a6667db7
......@@ -23,6 +23,7 @@
#include "graph_closeness.hh"
#include <functional>
#include <boost/python.hpp>
using namespace std;
using namespace graph_tool;
......
......@@ -26,7 +26,7 @@
#include <boost/python/extract.hpp>
#include "histogram.hh"
#include "numpy_bind.hh"
#include "hash_map_wrap.hh"
namespace graph_tool
{
......@@ -182,8 +182,8 @@ struct get_closeness
{
using namespace boost;
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
typedef unordered_map<vertex_t,default_color_type,
DescriptorHash<VertexIndex> > cmap_t;
typedef gt_hash_map<vertex_t,default_color_type,
DescriptorHash<VertexIndex> > cmap_t;
cmap_t cmap(0, DescriptorHash<VertexIndex>(vertex_index));
InitializedPropertyMap<cmap_t>
color_map(cmap, color_traits<default_color_type>::white());
......
......@@ -20,7 +20,7 @@
#ifndef GRAPH_EXTENDED_CLUSTERING_HH
#define GRAPH_EXTENDED_CLUSTERING_HH
#include <unordered_set>
#include "hash_map_wrap.hh"
#include <boost/graph/breadth_first_search.hpp>
......@@ -134,7 +134,7 @@ struct get_extended_clustering
fg_t fg(g, keep_all(), filter_t(v));
typedef DescriptorHash<IndexMap> hasher_t;
typedef std::unordered_set<vertex_t,hasher_t> neighbour_set_t;
typedef gt_hash_set<vertex_t,hasher_t> neighbour_set_t;
neighbour_set_t neighbours(0, hasher_t(vertex_index));
neighbour_set_t targets(0, hasher_t(vertex_index));
typename neighbour_set_t::iterator ni, ti;
......@@ -161,14 +161,14 @@ struct get_extended_clustering
// And now we setup and start the BFS bonanza
for (ni = neighbours.begin(); ni != neighbours.end(); ++ni)
{
typedef std::unordered_map<vertex_t,size_t,
DescriptorHash<IndexMap> > dmap_t;
typedef gt_hash_map<vertex_t,size_t,
DescriptorHash<IndexMap> > dmap_t;
dmap_t dmap(0, DescriptorHash<IndexMap>(vertex_index));
InitializedPropertyMap<dmap_t>
distance_map(dmap, numeric_limits<size_t>::max());
typedef std::unordered_map<vertex_t,default_color_type,
DescriptorHash<IndexMap> > cmap_t;
typedef gt_hash_map<vertex_t,default_color_type,
DescriptorHash<IndexMap> > cmap_t;
cmap_t cmap(0, DescriptorHash<IndexMap>(vertex_index));
InitializedPropertyMap<cmap_t>
color_map(cmap, color_traits<default_color_type>::white());
......
......@@ -19,12 +19,12 @@
#define GRAPH_MOTIFS_HH
#include <boost/graph/isomorphism.hpp>
#include <unordered_set>
#include <boost/functional/hash.hpp>
#include <algorithm>
#include <vector>
#include "random.hh"
#include "hash_map_wrap.hh"
namespace graph_tool
{
......@@ -313,9 +313,9 @@ struct get_all_motifs
any_cast<std::vector<graph_sg_t>&>(list);
// this hashes subgraphs according to their signature
std::unordered_map<std::vector<size_t>,
std::vector<pair<size_t, graph_sg_t> >,
std::hash<std::vector<size_t>>> sub_list;
gt_hash_map<std::vector<size_t>,
std::vector<pair<size_t, graph_sg_t> >,
std::hash<std::vector<size_t>>> sub_list;
std::vector<size_t> sig; // current signature
for (size_t i = 0; i < subgraph_list.size(); ++i)
......
......@@ -687,7 +687,7 @@ void vector_continuous_map(boost::python::object ovals)
{
multi_array_ref<Value,1> vals = get_array<Value,1>(ovals);
unordered_map<Value, size_t> map;
gt_hash_map<Value, size_t> map;
for (size_t i = 0; i < vals.size(); ++i)
{
......
......@@ -260,7 +260,7 @@ struct entropy_parallel_edges
auto get_node = [](size_t i) {return i;};
for (auto v : vertices_range(g))
{
unordered_map<decltype(v), int> us;
gt_hash_map<decltype(v), int> us;
for (auto e : out_edges_range(v, g))
{
auto u = target(e, g);
......@@ -1911,7 +1911,7 @@ void merge_vertices(size_t u, size_t v, Eprop& eweight_u, Vprop& vweight, Graph&
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
typedef typename graph_traits<Graph>::edge_descriptor edge_t;
unordered_map<vertex_t, vector<edge_t>> ns_u, ns_v;
gt_hash_map<vertex_t, vector<edge_t>> ns_u, ns_v;
for(auto e : out_edges_range(u, g))
ns_u[target(e, g)].push_back(e);
for(auto e : out_edges_range(v, g))
......@@ -2154,7 +2154,7 @@ double virtual_move(const Vec& vs, size_t s, Vprop& b, VLprop& cv, VVprop& vmap,
if (s == size_t(b[vs[0]]))
return 0;
unordered_map<int, vector<size_t>> us;
gt_hash_map<int, vector<size_t>> us;
for (size_t i = 0; i < vs.size(); ++i)
{
size_t v = vs[i];
......@@ -2200,7 +2200,7 @@ double virtual_move(const Vec& vs, size_t s, Vprop& b, VLprop& cv, VVprop& vmap,
if (multigraph && !dense && state.overlap_stats.is_enabled())
{
std::unordered_map<int, size_t> bundles;
gt_hash_map<int, size_t> bundles;
auto& mi = state.overlap_stats.get_mi();
for (auto w : iter.second)
{
......@@ -2333,7 +2333,7 @@ void move_vertex(const Vec& vs, size_t s, Vprop& b, VLprop& cv, VVprop& vmap,
if (s == r)
return;
unordered_map<int, vector<size_t>> us;
gt_hash_map<int, vector<size_t>> us;
for (size_t i = 0; i < vs.size(); ++i)
{
auto& ls = cv[vs[i]];
......@@ -2443,7 +2443,7 @@ void move_sweep(vector<BlockState>& states, vector<MEntries>& m_entries_r,
}
// used only if merging
std::unordered_set<vertex_t> past_moves;
gt_hash_set<vertex_t> past_moves;
vector<pair<vertex_t, double> > best_move;
if (nmerges > 0 || parallel)
best_move.resize(num_vertices(g), make_pair(vertex_t(0), numeric_limits<double>::max()));
......
......@@ -42,7 +42,7 @@ struct ec_hist
void operator()(Graph&g, const EVMap& ev, EMap& ec) const
{
typedef typename property_traits<EVMap>::value_type val_t;
unordered_map<val_t, size_t> ehist;
gt_hash_map<val_t, size_t> ehist;
for (auto e : edges_range(g))
{
auto iter = ehist.find(ev[e]);
......@@ -76,7 +76,7 @@ struct split_graph
std::vector<std::reference_wrapper<VMap>>& block_rmap,
std::vector<std::reference_wrapper<VMap>>& uvmap) const
{
std::vector<unordered_map<size_t, size_t>> vhmap(num_vertices(g));
std::vector<gt_hash_map<size_t, size_t>> vhmap(num_vertices(g));
auto get_v = [&] (size_t v, size_t l) -> size_t
{
......
......@@ -576,7 +576,7 @@ struct get_bv_overlap
{
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
typedef unordered_map<int, int> map_t;
typedef gt_hash_map<int, int> map_t;
vector<map_t> hist_in;
vector<map_t> hist_out;
......@@ -730,7 +730,7 @@ struct get_augmented_overlap
void operator()(Graph& g, VProp b, VIProp node_index, VProp br_map,
vector<int32_t>& br_b, vector<int32_t>& br_ni) const
{
unordered_map<std::tuple<int, int>, size_t> idx_map;
gt_hash_map<std::tuple<int, int>, size_t> idx_map;
vector<std::tuple<int, int>> idx_rmap;
size_t pos = 0;
......@@ -788,7 +788,7 @@ struct get_overlap_split
template <class Graph, class VVProp, class VProp>
void operator()(Graph& g, VVProp bv, VProp b) const
{
unordered_map<vector<int>, size_t> bvset;
gt_hash_map<vector<int>, size_t> bvset;
for (auto v : vertices_range(g))
{
......
......@@ -19,8 +19,6 @@
#define GRAPH_BLOCKMODEL_OVERLAP_HH
#include "config.h"
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include "graph_blockmodel.hh"
......@@ -96,7 +94,7 @@ public:
{
auto& he = half_edges[i];
unordered_map<size_t, vector<size_t>> out_us;
gt_hash_map<size_t, vector<size_t>> out_us;
for (auto u : he)
{
auto w = _out_neighbours[u];
......@@ -1760,7 +1758,7 @@ void merge_sweep_overlap(vector<BlockState>& states,
Vprop best_move = b.copy();
vector<double> best_move_dS;
vector<vector<vertex_t>> groups(B);
vector<unordered_map<size_t, vector<size_t>>> bundles(B);
vector<gt_hash_map<size_t, vector<size_t>>> bundles(B);
best_move_dS.resize(B, numeric_limits<double>::max());
std::shuffle(vlist.begin(), vlist.end(), rng);
......
......@@ -18,7 +18,6 @@
#ifndef GRAPH_COMMUNITY_HH
#define GRAPH_COMMUNITY_HH
#include <unordered_set>
#include <tuple>
#include <iostream>
#include <fstream>
......@@ -30,6 +29,7 @@
#include "graph_util.hh"
#include "graph_properties.hh"
#include "random.hh"
#include "hash_map_wrap.hh"
namespace graph_tool
{
......@@ -37,9 +37,6 @@ namespace graph_tool
using namespace std;
using namespace boost;
using std::unordered_map;
using std::unordered_set;
// computes the community structure through a spin glass system with
// simulated annealing
......@@ -74,7 +71,7 @@ struct get_communities
double Tmin = Tinterval.first;
double Tmax = Tinterval.second;
unordered_map<size_t, size_t> Ns; // spin histogram
gt_hash_map<size_t, size_t> Ns; // spin histogram
CommunityMap temp_s(vertex_index, num_vertices(g));
// init spins from [0,N-1] and global info
......@@ -120,7 +117,7 @@ struct get_communities
new_s = sample_spin(rng);
}
unordered_map<size_t, double> ns; // number of neighbours with a
gt_hash_map<size_t, double> ns; // number of neighbours with a
// given spin 's' (weighted)
// neighborhood spins info
......@@ -221,7 +218,7 @@ struct get_communities
}
// rename spins, starting from zero
unordered_map<size_t,size_t> spins;
gt_hash_map<size_t,size_t> spins;
for (tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
{
if (spins.find(s[*vi]) == spins.end())
......@@ -270,7 +267,7 @@ public:
private:
double _p;
unordered_map<size_t,size_t> _Ns;
gt_hash_map<size_t,size_t> _Ns;
};
template <class Graph, class CommunityMap>
......@@ -308,7 +305,7 @@ public:
private:
const Graph& _g;
size_t _K;
unordered_map<size_t,size_t> _Ks;
gt_hash_map<size_t,size_t> _Ks;
};
template <class Graph, class CommunityMap>
......@@ -317,7 +314,7 @@ class NNKSCorr
public:
NNKSCorr(const Graph &g, CommunityMap s): _g(g)
{
unordered_set<size_t> spins;
gt_hash_set<size_t> spins;
typename graph_traits<Graph>::vertex_iterator v,v_end;
for (tie(v,v_end) = vertices(_g); v != v_end; ++v)
......@@ -387,9 +384,9 @@ public:
continue;
if (_Pkk.find(k1)->second.find(k2) == _Pkk.find(k1)->second.end())
continue;
unordered_map<size_t,double>& NNks_k1 = _NNks[k1];
gt_hash_map<size_t,double>& NNks_k1 = _NNks[k1];
double Pk1k2 = _Pkk[k1][k2];
unordered_map<size_t,size_t>& Nksk2 = _Nks[k2];
gt_hash_map<size_t,size_t>& Nksk2 = _Nks[k2];
double Nk2 = _Nk[k2];
NNks_k1[old_s] -= k1*Pk1k2 * Nksk2[old_s]/Nk2;
if (NNks_k1[old_s] == 0.0)
......@@ -413,9 +410,9 @@ public:
continue;
if (_Pkk.find(k1)->second.find(k2) == _Pkk.find(k1)->second.end())
continue;
unordered_map<size_t,double>& NNks_k1 = _NNks[k1];
gt_hash_map<size_t,double>& NNks_k1 = _NNks[k1];
double Pk1k2 = _Pkk[k1][k2];
unordered_map<size_t,size_t>& Nksk2 = _Nks[k2];
gt_hash_map<size_t,size_t>& Nksk2 = _Nks[k2];
double Nk2 = _Nk[k2];
NNks_k1[old_s] += k1*Pk1k2 * Nksk2[old_s]/Nk2;
if (NNks_k1[old_s] == 0.0)
......@@ -427,7 +424,7 @@ public:
double operator()(size_t k, size_t s) const
{
const unordered_map<size_t,double>& nnks = _NNks.find(k)->second;
const gt_hash_map<size_t,double>& nnks = _NNks.find(k)->second;
const typeof(nnks.begin()) iter = nnks.find(s);
if (iter != nnks.end())
return iter->second;
......@@ -437,10 +434,10 @@ public:
private:
const Graph& _g;
vector<size_t> _degs;
unordered_map<size_t,size_t> _Nk;
unordered_map<size_t,unordered_map<size_t,double> > _Pkk;
unordered_map<size_t,unordered_map<size_t,size_t> > _Nks;
unordered_map<size_t,unordered_map<size_t,double> > _NNks;
gt_hash_map<size_t,size_t> _Nk;
gt_hash_map<size_t,gt_hash_map<size_t,double> > _Pkk;
gt_hash_map<size_t,gt_hash_map<size_t,size_t> > _Nks;
gt_hash_map<size_t,gt_hash_map<size_t,double> > _NNks;
};
enum comm_corr_t
......
......@@ -18,10 +18,9 @@
#ifndef GRAPH_ASSORTATIVITY_HH
#define GRAPH_ASSORTATIVITY_HH
#include <unordered_map>
#include "shared_map.hh"
#include "graph_util.hh"
#include "hash_map_wrap.hh"
namespace graph_tool
{
......@@ -46,7 +45,7 @@ struct get_assortativity_coefficient
count_t e_kk = 0;
typedef typename DegreeSelector::value_type val_t;
typedef unordered_map<val_t, count_t> map_t;
typedef gt_hash_map<val_t, count_t> map_t;
map_t a, b;
SharedMap<map_t> sa(a), sb(b);
......
......@@ -18,7 +18,6 @@
#ifndef GRAPH_GENERATION_HH
#define GRAPH_GENERATION_HH
#include <unordered_map>
#include <tuple>
#include <boost/functional/hash.hpp>
#include <map>
......@@ -27,6 +26,7 @@
#include "graph_util.hh"
#include "random.hh"
#include "hash_map_wrap.hh"
namespace graph_tool
{
......@@ -465,7 +465,7 @@ struct gen_graph
set<deg_t, cmp_in<greater<size_t> > > targets;
// vertices with a given degree
unordered_map<deg_t, vector<size_t>> vset;
gt_hash_map<deg_t, vector<size_t>> vset;
size_t num_e = 0;
for (size_t i = 0; i < vertices.size(); ++i)
......
......@@ -23,7 +23,7 @@
#include "graph_util.hh"
#include "random.hh"
#include <unordered_set>
#include "hash_map_wrap.hh"
#include <map>
#include <iostream>
......@@ -61,8 +61,7 @@ struct get_price
if (probs.empty() || probs.rbegin()->first <= 0)
throw GraphException("Cannot connect edges: probabilities are <= 0!");
std::unordered_set<typename graph_traits<Graph>::vertex_descriptor>
visited;
gt_hash_set<typename graph_traits<Graph>::vertex_descriptor> visited;
for (size_t i = 0; i < N; ++i)
{
visited.clear();
......
......@@ -691,7 +691,7 @@ public:
if (_probs.empty())
{
std::unordered_set<deg_t> deg_set;
gt_hash_set<deg_t> deg_set;
for (size_t ei = 0; ei < base_t::_edges.size(); ++ei)
{
edge_t& e = base_t::_edges[ei];
......@@ -829,7 +829,7 @@ public:
if (!is_directed::apply<Graph>::type::value)
_out_pos.resize(base_t::_edges.size());
std::unordered_set<deg_t> deg_set;
gt_hash_set<deg_t> deg_set;
for (size_t ei = 0; ei < base_t::_edges.size(); ++ei)
{
edge_t& e = base_t::_edges[ei];
......@@ -893,8 +893,8 @@ public:
}
else
{
std::unordered_map<deg_t, vector<double>> sprobs;
std::unordered_map<deg_t, vector<deg_t>> sitems;
gt_hash_map<deg_t, vector<double>> sprobs;
gt_hash_map<deg_t, vector<deg_t>> sitems;
for (auto iter = _probs.begin(); iter != _probs.end(); ++iter)
{
deg_t s = iter->first.first;
......@@ -1130,7 +1130,7 @@ private:
sampler_map_t _sampler;
typedef gt_hash_map<deg_t, std::unordered_map<deg_t, double>> sprob_map_t;
typedef gt_hash_map<deg_t, gt_hash_map<deg_t, double>> sprob_map_t;
sprob_map_t _sprob;
......@@ -1173,7 +1173,7 @@ public:
_vertices[d].push_back(*v);
}
std::unordered_map<pair<deg_t, deg_t>, double> probs;
gt_hash_map<pair<deg_t, deg_t>, double> probs;
_corr_prob.get_probs(probs);
vector<double> dprobs;
......
......@@ -23,12 +23,12 @@
#ifndef GRAPH_TRIANGULATION_HH
#define GRAPH_TRIANGULATION_HH
#include <unordered_set>
#include <tuple>
#include <boost/functional/hash.hpp>
#include "graph_util.hh"
#include "hash_map_wrap.hh"
namespace graph_tool
{
......@@ -106,7 +106,7 @@ struct get_triangulation
template <class Graph, class Points, class PosMap>
void operator()(Graph& g, Points& points, PosMap pos) const
{
typedef std::unordered_map
typedef gt_hash_map
<typename Triang::Vertex,
typename graph_traits<Graph>::vertex_descriptor,
hash_point> vertex_map_t;
......
......@@ -21,8 +21,7 @@
#include "graph_filtering.hh"
#include "graph_selectors.hh"
#include "graph_util.hh"
#include <unordered_set>
#include "hash_map_wrap.hh"
#include <boost/mpl/for_each.hpp>
......@@ -163,7 +162,7 @@ struct do_infect_vertex_property
typedef typename property_traits<PropertyMap>::value_type val_t;
bool all = false;
std::unordered_set<val_t, std::hash<val_t> > vals;
gt_hash_set<val_t> vals;
if (oval == boost::python::object())
{
all = true;
......@@ -264,7 +263,7 @@ struct do_perfect_vhash
{
typedef typename property_traits<VertexPropertyMap>::value_type val_t;
typedef typename property_traits<HashProp>::value_type hash_t;
typedef unordered_map<val_t, hash_t> dict_t;
typedef gt_hash_map<val_t, hash_t> dict_t;
if (adict.empty())
adict = dict_t();
......@@ -303,7 +302,7 @@ struct do_perfect_ehash
{
typedef typename property_traits<EdgePropertyMap>::value_type val_t;
typedef typename property_traits<HashProp>::value_type hash_t;
typedef unordered_map<val_t, hash_t> dict_t;
typedef gt_hash_map<val_t, hash_t> dict_t;
if (adict.empty())
adict = dict_t();
......
......@@ -21,8 +21,6 @@
#include <typeinfo>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <random>
#include <functional>
......@@ -46,6 +44,7 @@
#include "graph.hh"
#include "graph_exceptions.hh"
#include "hash_map_wrap.hh"
// this file provides general functions for manipulating graph properties
......@@ -528,7 +527,7 @@ class HashedDescriptorMap
{
public:
typedef DescriptorHash<IndexMap> hashfc_t;
typedef unordered_map<typename IndexMap::key_type,Value,hashfc_t>
typedef gt_hash_map<typename IndexMap::key_type,Value,hashfc_t>
map_t;
typedef boost::associative_property_map<map_t> prop_map_t;
......
......@@ -24,6 +24,7 @@
#include "graph_sfdp.hh"
#include "random.hh"
#include "hash_map_wrap.hh"
using namespace std;
using namespace boost;
......@@ -96,7 +97,7 @@ struct do_propagate_pos
typedef typename pos_t::value_type val_t;
uniform_real_distribution<val_t> noise(-delta, delta);
unordered_map<c_t, pos_t> cmap(num_vertices(*cg));
gt_hash_map<c_t, pos_t> cmap;
for (auto v : vertices_range(*cg))
cmap[cvmap[v]] = cpos[v];
......@@ -133,7 +134,6 @@ void propagate_pos(GraphInterface& gi, GraphInterface& cgi, boost::any vmap,
GraphInterface::vertex_index_map_t>::type>::type
vmaps_t;
run_action<>()
(gi, std::bind(do_propagate_pos(),
placeholders::_1, placeholders::_2, placeholders::_3,
......
......@@ -27,6 +27,7 @@
#include "histogram.hh"
#include "numpy_bind.hh"
#include "hash_map_wrap.hh"
namespace graph_tool
{
......@@ -137,8 +138,8 @@ struct get_distance_histogram
DistanceMap dist_map, no_weightS) const
{
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
typedef unordered_map<vertex_t,default_color_type,
DescriptorHash<VertexIndex> > cmap_t;
typedef gt_hash_map<vertex_t,default_color_type,
DescriptorHash<VertexIndex> > cmap_t;
cmap_t cmap(0, DescriptorHash<VertexIndex>(vertex_index));
InitializedPropertyMap<cmap_t>
color_map(cmap, color_traits<default_color_type>::white());
......
......@@ -27,6 +27,7 @@
#include "histogram.hh"
#include "numpy_bind.hh"
#include "hash_map_wrap.hh"
namespace graph_tool
{
......@@ -152,8 +153,8 @@ struct get_sampled_distance_histogram
DistanceMap dist_map, no_weightS) const
{
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
typedef unordered_map<vertex_t,default_color_type,
DescriptorHash<VertexIndex> > cmap_t;
typedef gt_hash_map<vertex_t,default_color_type,
DescriptorHash<VertexIndex> > cmap_t;
cmap_t cmap(0, DescriptorHash<VertexIndex>(vertex_index));
InitializedPropertyMap<cmap_t>
color_map(cmap, color_traits<default_color_type>::white());
......
......@@ -20,6 +20,7 @@
#include "graph_properties.hh"
#include "graph_selectors.hh"
#include "numpy_bind.hh"
#include "hash_map_wrap.hh"
#include <boost/graph/breadth_first_search.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
......@@ -83,7 +84,7 @@ class bfs_max_multiple_targets_visitor:
public:
bfs_max_multiple_targets_visitor(DistMap dist_map, PredMap pred,
size_t max_dist,
std::unordered_set<std::size_t> target)
gt_hash_set<std::size_t> target)