24#ifndef PXR_BASE_TF_STL_H
25#define PXR_BASE_TF_STL_H
32#include "pxr/base/tf/api.h"
34#include "pxr/base/tf/hashmap.h"
35#include "pxr/base/tf/hashset.h"
44PXR_NAMESPACE_OPEN_SCOPE
48struct Tf_MapLookupHelper {
51 template <
class Key,
class Result>
52 static bool Lookup(Container
const& map, Key
const &key, Result* valuePtr)
54 typename Container::const_iterator i = map.find(key);
59 *valuePtr = i->second;
85template <
class Container,
class Key,
class Result>
86bool TfMapLookup(Container
const &map, Key
const &key, Result* valuePtr)
88 return Tf_MapLookupHelper<Container>::Lookup(map, key, valuePtr);
111template <
class Container,
class Key,
class Result>
113 Key
const &key,
const Result &defaultValue)
115 typename Container::const_iterator i = map.find(key);
116 if (i == map.end()) {
139template <
class Container,
class Key>
140typename Container::mapped_type *
143 typename Container::iterator i = map.find(key);
144 return (i != map.end()) ? &(i->second) : NULL;
147template <
class Container,
class Key>
148typename Container::mapped_type
const *
151 typename Container::const_iterator i = map.find(key);
152 return (i != map.end()) ? &(i->second) : NULL;
166 return (a < b) ? std::pair<T,T>(a,b) : std::pair<T,T>(b,a);
191TF_API
size_t Tf_GetEmptyHashMapBucketCount();
194template <
class Key,
class Value,
class Hash,
class Equal,
class Alloc>
195inline void TfReset(TfHashMap<Key, Value, Hash, Equal, Alloc> &hash){
202 static size_t emptyCount = Tf_GetEmptyHashMapBucketCount();
204 if (hash.bucket_count() > emptyCount)
205 TfHashMap<Key, Value, Hash, Equal, Alloc>(0).swap(hash);
206 else if (!hash.empty())
210TF_API
size_t Tf_GetEmptyHashSetBucketCount();
213template <
class Value,
class Hash,
class Equal,
class Alloc>
214inline void TfReset(TfHashSet<Value, Hash, Equal, Alloc> &hash) {
215 static size_t emptyCount = Tf_GetEmptyHashSetBucketCount();
218 if (hash.bucket_count() > emptyCount)
219 TfHashSet<Value, Hash, Equal, Alloc>(0).swap(hash);
220 else if (!hash.empty())
235template <
class InputIterator1,
class InputIterator2,
class OutputIterator>
238 InputIterator2 first2, InputIterator2 last2,
239 OutputIterator result)
241 typedef std::multiset<typename InputIterator2::value_type> SetType;
242 SetType set2(first2, last2);
246 for (InputIterator1 i = first1; i != last1; ++i) {
247 typename SetType::iterator j = set2.find(*i);
266template <
class BackInsertionSequence,
267 class InputIterator1,
class InputIterator2>
270 InputIterator2 first2, InputIterator2 last2)
272 BackInsertionSequence result;
274 std::back_inserter(result));
289template <
class InputIterator1,
class InputIterator2,
class OutputIterator>
292 InputIterator2 first2, InputIterator2 last2,
293 OutputIterator result)
295 typedef std::set<typename InputIterator1::value_type> Set1Type;
296 typedef std::set<typename InputIterator2::value_type> Set2Type;
299 Set2Type set2(first2, last2);
303 for (InputIterator1 i = first1; i != last1; ++i)
304 if (set1.insert(*i).second && !set2.count(*i))
319template <
class BackInsertionSequence,
320 class InputIterator1,
class InputIterator2>
323 InputIterator1 last1,
324 InputIterator2 first2,
325 InputIterator2 last2)
327 BackInsertionSequence result;
329 std::back_inserter(result));
341template <
class ForwardIterator,
class Predicate>
342static inline ForwardIterator
343TfFindBoundary(ForwardIterator first, ForwardIterator last,
344 Predicate
const &pred)
346 size_t len = std::distance(first, last);
348 ForwardIterator middle;
353 std::advance(middle, half);
357 len = len - half - 1;
381 template <
class PairOrTuple>
382 using return_type =
typename std::tuple_element<N, PairOrTuple>::type;
384 template <
class PairOrTuple>
385 constexpr return_type<PairOrTuple>& operator()(PairOrTuple& p)
const
387 return std::get<N>(p);
390 template <
class PairOrTuple>
391 constexpr const return_type<PairOrTuple>& operator()(
392 const PairOrTuple& p)
const
394 return std::get<N>(p);
397 template <
class PairOrTuple>
398 constexpr return_type<PairOrTuple>&& operator()(PairOrTuple&& p)
const
400 return std::get<N>(std::move(p));
404PXR_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.