24 #ifndef PXR_USD_SDF_PATH_TABLE_H
25 #define PXR_USD_SDF_PATH_TABLE_H
32 #include <hboost/iterator/iterator_facade.hpp>
33 #include <hboost/noncopyable.hpp>
83 template <
class MappedType>
98 struct _Entry : hboost::noncopyable {
103 , nextSiblingOrParent(0,
false) {}
107 _Entry *GetNextSibling() {
108 return nextSiblingOrParent.template BitsAs<bool>() ?
109 nextSiblingOrParent.Get() : 0;
113 _Entry
const *GetNextSibling()
const {
114 return nextSiblingOrParent.template BitsAs<bool>() ?
115 nextSiblingOrParent.Get() : 0;
120 _Entry *GetParentLink() {
121 return nextSiblingOrParent.template BitsAs<bool>() ? 0 :
122 nextSiblingOrParent.Get();
126 _Entry
const *GetParentLink()
const {
127 return nextSiblingOrParent.template BitsAs<bool>() ? 0 :
128 nextSiblingOrParent.Get();
133 void SetSibling(_Entry *sibling) {
134 nextSiblingOrParent.Set(sibling,
true);
139 void SetParentLink(_Entry *parent) {
140 nextSiblingOrParent.Set(parent,
false);
144 void AddChild(_Entry *child) {
148 child->SetSibling(firstChild);
150 child->SetParentLink(
this);
154 void RemoveChild(_Entry *child) {
156 if (child == firstChild) {
157 firstChild = child->GetNextSibling();
161 _Entry *prev, *cur = firstChild;
164 cur = prev->GetNextSibling();
165 }
while (cur != child);
166 prev->nextSiblingOrParent = cur->nextSiblingOrParent;
189 typedef std::vector<_Entry *> _BucketVec;
196 template <
class ValType,
class EntryPtr>
198 public hboost::iterator_facade<Iterator<ValType, EntryPtr>,
199 ValType, hboost::forward_traversal_tag>
207 template <
class OtherVal,
class OtherEntryPtr>
218 if (EntryPtr sibling =
_entry->GetNextSibling()) {
224 for (EntryPtr
p =
_entry->GetParentLink();
p;
225 p =
p->GetParentLink()) {
226 if (EntryPtr sibling =
p->GetNextSibling()) {
257 template <
class OtherVal,
class OtherEntryPtr>
282 : _buckets(other._buckets.
size())
290 iterator j = _InsertInTable(*i).first;
292 if (i._entry->firstChild && !j._entry->firstChild) {
293 j._entry->firstChild =
294 _InsertInTable(i._entry->firstChild->value).first._entry;
297 if (i._entry->nextSiblingOrParent.Get() &&
298 !j._entry->nextSiblingOrParent.Get()) {
299 j._entry->nextSiblingOrParent.Set(
300 _InsertInTable(i._entry->nextSiblingOrParent.
302 i._entry->nextSiblingOrParent.template BitsAs<bool>());
309 : _buckets(std::move(other._buckets))
386 _Entry *
const entry = i._entry;
387 _EraseSubtree(entry);
388 _RemoveFromParent(entry);
389 _EraseFromTable(entry);
397 for (_Entry *e = _buckets[_Hash(path)]; e; e = e->next) {
398 if (e->value.first == path)
410 for (_Entry
const *e = _buckets[_Hash(path)]; e; e = e->next) {
411 if (e->value.first == path)
421 std::pair<iterator, iterator>
423 std::pair<iterator, iterator>
result;
424 result.first =
find(path);
425 result.second = result.first.GetNextSubtree();
432 std::pair<const_iterator, const_iterator>
434 std::pair<const_iterator, const_iterator>
result;
435 result.first =
find(path);
436 result.second = result.first.GetNextSubtree();
446 inline size_t size()
const {
return _size; }
467 _Entry *
const newEntry = result.first._entry;
468 SdfPath const &parentPath = _GetParentPath(value.first);
473 parIter._entry->AddChild(newEntry);
493 for (
size_t i = 0,
n = _buckets.size(); i !=
n; ++i) {
494 _Entry *entry = _buckets[i];
496 _Entry *next = entry->next;
509 _buckets.size(), _DeleteEntryChain);
515 _buckets.swap(other._buckets);
522 std::vector<size_t>
sizes(_buckets.size(), 0u);;
523 for (
size_t i = 0,
n = _buckets.size(); i !=
n; ++i) {
524 for (_Entry *entry = _buckets[i]; entry; entry = entry->next) {
542 for (
iterator i=range.first; i!=range.second; ++i) {
544 i->first.ReplacePrefix(oldName, newName),
548 if (range.first != range.second)
557 static void _DeleteEntryChain(
void *voidEntry) {
558 _Entry *entry =
static_cast<_Entry *
>(voidEntry);
560 _Entry *next = entry->next;
579 _Entry **bucketHead = &(_buckets[_Hash(value.first)]);
580 for (_Entry *e = *bucketHead; e; e = e->next)
581 if (e->value.first == value.first)
588 bucketHead = &(_buckets[_Hash(value.first)]);
591 TfAutoMallocTag2 tag2(
"Sdf",
"SdfPathTable::_FindOrCreate");
595 *bucketHead =
new _Entry(value, *bucketHead);
605 void _EraseFromTable(_Entry *entry) {
607 _Entry **cur = &_buckets[_Hash(entry->value.first)];
608 while (*cur != entry)
609 cur = &((*cur)->next);
619 void _EraseSubtree(_Entry *entry) {
621 if (_Entry *
const firstChild = entry->firstChild) {
622 _EraseSubtreeAndSiblings(firstChild);
623 _EraseFromTable(firstChild);
629 void _EraseSubtreeAndSiblings(_Entry *entry) {
631 _EraseSubtree(entry);
634 _Entry *sibling = entry->GetNextSibling();
635 _Entry *nextSibling = sibling ? sibling->GetNextSibling() :
nullptr;
637 _EraseSubtree(sibling);
638 _EraseFromTable(sibling);
639 sibling = nextSibling;
640 nextSibling = sibling ? sibling->GetNextSibling() :
nullptr;
646 void _RemoveFromParent(_Entry *entry) {
651 iterator parIter =
find(_GetParentPath(entry->value.first));
654 parIter._entry->RemoveChild(entry);
661 TfAutoMallocTag2 tag2(
"Sdf",
"SdfPathTable::_Grow");
666 _mask =
std::max(
size_t(7), (_mask << 1) + 1);
667 _BucketVec newBuckets(_mask + 1);
670 for (
size_t i = 0,
n = _buckets.size(); i !=
n; ++i) {
671 _Entry *elem = _buckets[i];
674 _Entry *next = elem->next;
677 _Entry *&
m = newBuckets[_Hash(elem->value.first)];
689 _buckets.swap(newBuckets);
693 bool _IsTooFull()
const {
694 return _size > _buckets.size();
698 inline size_t _Hash(
SdfPath const &path)
const {
711 #endif // PXR_USD_SDF_PATH_TABLE_H
vint4 max(const vint4 &a, const vint4 &b)
const_iterator begin() const
Return a const_iterator to the start of the table.
static SDF_API const SdfPath & AbsoluteRootPath()
~SdfPathTable()
Destructor.
SdfPathTable()
Default constructor.
SdfPathTable & operator=(SdfPathTable const &other)
Copy assignment.
const_iterator end() const
Return a const_iterator denoting the end of the table.
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.
Iterator GetNextSubtree() const
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
void UpdateForRename(const SdfPath &oldName, const SdfPath &newName)
Iterator(Iterator< OtherVal, OtherEntryPtr > const &other)
Copy constructor (also allows for converting non-const to const).
friend class hboost::iterator_core_access
iterator find(SdfPath const &path)
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
#define __ARCH_PRETTY_FUNCTION__
void erase(iterator const &i)
SdfPathTable(SdfPathTable const &other)
Copy constructor.
std::pair< iterator, iterator > FindSubtreeRange(SdfPath const &path)
Iterator< const value_type, const _Entry * > const_iterator
GLsizei const GLchar *const * path
iterator begin()
Return an iterator to the start of the table.
PXR_NAMESPACE_OPEN_SCOPE SDF_API void Sdf_ClearPathTableInParallel(void **, size_t, void(*)(void *))
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.
#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)
bool empty() const
Return true if this table is empty.
GLsizei const GLfloat * value
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
void swap(SdfPathTable &other)
Swap this table's contents with other.
iterator end()
Return an iterator denoting the end of the table.