7#ifndef PXR_BASE_TF_STL_H
8#define PXR_BASE_TF_STL_H
15#include "pxr/base/tf/api.h"
17#include "pxr/base/tf/hashmap.h"
18#include "pxr/base/tf/hashset.h"
27PXR_NAMESPACE_OPEN_SCOPE
31struct Tf_MapLookupHelper {
34 template <
class Key,
class Result>
35 static bool Lookup(Container
const& map, Key
const &key, Result* valuePtr)
37 typename Container::const_iterator i = map.find(key);
42 *valuePtr = i->second;
68template <
class Container,
class Key,
class Result>
69bool TfMapLookup(Container
const &map, Key
const &key, Result* valuePtr)
71 return Tf_MapLookupHelper<Container>::Lookup(map, key, valuePtr);
94template <
class Container,
class Key,
class Result>
96 Key
const &key,
const Result &defaultValue)
98 typename Container::const_iterator i = map.find(key);
122template <
class Container,
class Key>
123typename Container::mapped_type *
126 typename Container::iterator i = map.find(key);
127 return (i != map.end()) ? &(i->second) : NULL;
130template <
class Container,
class Key>
131typename Container::mapped_type
const *
134 typename Container::const_iterator i = map.find(key);
135 return (i != map.end()) ? &(i->second) : NULL;
149 return (a < b) ? std::pair<T,T>(a,b) : std::pair<T,T>(b,a);
174TF_API
size_t Tf_GetEmptyHashMapBucketCount();
177template <
class Key,
class Value,
class Hash,
class Equal,
class Alloc>
178inline void TfReset(TfHashMap<Key, Value, Hash, Equal, Alloc> &hash){
185 static size_t emptyCount = Tf_GetEmptyHashMapBucketCount();
187 if (hash.bucket_count() > emptyCount)
188 TfHashMap<Key, Value, Hash, Equal, Alloc>(0).swap(hash);
189 else if (!hash.empty())
193TF_API
size_t Tf_GetEmptyHashSetBucketCount();
196template <
class Value,
class Hash,
class Equal,
class Alloc>
197inline void TfReset(TfHashSet<Value, Hash, Equal, Alloc> &hash) {
198 static size_t emptyCount = Tf_GetEmptyHashSetBucketCount();
201 if (hash.bucket_count() > emptyCount)
202 TfHashSet<Value, Hash, Equal, Alloc>(0).swap(hash);
203 else if (!hash.empty())
218template <
class InputIterator1,
class InputIterator2,
class OutputIterator>
221 InputIterator2 first2, InputIterator2 last2,
222 OutputIterator result)
224 typedef std::multiset<typename InputIterator2::value_type> SetType;
225 SetType set2(first2, last2);
229 for (InputIterator1 i = first1; i != last1; ++i) {
230 typename SetType::iterator j = set2.find(*i);
249template <
class BackInsertionSequence,
250 class InputIterator1,
class InputIterator2>
253 InputIterator2 first2, InputIterator2 last2)
255 BackInsertionSequence result;
257 std::back_inserter(result));
272template <
class InputIterator1,
class InputIterator2,
class OutputIterator>
275 InputIterator2 first2, InputIterator2 last2,
276 OutputIterator result)
278 typedef std::set<typename InputIterator1::value_type> Set1Type;
279 typedef std::set<typename InputIterator2::value_type> Set2Type;
282 Set2Type set2(first2, last2);
286 for (InputIterator1 i = first1; i != last1; ++i)
287 if (set1.insert(*i).second && !set2.count(*i))
302template <
class BackInsertionSequence,
303 class InputIterator1,
class InputIterator2>
306 InputIterator1 last1,
307 InputIterator2 first2,
308 InputIterator2 last2)
310 BackInsertionSequence result;
312 std::back_inserter(result));
324template <
class ForwardIterator,
class Predicate>
325static inline ForwardIterator
326TfFindBoundary(ForwardIterator first, ForwardIterator last,
327 Predicate
const &pred)
329 size_t len = std::distance(first, last);
331 ForwardIterator middle;
336 std::advance(middle, half);
340 len = len - half - 1;
364 template <
class PairOrTuple>
365 using return_type =
typename std::tuple_element<N, PairOrTuple>::type;
367 template <
class PairOrTuple>
368 constexpr return_type<PairOrTuple>& operator()(PairOrTuple& p)
const
370 return std::get<N>(p);
373 template <
class PairOrTuple>
374 constexpr const return_type<PairOrTuple>& operator()(
375 const PairOrTuple& p)
const
377 return std::get<N>(p);
380 template <
class PairOrTuple>
381 constexpr return_type<PairOrTuple>&& operator()(PairOrTuple&& p)
const
383 return std::get<N>(std::move(p));
387PXR_NAMESPACE_CLOSE_SCOPE
A simple iterator adapter for STL containers.
Function object for retrieving the N'th element of a std::pair or std::tuple.
std::pair< T, T > TfOrderedPair(T a, T b)
Return an std::pair in sorted order.
Container::mapped_type * TfMapLookupPtr(Container &map, Key const &key)
Checks if an item exists in a map or TfHashMap, without copying it.
bool TfMapLookup(Container const &map, Key const &key, Result *valuePtr)
Checks if an item exists in a map or a TfHashMap.
const Result TfMapLookupByValue(Container const &map, Key const &key, const Result &defaultValue)
Checks if an item exists in a map or a TfHashMap.
void TfOrderedSetDifference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
Produce a sequence consisting of the set difference of [first1, last1) and [first2,...
BackInsertionSequence TfOrderedUniquingSetDifferenceToContainer(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
Produce a sequence consisting of the set difference of the unique elements in [first1,...
void TfReset(T &obj)
Reset obj to be an empty, space-optimized object.
BackInsertionSequence TfOrderedSetDifferenceToContainer(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
Produce a sequence consisting of the set difference of [first1, last1) and [first2,...
void TfOrderedUniquingSetDifference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
Produce a sequence consisting of the set difference of the unique elements in [first1,...
A file containing basic constants and definitions.