Skip to content

Commit

Permalink
Tf: Remove boost fallback for hash_{map,set} now that we
Browse files Browse the repository at this point in the history
assume c++11.

This change caused some Python-related build issues in some
other files on MacOS, which were fixed up as well.

Fixes #127

(Internal change: 1765732)
(Internal change: 1765736)
(Internal change: 1765783)
(Internal change: 1765909)
  • Loading branch information
blevin authored and pixar-oss committed Jul 13, 2017
1 parent 5881035 commit c288d89
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 402 deletions.
204 changes: 5 additions & 199 deletions pxr/base/lib/tf/hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,18 @@
//
// Wrapping provides a convenient way to switch between implementations.
// The GNU extension (currently) has the best overall performance but
// isn't standard. The boost implementation is widely available but
// slow. The standard implementation isn't available prior to C++11.
// isn't standard. Otherwise we use the C++11 standard implementation.

#ifndef TF_HASHMAP_H
#define TF_HASHMAP_H

#include "pxr/pxr.h"

#if !defined(TF_NO_GNU_EXT)
// Use GNU extension.
#if !defined(TF_NO_GNU_EXT) // Use GNU extension.
#include <ext/hash_map>
#elif __cplusplus > 201103L
// Use C++11 unordered_map.
#else // Use C++11 unordered_map.
#include <unordered_map>
#else
// Use boost unordered_map.
#include <boost/unordered_map.hpp>
#endif // TF_NO_GNU_EXT
#endif // TF_NO_GNU_EXT

PXR_NAMESPACE_OPEN_SCOPE

Expand Down Expand Up @@ -264,7 +258,7 @@ class TfHashMultiMap :
}
};

#elif __cplusplus > 201103L // C++11
#else

template<class Key, class Mapped, class HashFn = std::hash<Key>,
class EqualKey = std::equal_to<Key>,
Expand Down Expand Up @@ -452,194 +446,6 @@ class TfHashMultiMap :
const TfHashMap<Key2, Mapped2, HashFn2, EqualKey2, Alloc2>&);
};

#else

template<class Key, class Mapped, class HashFn = boost::hash<Key>,
class EqualKey = std::equal_to<Key>,
class Alloc = std::allocator<std::pair<const Key, Mapped> > >
class TfHashMap :
private boost::unordered_map<Key, Mapped, HashFn, EqualKey, Alloc> {
typedef boost::unordered_map<Key, Mapped, HashFn, EqualKey, Alloc> _Base;
public:
typedef typename _Base::key_type key_type;
typedef typename _Base::mapped_type mapped_type;
typedef typename _Base::value_type value_type;
typedef typename _Base::hasher hasher;
typedef typename _Base::key_equal key_equal;
typedef typename _Base::size_type size_type;
typedef typename _Base::difference_type difference_type;
typedef typename _Base::pointer pointer;
typedef typename _Base::const_pointer const_pointer;
typedef typename _Base::reference reference;
typedef typename _Base::const_reference const_reference;
typedef typename _Base::iterator iterator;
typedef typename _Base::const_iterator const_iterator;
typedef typename _Base::allocator_type allocator_type;
// No local_iterator nor any methods using them.

TfHashMap() : _Base() { }
explicit
TfHashMap(size_type n, const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& alloc = allocator_type()) :
_Base(n, hf, eql, alloc) { }
explicit
TfHashMap(const allocator_type& alloc) : _Base(alloc) { }
template<class InputIterator>
TfHashMap(InputIterator first, InputIterator last,
size_type n = 0, const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& alloc = allocator_type()) :
_Base(first, last, n, hf, eql, alloc) { }
TfHashMap(const TfHashMap& other) : _Base(other) { }

TfHashMap& operator=(const TfHashMap& rhs) {
_Base::operator=(rhs);
return *this;
}

iterator begin() { return _Base::begin(); }
const_iterator begin() const { return _Base::begin(); }
// using _Base::bucket;
using _Base::bucket_count;
using _Base::bucket_size;
const_iterator cbegin() const { return _Base::cbegin(); }
const_iterator cend() const { return _Base::cend(); }
using _Base::clear;
using _Base::count;
using _Base::empty;
iterator end() { return _Base::end(); }
const_iterator end() const { return _Base::end(); }
using _Base::equal_range;
size_type erase(const key_type& key) { return _Base::erase(key); }
void erase(const_iterator position) { _Base::erase(position); }
void erase(const_iterator first, const_iterator last) {
_Base::erase(first, last);
}
using _Base::find;
using _Base::get_allocator;
using _Base::hash_function;
std::pair<iterator, bool> insert(const value_type& v) {
return _Base::insert(v);
}
iterator insert(const_iterator hint, const value_type& v) {
return _Base::insert(hint, v);
}
template<class InputIterator>
void insert(InputIterator first, InputIterator last) {
_Base::insert(first, last);
}
using _Base::key_eq;
using _Base::load_factor;
using _Base::max_bucket_count;
using _Base::max_load_factor;
// using _Base::max_load_factor;
using _Base::max_size;
using _Base::rehash;
using _Base::reserve;
using _Base::size;
void swap(TfHashMap& other) { _Base::swap(other); }
mapped_type& operator[](const key_type& k) { return _Base::operator[](k); }

template<class Key2, class Mapped2, class HashFn2, class EqualKey2, class Alloc2>
friend bool
operator==(const TfHashMap<Key2, Mapped2, HashFn2, EqualKey2, Alloc2>&,
const TfHashMap<Key2, Mapped2, HashFn2, EqualKey2, Alloc2>&);
};

