24 #ifndef PXR_BASE_TF_DENSE_HASH_SET_H
25 #define PXR_BASE_TF_DENSE_HASH_SET_H
52 class EqualElement = std::equal_to<Element>,
53 unsigned Threshold = 128
66 typedef std::vector<Element> _Vector;
78 typedef typename _Vector::const_iterator
iterator;
91 const HashFn &hashFn = HashFn(),
92 const EqualElement &equalElement = EqualElement())
95 _equ() = equalElement;
101 : _storage(rhs._storage) {
103 _h = std::make_unique<_HashMap>(*rhs._h);
113 template <
class Iterator>
121 insert(l.begin(), l.end());
142 insert(l.begin(), l.end());
157 if (!rhs.
count(*iter))
165 return !(*
this == rhs);
178 _storage.swap(rhs._storage);
185 return _vec().empty();
191 return _vec().size();
197 return _vec().begin();
212 if (iter == _h->end())
215 return _vec().begin() + iter->second;
218 typename _Vector::const_iterator iter,
end = _vec().end();
220 for(iter = _vec().
begin(); iter !=
end; ++iter)
221 if (_equ()(*iter, k))
243 std::pair<typename _HashMap::iterator, bool> res =
244 _h->insert(std::make_pair(v,
size()));
259 _CreateTableIfNeeded();
267 template<
class IteratorType>
277 for (IteratorType iter = i0; iter !=
i1; ++iter)
284 template <
class Iterator>
288 _vec().assign(begin, end);
289 _CreateTableIfNeeded();
317 if (iter != std::prev(
end())) {
323 swap(*const_cast<Element *>(&(*iter)), _vec().back());
327 (*_h)[*iter] = iter - _vec().begin();
339 _h->erase(iter->first);
345 for(; vremain != _vec().end(); ++vremain)
346 (*_h)[*vremain] = vremain - _vec().begin();
355 _vec().shrink_to_fit();
363 if (sz < Threshold) {
370 _h.reset(
new _HashMap(sz, _hash(), _equ()));
371 for(
size_t i=0; i<sz; ++i)
372 (*_h)[_vec()[i]] = i;
379 TF_VERIFY(index <
size());
380 return _vec()[
index];
389 return _storage.vector;
398 EqualElement &_equ() {
403 const _Vector &_vec()
const {
404 return _storage.vector;
408 const HashFn &_hash()
const {
413 const EqualElement &_equ()
const {
418 inline void _CreateTableIfNeeded() {
419 if (
size() >= Threshold) {
426 inline void _CreateTable() {
428 _h.reset(
new _HashMap(Threshold, _hash(), _equ()));
429 for(
size_t i=0; i <
size(); ++i)
430 (*_h)[_vec()[i]] = i;
438 struct ARCH_EMPTY_BASES _CompressedStorage :
439 private EqualElement,
private HashFn {
441 "EqualElement and HashFn must be distinct types.");
442 _CompressedStorage() =
default;
443 _CompressedStorage(
const EqualElement&
equal,
const HashFn& hashFn)
444 : EqualElement(equal), HashFn(hashFn) {}
446 void swap(_CompressedStorage& other) {
448 vector.swap(other.vector);
449 swap(static_cast<EqualElement&>(*
this),
450 static_cast<EqualElement&>(other));
451 swap(static_cast<HashFn&>(*
this), static_cast<HashFn&>(other));
456 _CompressedStorage _storage;
459 std::unique_ptr<_HashMap> _h;
464 #endif // PXR_BASE_TF_DENSE_HASH_SET_H
_Base::const_iterator const_iterator
void erase(const iterator &i0, const iterator &i1)
bool operator==(const TfDenseHashSet &rhs) const
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
const_iterator end() const
GLsizei const GLfloat * value
void erase(const iterator &iter)
std::pair< const_iterator, bool > insert_result
Return type for insert() method.
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
TfDenseHashSet(const TfDenseHashSet &rhs)
const_iterator find(const Element &k) const
size_t count(const Element &k) const
void insert(IteratorType i0, IteratorType i1)
const Element & operator[](size_t index) const
TfDenseHashSet & operator=(const TfDenseHashSet &rhs)
TfDenseHashSet(const HashFn &hashFn=HashFn(), const EqualElement &equalElement=EqualElement())
TfDenseHashSet & operator=(std::initializer_list< Element > l)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
TfDenseHashSet(Iterator begin, Iterator end)
TfDenseHashSet(std::initializer_list< Element > l)
_Vector::const_iterator iterator
#define PXR_NAMESPACE_CLOSE_SCOPE
void swap(TfDenseHashSet &rhs)
size_t erase(const Element &k)
bool operator!=(const TfDenseHashSet &rhs) const
void insert_unique(Iterator begin, Iterator end)
insert_result insert(const value_type &v)
SIM_API const UT_StringHolder distance
const_iterator begin() const
_Vector::const_iterator const_iterator
A const_iterator type for this set.