Loading...
Searching...
No Matches
maskMemoizer.h
Go to the documentation of this file.
1//
2// Copyright 2025 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_EXEC_VDF_MASK_MEMOIZER_H
8#define PXR_EXEC_VDF_MASK_MEMOIZER_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/mask.h"
15
16#include "pxr/base/tf/hash.h"
17
18#include <utility>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
32template <template <typename...> class MapType>
34{
35public:
38 const VdfMask &Append(const VdfMask &lhs, const VdfMask &rhs) {
39 _Key key{lhs, rhs};
40
41 typename _Cache::iterator it = _appended.find(key);
42 if (it != _appended.end()) {
43 return it->second;
44 }
45
46 return _appended.insert({std::move(key), lhs | rhs}).first->second;
47 }
48
49private:
50
51 // Operations are keyed off of the lhs and rhs operands.
52 using _Key = std::pair<VdfMask, VdfMask>;
53
54 // Produce a combination of lhs and rhs hash values as the hash for the
55 // key.
56 struct _Hash {
57 size_t operator()(const _Key &v) const {
58 return TfHash::Combine(v.first.GetHash(), v.second.GetHash());
59 }
60 };
61
62 // The cache for append operations.
63 using _Cache = MapType<_Key, VdfMask, _Hash>;
64 _Cache _appended;
65};
66
67PXR_NAMESPACE_CLOSE_SCOPE
68
69#endif
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:37
Memoizes the results of mask append (union) operations.
Definition: maskMemoizer.h:34
const VdfMask & Append(const VdfMask &lhs, const VdfMask &rhs)
Append lhs and rhs and return the result.
Definition: maskMemoizer.h:38