template<class Key, class Mapped, class HashFn = boost::hash<Key>,
class EqualKey = std::equal_to<Key>,
class Alloc = std::allocator<std::pair<const Key, Mapped> > >
class TfHashMultiMap :
private boost::unordered_map<Key, Mapped, HashFn, EqualKey, Alloc> {
typedef boost::unordered_map<Key, Mapped, HashFn, EqualKey, Alloc> _Base;
public:
typedef typename _Base::key_type key_type;
typedef typename _Base::mapped_type mapped_type;
typedef typename _Base::value_type value_type;
typedef typename _Base::hasher hasher;
typedef typename _Base::key_equal key_equal;
typedef typename _Base::size_type size_type;
typedef typename _Base::difference_type difference_type;
typedef typename _Base::pointer pointer;
typedef typename _Base::const_pointer const_pointer;
typedef typename _Base::reference reference;
typedef typename _Base::const_reference const_reference;
typedef typename _Base::iterator iterator;
typedef typename _Base::const_iterator const_iterator;
typedef typename _Base::allocator_type allocator_type;
// No local_iterator nor any methods using them.

TfHashMultiMap() : _Base() { }
explicit
TfHashMultiMap(size_type n, const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& alloc = allocator_type()) :
_Base(n, hf, eql, alloc) { }
explicit
TfHashMultiMap(const allocator_type& alloc) : _Base(alloc) { }
template<class InputIterator>
TfHashMultiMap(InputIterator first, InputIterator last,
size_type n = 0, const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& alloc = allocator_type()) :
_Base(first, last, n, hf, eql, alloc) { }
TfHashMultiMap(const TfHashMultiMap& other) : _Base(other) { }

TfHashMultiMap& operator=(const TfHashMultiMap& rhs) {
_Base::operator=(rhs);
return *this;
}

iterator begin() { return _Base::begin(); }
const_iterator begin() const { return _Base::begin(); }
// using _Base::bucket;
using _Base::bucket_count;
using _Base::bucket_size;
const_iterator cbegin() const { return _Base::cbegin(); }
const_iterator cend() const { return _Base::cend(); }
using _Base::clear;
using _Base::count;
using _Base::empty;
iterator end() { return _Base::end(); }
const_iterator end() const { return _Base::end(); }
using _Base::equal_range;
size_type erase(const key_type& key) { return _Base::erase(key); }
void erase(const_iterator position) { _Base::erase(position); }
void erase(const_iterator first, const_iterator last) {
_Base::erase(first, last);
}
using _Base::find;
using _Base::get_allocator;
using _Base::hash_function;
iterator insert(const value_type& v) {
return _Base::insert(v);
}
iterator insert(const_iterator hint, const value_type& v) {
return _Base::insert(hint, v);
}
template<class InputIterator>
void insert(InputIterator first, InputIterator last) {
_Base::insert(first, last);
}
using _Base::key_eq;
using _Base::load_factor;
using _Base::max_bucket_count;
using _Base::max_load_factor;
// using _Base::max_load_factor;
using _Base::max_size;
using _Base::rehash;
using _Base::reserve;
using _Base::size;
void swap(TfHashMultiMap& other) { _Base::swap(other); }
mapped_type& operator[](const key_type& k) { return _Base::operator[](k); }

template<class Key2, class Mapped2, class HashFn2, class EqualKey2, class Alloc2>
friend bool
operator==(const TfHashMap<Key2, Mapped2, HashFn2, EqualKey2, Alloc2>&,
const TfHashMap<Key2, Mapped2, HashFn2, EqualKey2, Alloc2>&);
};

#endif

template<class Key, class Mapped, class HashFn, class EqualKey, class Alloc>
Expand Down
Loading

0 comments on commit c288d89

Please sign in to comment.