use standard unordered containers (#673)

This commit is contained in:
Arvid Norberg 2016-04-30 16:53:20 -04:00
parent 4e97bf556c
commit 98fb7df56f
8 changed files with 33 additions and 87 deletions

View File

@ -49,10 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <set>
#include <list>
#include <stdarg.h> // for va_start, va_end
#if TORRENT_HAS_BOOST_UNORDERED
#include <boost/unordered_map.hpp>
#endif
#include <unordered_map>
#ifdef TORRENT_USE_OPENSSL
#include "libtorrent/ssl_stream.hpp"
@ -202,11 +199,7 @@ namespace libtorrent
friend class libtorrent::invariant_access;
#endif
typedef std::set<boost::shared_ptr<peer_connection> > connection_map;
#if TORRENT_HAS_BOOST_UNORDERED
typedef boost::unordered_map<sha1_hash, boost::shared_ptr<torrent> > torrent_map;
#else
typedef std::map<sha1_hash, boost::shared_ptr<torrent> > torrent_map;
#endif
typedef std::unordered_map<sha1_hash, boost::shared_ptr<torrent> > torrent_map;
session_impl(io_service& ios);
virtual ~session_impl();

View File

@ -587,10 +587,6 @@ int snprintf(char* buf, int len, char const* fmt, ...)
#define TORRENT_USE_I2P 1
#endif
#ifndef TORRENT_HAS_BOOST_UNORDERED
#define TORRENT_HAS_BOOST_UNORDERED 1
#endif
#if !defined TORRENT_IOV_MAX
#ifdef IOV_MAX
#define TORRENT_IOV_MAX IOV_MAX

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <string>
#include <vector>
#include <unordered_set>
#include <ctime>
#include <boost/cstdint.hpp>
@ -498,7 +499,7 @@ namespace libtorrent
// levels. i.e. if one path in the torrent is ``foo/bar/baz``, the CRC32
// hashes for ``foo``, ``foo/bar`` and ``foo/bar/baz`` will be added to
// the set.
void all_path_hashes(boost::unordered_set<boost::uint32_t>& table) const;
void all_path_hashes(std::unordered_set<boost::uint32_t>& table) const;
// flags indicating various attributes for files in
// a file_storage.

View File

@ -35,23 +35,15 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <vector>
#include <deque>
#include <map>
#include <unordered_map>
#include <boost/cstdint.hpp>
#include <boost/pool/pool.hpp>
#include <boost/function/function3.hpp>
#if TORRENT_HAS_BOOST_UNORDERED
#include <boost/unordered_map.hpp>
#else
#include <multimap>
#endif
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <libtorrent/socket.hpp>
#include <libtorrent/entry.hpp>
#include <libtorrent/kademlia/node_id.hpp>
#include <libtorrent/kademlia/observer.hpp>
@ -59,7 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent { namespace aux { struct session_impl; } }
namespace libtorrent { struct dht_settings; }
namespace libtorrent { struct dht_settings; class entry; }
namespace libtorrent { namespace dht
{
@ -117,11 +109,7 @@ private:
mutable boost::pool<> m_pool_allocator;
#if TORRENT_HAS_BOOST_UNORDERED
typedef boost::unordered_multimap<int, observer_ptr> transactions_t;
#else
typedef std::multimap<int, observer_ptr> transactions_t;
#endif
typedef std::unordered_multimap<int, observer_ptr> transactions_t;
transactions_t m_transactions;
udp_socket_interface* m_sock;

View File

@ -319,6 +319,7 @@ namespace libtorrent
};
// this is here to support usage of sha1_hash in boost unordered containers
typedef sha1_hash peer_id;
inline std::size_t hash_value(sha1_hash const& b)
{
@ -349,5 +350,20 @@ namespace libtorrent
#endif // TORRENT_USE_IOSTREAM
}
namespace std {
template <>
struct hash<libtorrent::sha1_hash>
{
std::size_t operator()(libtorrent::sha1_hash const& k) const
{
std::size_t ret;
// this is OK because sha1_hash is already a hash
std::memcpy(&ret, k.data(), sizeof(ret));
return ret;
}
};
}
#endif // TORRENT_PEER_ID_HPP_INCLUDED

View File

@ -637,7 +637,7 @@ namespace libtorrent
template <class CRC>
void process_path_lowercase(
boost::unordered_set<boost::uint32_t>& table
std::unordered_set<boost::uint32_t>& table
, CRC crc
, char const* str, int len)
{
@ -653,7 +653,7 @@ namespace libtorrent
}
void file_storage::all_path_hashes(
boost::unordered_set<boost::uint32_t>& table) const
std::unordered_set<boost::uint32_t>& table) const
{
boost::crc_optimal<32, 0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, true, true> crc;

View File

@ -40,11 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <algorithm>
#if defined TORRENT_DEBUG && !defined TORRENT_DISABLE_INVARIANT_CHECKS
#if TORRENT_HAS_BOOST_UNORDERED
#include <boost/unordered_set.hpp>
#else
#include <set>
#endif
#include <unordered_set>
#endif // TORRENT_DEBUG && !TORRENT_DISABLE_INVARIANT_CHECKS
#include <boost/limits.hpp>
@ -4814,7 +4810,6 @@ namespace aux {
}
#endif
#if TORRENT_HAS_BOOST_UNORDERED
sha1_hash next_lsd(0);
sha1_hash next_dht(0);
if (m_next_lsd_torrent != m_torrents.end())
@ -4824,7 +4819,6 @@ namespace aux {
next_dht = m_next_dht_torrent->first;
#endif
float load_factor = m_torrents.load_factor();
#endif // TORRENT_HAS_BOOST_UNORDERED
m_torrents.insert(std::make_pair(*ih, torrent_ptr));
@ -4845,7 +4839,6 @@ namespace aux {
bump_torrent(torrent_ptr.get());
}
#if TORRENT_HAS_BOOST_UNORDERED
// if this insert made the hash grow, the iterators became invalid
// we need to reset them
if (m_torrents.load_factor() < load_factor)
@ -4858,7 +4851,6 @@ namespace aux {
m_next_dht_torrent = m_torrents.find(next_dht);
#endif
}
#endif // TORRENT_HAS_BOOST_UNORDERED
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2
@ -6809,11 +6801,7 @@ namespace aux {
}
}
#if TORRENT_HAS_BOOST_UNORDERED
boost::unordered_set<torrent*> unique_torrents;
#else
std::set<torrent*> unique_torrents;
#endif
std::unordered_set<torrent*> unique_torrents;
for (list_iterator<torrent> i = m_torrent_lru.iterate(); i.get(); i.next())
{
torrent* t = i.get();
@ -6828,11 +6816,7 @@ namespace aux {
#if defined TORRENT_EXPENSIVE_INVARIANT_CHECKS
#if TORRENT_HAS_BOOST_UNORDERED
boost::unordered_set<int> unique;
#else
std::set<int> unique;
#endif
std::unordered_set<int> unique;
#endif
int num_active_downloading = 0;
@ -6873,11 +6857,7 @@ namespace aux {
TORRENT_ASSERT(num_active_downloading == m_torrent_lists[torrent_want_peers_download].size());
TORRENT_ASSERT(num_active_finished == m_torrent_lists[torrent_want_peers_finished].size());
#if TORRENT_HAS_BOOST_UNORDERED
boost::unordered_set<peer_connection*> unique_peers;
#else
std::set<peer_connection*> unique_peers;
#endif
std::unordered_set<peer_connection*> unique_peers;
TORRENT_ASSERT(m_settings.get_int(settings_pack::connections_limit) > 0);
int unchokes = 0;

View File

@ -58,8 +58,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/bind.hpp>
#include <boost/assert.hpp>
#include <boost/unordered_set.hpp>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <set>
@ -520,7 +520,6 @@ namespace libtorrent
return true;
}
#if TORRENT_HAS_BOOST_UNORDERED
struct string_hash_no_case
{
size_t operator()(std::string const& s) const
@ -561,29 +560,6 @@ namespace libtorrent
}
};
#else
struct string_less_no_case
{
bool operator()(std::string const& lhs, std::string const& rhs) const
{
char c1, c2;
char const* s1 = lhs.c_str();
char const* s2 = rhs.c_str();
while (*s1 != 0 || *s2 != 0)
{
c1 = to_lower(*s1);
c2 = to_lower(*s2);
if (c1 < c2) return true;
if (c1 > c2) return false;
++s1;
++s2;
}
return false;
}
};
#endif
// root_dir is the name of the torrent, unless this is a single file
// torrent, in which case it's empty.
bool extract_files(bdecode_node const& list, file_storage& target
@ -697,7 +673,7 @@ namespace libtorrent
{
INVARIANT_CHECK;
boost::unordered_set<boost::uint32_t> files;
std::unordered_set<boost::uint32_t> files;
std::string empty_str;
@ -725,11 +701,7 @@ namespace libtorrent
INVARIANT_CHECK;
int cnt = 0;
#if TORRENT_HAS_BOOST_UNORDERED
boost::unordered_set<std::string, string_hash_no_case, string_eq_no_case> files;
#else
std::set<std::string, string_less_no_case> files;
#endif
std::unordered_set<std::string, string_hash_no_case, string_eq_no_case> files;
std::vector<std::string> const& paths = m_files.paths();
files.reserve(paths.size() + m_files.num_files());