Loading...
Searching...
No Matches
nodeSet.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_NODE_SET_H
8#define PXR_EXEC_VDF_NODE_SET_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
15#include "pxr/exec/vdf/node.h"
16
17#include "pxr/base/tf/bits.h"
18
19PXR_NAMESPACE_OPEN_SCOPE
20
26public:
27
30 VdfNodeSet() = default;
31
34 bool IsEmpty() const {
35 return _bits.GetSize() == 0 || _bits.GetNumSet() == 0;
36 }
37
40 size_t GetSize() const {
41 return _bits.GetNumSet();
42 }
43
48 VDF_API
49 void Clear();
50
53 bool Contains(const VdfNode &node) const {
55 }
56
59 bool Contains(const VdfIndex index) const {
60 return index < _bits.GetSize() ? _bits.IsSet(index) : false;
61 }
62
65 inline void Insert(const VdfNode &node);
66
69 VDF_API
70 void Insert(const VdfNodeSet &rhs);
71
76 VDF_API
77 bool Remove(const VdfNode &node);
78
83
86 const_iterator begin() const {
87 return _bits.GetAllSetView().begin();
88 }
89
92 const_iterator end() const {
93 return _bits.GetAllSetView().end();
94 }
95
98 friend void swap(VdfNodeSet &lhs, VdfNodeSet &rhs) {
99 lhs._bits.Swap(rhs._bits);
100 }
101
102private:
103
104 // Grow the underlying storage to accomodate at least the number of
105 // specified indices.
106 VDF_API
107 void _Grow(size_t size);
108
109 // The bit set representing nodes included in the set. The size of this
110 // bit set denotes the capacity.
111 TfBits _bits;
112
113};
114
115void
117{
118 // Make sure to grow the bitset to accomodate the corresponding index of
119 // the specified node.
120 const VdfIndex index = VdfNode::GetIndexFromId(node.GetId());
121 if (index >= _bits.GetSize()) {
122 _Grow(index + 1);
123 }
124
125 // Set the index.
126 _bits.Set(index);
127}
128
129PXR_NAMESPACE_CLOSE_SCOPE
130
131#endif
Iterator support.
Definition: bits.h:796
Fast bit array that keeps track of the number of bits set and can find the next set in a timely manne...
Definition: bits.h:49
size_t GetSize() const
Returns the size of the bit array, ie.
Definition: bits.h:475
void Swap(TfBits &rhs)
Provides a fast swap.
Definition: bits.h:261
void Set(size_t index)
Sets bit # index to one.
Definition: bits.h:377
bool IsSet(size_t index) const
Returns true, if bit # index is set.
Definition: bits.h:412
AllSetView GetAllSetView() const
Returns an iteratable view for the bits that steps over all set bits.
Definition: bits.h:914
size_t GetNumSet() const
Returns the number of bits currently set in this array.
Definition: bits.h:520
This is the base class for all nodes in a VdfNetwork.
Definition: node.h:53
static VdfIndex GetIndexFromId(const VdfId id)
Get the node index from the node id.
Definition: node.h:123
VdfId GetId() const
Returns the unique id of this node in its network.
Definition: node.h:116
Class that efficiently stores a set of VdfNodes.
Definition: nodeSet.h:25
bool Contains(const VdfIndex index) const
Returns true if the node with the given index is in the set.
Definition: nodeSet.h:59
size_t GetSize() const
Get the number of elements contained in this set.
Definition: nodeSet.h:40
VdfNodeSet()=default
Default constructor.
const_iterator begin() const
Returns an iterator at the beginning of the iterable range.
Definition: nodeSet.h:86
VDF_API bool Remove(const VdfNode &node)
Removes node from the set.
TfBits::View< TfBits::AllSet >::const_iterator iterator
Iterator types.
Definition: nodeSet.h:81
bool IsEmpty() const
Is this set empty?
Definition: nodeSet.h:34
VDF_API void Insert(const VdfNodeSet &rhs)
Inserts another nodeSet into this set.
const_iterator end() const
Returns an iterator at the end of the iterable range.
Definition: nodeSet.h:92
VDF_API void Clear()
Clears the node set.
friend void swap(VdfNodeSet &lhs, VdfNodeSet &rhs)
Swaps two VdfNodeSet instances.
Definition: nodeSet.h:98
void Insert(const VdfNode &node)
Inserts node into the set.
Definition: nodeSet.h:116
bool Contains(const VdfNode &node) const
Returns true if node is in the set.
Definition: nodeSet.h:53
uint32_t VdfIndex
The index type for Vdf objects.
Definition: types.h:110