HDK
|
#include "pxr/pxr.h"
#include "pxr/base/tf/api.h"
#include "pxr/base/tf/tf.h"
#include "pxr/base/tf/hashmap.h"
#include "pxr/base/tf/hashset.h"
#include "pxr/base/tf/iterator.h"
#include <algorithm>
#include <iterator>
#include <map>
#include <set>
#include <utility>
Go to the source code of this file.
Classes | |
struct | Tf_MapLookupHelper< T > |
class | TfGet< N > |
Functions | |
template<class Container , class Key , class Result > | |
bool | TfMapLookup (Container const &map, Key const &key, Result *valuePtr) |
template<class Container , class Key , class Result > | |
const Result | TfMapLookupByValue (Container const &map, Key const &key, const Result &defaultValue) |
template<class Container , class Key > | |
Container::mapped_type * | TfMapLookupPtr (Container &map, Key const &key) |
template<class Container , class Key > | |
Container::mapped_type const * | TfMapLookupPtr (Container const &map, Key const &key) |
template<typename T > | |
std::pair< T, T > | TfOrderedPair (T a, T b) |
template<class T > | |
void | TfReset (T &obj) |
TF_API size_t | Tf_GetEmptyHashMapBucketCount () |
template<class Key , class Value , class Hash , class Equal , class Alloc > | |
void | TfReset (TfHashMap< Key, Value, Hash, Equal, Alloc > &hash) |
Specialize for TfHashMap to make minimally sized hashes. More... | |
TF_API size_t | Tf_GetEmptyHashSetBucketCount () |
template<class Value , class Hash , class Equal , class Alloc > | |
void | TfReset (TfHashSet< Value, Hash, Equal, Alloc > &hash) |
Specialize for TfHashSet to make minimally sized hashes. More... | |
template<class InputIterator1 , class InputIterator2 , class OutputIterator > | |
void | TfOrderedSetDifference (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result) |
template<class BackInsertionSequence , class InputIterator1 , class InputIterator2 > | |
BackInsertionSequence | TfOrderedSetDifferenceToContainer (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2) |
template<class InputIterator1 , class InputIterator2 , class OutputIterator > | |
void | TfOrderedUniquingSetDifference (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result) |
template<class BackInsertionSequence , class InputIterator1 , class InputIterator2 > | |
BackInsertionSequence | TfOrderedUniquingSetDifferenceToContainer (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2) |
TF_API size_t Tf_GetEmptyHashMapBucketCount | ( | ) |
TF_API size_t Tf_GetEmptyHashSetBucketCount | ( | ) |
bool TfMapLookup | ( | Container const & | map, |
Key const & | key, | ||
Result * | valuePtr | ||
) |
Checks if an item exists in a map
or a TfHashMap
.
If key
exists in map
, then this function returns true
and the value indexed by key
is copied into *valuePtr
. Otherwise, *valuePtr
is not modified, and false
is returned.
Example:
const Result TfMapLookupByValue | ( | Container const & | map, |
Key const & | key, | ||
const Result & | defaultValue | ||
) |
Checks if an item exists in a map
or a TfHashMap
.
If key
exists in map
, then this function returns the value index by key
. Otherwise, defaultValue
is returned. Note that the result is returned by value, so this is best used for types that are quick to copy.
Example:
Container::mapped_type* TfMapLookupPtr | ( | Container & | map, |
Key const & | key | ||
) |
Checks if an item exists in a map
or TfHashMap
, without copying it.
If key
exists in the map
, then this function returns a pointer to the value indexed by key
. Otherwise, NULL is returned.
Example:
Container::mapped_type const* TfMapLookupPtr | ( | Container const & | map, |
Key const & | key | ||
) |
|
inline |
Return an std::pair
in sorted order.
This call is a useful helper for maps whose key is an unordered pair of elements. One can either define a new data type such that (a,b) is deemed equivalent to (b,a), or more simply, adopt the convention that a key is always written (a,b) with a < b.
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, last2), while maintaining the relative order of the first sequence. No particular order is required for either range, but elements must have a strict weak order provided by operator<.
If an element appears multiple times in either the first or second sequence, the number of occurrences in the output is the difference between the first sequence and the second (or zero if there are more occurrences in the second sequence). For example, if the first sequence is (1, 3, 3, 1) and the second sequence is (2, 3, 2), the result will be (1, 3, 1).
BackInsertionSequence TfOrderedSetDifferenceToContainer | ( | InputIterator1 | first1, |
InputIterator1 | last1, | ||
InputIterator2 | first2, | ||
InputIterator2 | last2 | ||
) |
Produce a sequence consisting of the set difference of [first1, last1) and [first2, last2), while maintaining the relative order of the first sequence. No particular order is required for either range, but elements must have a strict weak order provided by operator<.
If an element appears multiple times in either the first or second sequence, the number of occurrences in the output is the difference between the first sequence and the second (or zero if there are more occurrences in the second sequence). For example, if the first sequence is (1, 3, 3, 1) and the second sequence is (2, 3, 2), the result will be (1, 3, 1).
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, last1) and [first2, last2), while maintaining the relative order of the first sequence. No particular order is required for either range, but elements must have a strict weak order provided by operator<.
If an element appears multiple times in the first sequence, it appears either zero or one times in the output. It appears zero times if it appears in the second sequence, and one time if it does not. For example, if the first sequence is (1, 3, 3, 1) and the second sequence is (2, 3, 2), the result will be (1).
BackInsertionSequence TfOrderedUniquingSetDifferenceToContainer | ( | InputIterator1 | first1, |
InputIterator1 | last1, | ||
InputIterator2 | first2, | ||
InputIterator2 | last2 | ||
) |
Produce a sequence consisting of the set difference of the unique elements in [first1, last1) and [first2, last2), while maintaining the relative order of the first sequence. No particular order is required for either range, but elements must have a strict weak order provided by operator<.
If an element appears multiple times in the first sequence, it appears either zero or one times in the output. It appears zero times if it appears in the second sequence, and one time if it does not. For example, if the first sequence is (1, 3, 3, 1) and the second sequence is (2, 3, 2), the result will be (1).
|
inline |
Reset obj to be an empty, space-optimized object.
This can be used to clear c++ containers and reclaim their memory. For instance, std::vector::clear() will not reclaim any memory, even if the vector previously had a large number of elements. Often, this is what you want because the vector is later filled again. But sometimes you want to reclaim the memory, and this function will do that.
As another example, gcc's hash_map and hash_set do not clear their bucket lists when they themselves are cleared. This can lead to poor performance due to ever-growing bucket lists for hashes that are repeatedly filled, cleared, and filled again. TfReset will avoid this by effectively clearing the bucket list.
This function requires that the expression T().swap(obj) where obj is of type T& be valid. This is true for many classes, including the standard containers.