24 #ifndef PXR_USD_SDF_PATH_TABLE_H
25 #define PXR_USD_SDF_PATH_TABLE_H
81 template <
class MappedType>
97 _Entry(
const _Entry&) =
delete;
98 _Entry&
operator=(
const _Entry&) =
delete;
102 , firstChild(
nullptr)
103 , nextSiblingOrParent(
nullptr,
false) {}
106 :
value(std::move(value))
108 , firstChild(
nullptr)
109 , nextSiblingOrParent(
nullptr,
false) {}
113 _Entry *GetNextSibling() {
114 return nextSiblingOrParent.template BitsAs<bool>() ?
115 nextSiblingOrParent.Get() : 0;
119 _Entry
const *GetNextSibling()
const {
120 return nextSiblingOrParent.template BitsAs<bool>() ?
121 nextSiblingOrParent.Get() : 0;
126 _Entry *GetParentLink() {
127 return nextSiblingOrParent.template BitsAs<bool>() ? 0 :
128 nextSiblingOrParent.Get();
132 _Entry
const *GetParentLink()
const {
133 return nextSiblingOrParent.template BitsAs<bool>() ? 0 :
134 nextSiblingOrParent.Get();
139 void SetSibling(_Entry *sibling) {
140 nextSiblingOrParent.Set(sibling,
true);
145 void SetParentLink(_Entry *parent) {
146 nextSiblingOrParent.Set(parent,
false);
150 void AddChild(_Entry *child) {
154 child->SetSibling(firstChild);
156 child->SetParentLink(
this);
160 void RemoveChild(_Entry *child) {
162 if (child == firstChild) {
163 firstChild = child->GetNextSibling();
167 _Entry *prev, *cur = firstChild;
170 cur = prev->GetNextSibling();
171 }
while (cur != child);
172 prev->nextSiblingOrParent = cur->nextSiblingOrParent;
195 typedef std::vector<_Entry *> _BucketVec;
202 template <
class ValType,
class EntryPtr>
217 template <
class OtherVal,
class OtherEntryPtr>
236 template <
class OtherVal,
class OtherEntryPtr>
241 template <
class OtherVal,
class OtherEntryPtr>
243 return !
equal(other);
252 if (EntryPtr sibling =
_entry->GetNextSibling()) {
258 for (EntryPtr p =
_entry->GetParentLink(); p;
259 p = p->GetParentLink()) {
260 if (EntryPtr sibling = p->GetNextSibling()) {
273 return bool(
_entry->firstChild);
294 template <
class OtherVal,
class OtherEntryPtr>
329 ret._unlinkedEntry.reset(
new _Entry(value,
nullptr));
337 ret._unlinkedEntry.reset(
new _Entry(std::move(
value),
nullptr));
344 return New({ key, mapped });
351 return _unlinkedEntry->value.first;
358 return _unlinkedEntry->value.first;
365 return _unlinkedEntry->value.second;
372 return _unlinkedEntry->value.second;
378 return static_cast<bool>(_unlinkedEntry);
383 explicit operator bool()
const {
390 _unlinkedEntry.reset();
394 std::unique_ptr<_Entry> _unlinkedEntry;
402 : _buckets(other._buckets.
size())
412 if (i._entry->firstChild && !j._entry->firstChild) {
413 j._entry->firstChild =
414 _InsertInTable(i._entry->firstChild->value).first._entry;
417 if (i._entry->nextSiblingOrParent.Get() &&
418 !j._entry->nextSiblingOrParent.Get()) {
419 j._entry->nextSiblingOrParent.Set(
420 _InsertInTable(i._entry->nextSiblingOrParent.
422 i._entry->nextSiblingOrParent.template BitsAs<bool>());
429 : _buckets(std::move(other._buckets))
506 _Entry *
const entry = i._entry;
507 _EraseSubtree(entry);
508 _RemoveFromParent(entry);
509 _EraseFromTable(entry);
517 for (_Entry *e = _buckets[_Hash(path)]; e; e = e->next) {
518 if (e->value.first == path)
530 for (_Entry
const *e = _buckets[_Hash(path)]; e; e = e->next) {
531 if (e->value.first == path)
541 std::pair<iterator, iterator>
543 std::pair<iterator, iterator>
result;
544 result.first =
find(path);
545 result.second = result.first.GetNextSubtree();
552 std::pair<const_iterator, const_iterator>
554 std::pair<const_iterator, const_iterator>
result;
555 result.first =
find(path);
556 result.second = result.first.GetNextSubtree();
566 inline size_t size()
const {
return _size; }
587 _UpdateTreeForNewEntry(result);
603 _UpdateTreeForNewEntry(result);
622 for (
size_t i = 0,
n = _buckets.size(); i !=
n; ++i) {
623 _Entry *entry = _buckets[i];
625 _Entry *next = entry->next;
638 [](
void*& voidEntry) {
639 _Entry *entry =
static_cast<_Entry *
>(voidEntry);
641 _Entry *next = entry->next;
648 _buckets.size(), visitFn);
654 _buckets.swap(other._buckets);
661 std::vector<size_t>
sizes(_buckets.size(), 0u);;
662 for (
size_t i = 0,
n = _buckets.size(); i !=
n; ++i) {
663 for (_Entry *entry = _buckets[i]; entry; entry = entry->next) {
681 for (
iterator i=range.first; i!=range.second; ++i) {
683 i->first.ReplacePrefix(oldName, newName),
687 if (range.first != range.second)
696 template <
typename Callback>
699 [&visitFn](
void*& voidEntry) {
700 _Entry *entry =
static_cast<_Entry *
>(voidEntry);
702 visitFn(std::cref(entry->value.first),
708 _buckets.size(), lambda);
713 template <
typename Callback>
716 [&visitFn](
void*& voidEntry) {
717 const _Entry *entry =
static_cast<const _Entry *
>(voidEntry);
719 visitFn(std::cref(entry->value.first),
720 std::cref(entry->value.second));
726 reinterpret_cast<void **>(const_cast<_Entry**>(_buckets.data())),
727 _buckets.size(), lambda);
741 _Entry *
const newEntry = iresult.first._entry;
742 SdfPath const &parentPath = _GetParentPath(newEntry->value.first);
747 parIter._entry->AddChild(newEntry);
753 template <
class MakeEntryFn>
755 MakeEntryFn &&makeEntry) {
761 _Entry **bucketHead = &(_buckets[_Hash(key)]);
762 for (_Entry *e = *bucketHead; e; e = e->next) {
763 if (e->value.first == key) {
772 bucketHead = &(_buckets[_Hash(key)]);
776 *bucketHead = std::forward<MakeEntryFn>(makeEntry)(*bucketHead);
786 return _InsertInTableImpl(
787 value.first, [&value](_Entry *next) {
788 return new _Entry(value, next);
793 return _InsertInTableImpl(
794 node.GetKey(), [&node](_Entry *next)
mutable {
795 node._unlinkedEntry->next = next;
796 return node._unlinkedEntry.release();
801 void _EraseFromTable(_Entry *entry) {
803 _Entry **cur = &_buckets[_Hash(entry->value.first)];
804 while (*cur != entry)
805 cur = &((*cur)->next);
815 void _EraseSubtree(_Entry *entry) {
817 if (_Entry *
const firstChild = entry->firstChild) {
818 _EraseSubtreeAndSiblings(firstChild);
819 _EraseFromTable(firstChild);
825 void _EraseSubtreeAndSiblings(_Entry *entry) {
827 _EraseSubtree(entry);
830 _Entry *sibling = entry->GetNextSibling();
831 _Entry *nextSibling = sibling ? sibling->GetNextSibling() :
nullptr;
833 _EraseSubtree(sibling);
834 _EraseFromTable(sibling);
835 sibling = nextSibling;
836 nextSibling = sibling ? sibling->GetNextSibling() :
nullptr;
842 void _RemoveFromParent(_Entry *entry) {
847 iterator parIter =
find(_GetParentPath(entry->value.first));
850 parIter._entry->RemoveChild(entry);
857 TfAutoMallocTag2 tag2(
"Sdf",
"SdfPathTable::_Grow");
862 _mask =
std::max(
size_t(7), (_mask << 1) + 1);
863 _BucketVec newBuckets(_mask + 1);
866 for (
size_t i = 0,
n = _buckets.size(); i !=
n; ++i) {
867 _Entry *elem = _buckets[i];
870 _Entry *next = elem->next;
873 _Entry *&m = newBuckets[_Hash(elem->value.first)];
885 _buckets.swap(newBuckets);
889 bool _IsTooFull()
const {
890 return _size > _buckets.size();
894 inline size_t _Hash(
SdfPath const &path)
const {
907 #endif // PXR_USD_SDF_PATH_TABLE_H
void ParallelForEach(Callback const &visitFn) const
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
pointer operator->() const
const_iterator begin() const
Return a const_iterator to the start of the table.
_IterBoolPair insert(NodeHandle &&node)
static SDF_API const SdfPath & AbsoluteRootPath()
~SdfPathTable()
Destructor.
key_type & GetMutableKey()
SdfPathTable()
Default constructor.
SdfPathTable & operator=(SdfPathTable const &other)
Copy assignment.
const_iterator end() const
Return a const_iterator denoting the end of the table.
bool operator!=(Iterator< OtherVal, OtherEntryPtr > const &other) const
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
const_iterator find(SdfPath const &path) const
SdfPathTable & operator=(SdfPathTable &&other)
Move assignment.
GLsizei const GLfloat * value
GLsizei const GLchar *const * path
mapped_type const & GetMapped() const
Iterator GetNextSubtree() const
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
void ParallelForEach(Callback const &visitFn)
void UpdateForRename(const SdfPath &oldName, const SdfPath &newName)
**But if you need a result
static NodeHandle New(value_type &&value)
Iterator(Iterator< OtherVal, OtherEntryPtr > const &other)
Copy constructor (also allows for converting non-const to const).
static NodeHandle New(key_type const &key, mapped_type const &mapped)
size_t GetHash() const
Equality operator.
iterator find(SdfPath const &path)
mapped_type & GetMutableMapped()
#define __ARCH_PRETTY_FUNCTION__
std::forward_iterator_tag iterator_category
std::ptrdiff_t difference_type
void erase(iterator const &i)
bool operator==(Iterator< OtherVal, OtherEntryPtr > const &other) const
static NodeHandle New(value_type const &value)
SdfPathTable(SdfPathTable const &other)
Copy constructor.
std::pair< iterator, iterator > FindSubtreeRange(SdfPath const &path)
key_type const & GetKey() const
Iterator< const value_type, const _Entry * > const_iterator
iterator begin()
Return an iterator to the start of the table.
reference operator*() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
size_t size() const
Return the number of elements in the table.
bool equal(Iterator< OtherVal, OtherEntryPtr > const &other) const
size_t count(SdfPath const &path) const
Return 1 if there is an element for path in the table, otherwise 0.
SdfPathTable(SdfPathTable &&other)
Move constructor.
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define PXR_NAMESPACE_CLOSE_SCOPE
std::pair< const_iterator, const_iterator > FindSubtreeRange(SdfPath const &path) const
SDF_API SdfPath GetParentPath() const
bool erase(SdfPath const &path)
mapped_type & operator[](SdfPath const &path)
PXR_NAMESPACE_OPEN_SCOPE SDF_API void Sdf_VisitPathTableInParallel(void **, size_t, TfFunctionRef< void(void *&)>)
bool empty() const
Return true if this table is empty.
std::pair< iterator, bool > _IterBoolPair
Result type for insert().
std::pair< key_type, mapped_type > value_type
Iterator< value_type, _Entry * > iterator
_IterBoolPair insert(value_type const &value)
std::vector< size_t > GetBucketSizes() const
Return a vector of the count of elements in each bucket.
ValType & dereference() const
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
void swap(SdfPathTable &other)
Swap this table's contents with other.
iterator end()
Return an iterator denoting the end of the table.