|
KiCad PCB EDA Suite
|
Copy-on-Write wrapper for DYNAMIC_RTREE. More...
#include <dynamic_rtree_cow.h>
Classes | |
| struct | ALLOC_CHAIN |
| class | Iterator |
| Iterator for traversing all data items. More... | |
Public Types | |
| using | NODE = RTREE_NODE<DATATYPE, ELEMTYPE, NUMDIMS, TMAXNODES> |
| using | ALLOC = SLAB_ALLOCATOR<NODE> |
| using | BULK_ENTRY = typename DYNAMIC_RTREE<DATATYPE, ELEMTYPE, NUMDIMS, TMAXNODES>::BULK_ENTRY |
| Bulk load entries using Hilbert curve sorting and bottom-up packing. | |
Public Member Functions | |
| COW_RTREE () | |
| ~COW_RTREE () | |
| COW_RTREE (COW_RTREE &&aOther) noexcept | |
| COW_RTREE & | operator= (COW_RTREE &&aOther) noexcept |
| COW_RTREE (const COW_RTREE &)=delete | |
| COW_RTREE & | operator= (const COW_RTREE &)=delete |
| COW_RTREE | Clone () const |
| Create a clone that shares the tree structure with this tree. | |
| void | Insert (const ELEMTYPE aMin[NUMDIMS], const ELEMTYPE aMax[NUMDIMS], const DATATYPE &aData) |
| Insert an item. | |
| bool | Remove (const ELEMTYPE aMin[NUMDIMS], const ELEMTYPE aMax[NUMDIMS], const DATATYPE &aData) |
| Remove an item. | |
| template<class VISITOR> | |
| int | Search (const ELEMTYPE aMin[NUMDIMS], const ELEMTYPE aMax[NUMDIMS], VISITOR &aVisitor) const |
| Search for items whose bounding boxes overlap the query rectangle. | |
| void | RemoveAll () |
| void | BulkLoad (std::vector< BULK_ENTRY > &aEntries) |
| size_t | size () const |
| bool | empty () const |
| Iterator | begin () const |
| Iterator | end () const |
Private Member Functions | |
| void | ensureWritable (NODE *&aNode) |
| Ensure a node is exclusively owned (refcount == 1). | |
| void | releaseNode (NODE *aNode) |
| Release a reference to a node. | |
| void | freeToOwningAllocator (NODE *aNode) |
| Free a node through the allocator that actually owns its memory. | |
| void | releaseTree (NODE *aNode) |
| Release the entire tree rooted at aNode. | |
| void | insertSimple (NODE *aNode, const ELEMTYPE aMin[NUMDIMS], const ELEMTYPE aMax[NUMDIMS], const DATATYPE &aData) |
| Simplified insertion (no forced reinsert, just split on overflow). | |
| void | simpleSplit (NODE *aNode, const ELEMTYPE aMin[NUMDIMS], const ELEMTYPE aMax[NUMDIMS], const DATATYPE &aData) |
| Simple split for CoW insertion: median split along longest axis. | |
| bool | removeImpl (NODE *aNode, const ELEMTYPE aMin[NUMDIMS], const ELEMTYPE aMax[NUMDIMS], const DATATYPE &aData) |
| template<class VISITOR> | |
| void | searchImpl (NODE *aNode, const ELEMTYPE aMin[NUMDIMS], const ELEMTYPE aMax[NUMDIMS], VISITOR &aVisitor, int &aFound) const |
Private Attributes | |
| NODE * | m_root = nullptr |
| size_t | m_count = 0 |
| std::shared_ptr< ALLOC > | m_allocator |
| std::shared_ptr< ALLOC_CHAIN > | m_parentChain |
Copy-on-Write wrapper for DYNAMIC_RTREE.
Provides O(1) Clone() for the PNS router's branching pattern. The router frequently creates speculative branches that share most of their spatial index with the parent. Instead of copying all items, Clone() shares the tree structure via reference counting on nodes, only copying nodes along mutation paths.
When a node is shared between parent and clone (refcount > 1), any mutation first copies the node, decrements the old node's refcount, and increments refcounts on children that are now shared with the new copy.
| DATATYPE | Type of data stored in leaf nodes |
| ELEMTYPE | Coordinate element type (typically int) |
| NUMDIMS | Number of dimensions (2 or 3) |
| TMAXNODES | Maximum children per node (fanout) |
Definition at line 51 of file dynamic_rtree_cow.h.
| using KIRTREE::COW_RTREE< DATATYPE, ELEMTYPE, NUMDIMS, TMAXNODES >::ALLOC = SLAB_ALLOCATOR<NODE> |
Definition at line 55 of file dynamic_rtree_cow.h.
| using KIRTREE::COW_RTREE< DATATYPE, ELEMTYPE, NUMDIMS, TMAXNODES >::BULK_ENTRY = typename DYNAMIC_RTREE<DATATYPE, ELEMTYPE, NUMDIMS, TMAXNODES>::BULK_ENTRY |
Bulk load entries using Hilbert curve sorting and bottom-up packing.
Clears any existing tree first.
Definition at line 220 of file dynamic_rtree_cow.h.
| using KIRTREE::COW_RTREE< DATATYPE, ELEMTYPE, NUMDIMS, TMAXNODES >::NODE = RTREE_NODE<DATATYPE, ELEMTYPE, NUMDIMS, TMAXNODES> |
Definition at line 54 of file dynamic_rtree_cow.h.
|
inline |
Definition at line 67 of file dynamic_rtree_cow.h.
|
inline |
Definition at line 72 of file dynamic_rtree_cow.h.
|
inlinenoexcept |
Definition at line 78 of file dynamic_rtree_cow.h.
|
delete |
|
inline |
Definition at line 441 of file dynamic_rtree_cow.h.
|
inline |
Definition at line 222 of file dynamic_rtree_cow.h.
|
inline |
Create a clone that shares the tree structure with this tree.
The clone holds a shared_ptr to the parent's allocator to keep nodes alive as long as any tree references them.
Definition at line 114 of file dynamic_rtree_cow.h.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
inline |
Definition at line 351 of file dynamic_rtree_cow.h.
|
inline |
Definition at line 442 of file dynamic_rtree_cow.h.
|
inlineprivate |
Ensure a node is exclusively owned (refcount == 1).
If shared, create a copy in our own allocator and decrement the original's refcount.
Definition at line 449 of file dynamic_rtree_cow.h.
Referenced by KIRTREE::COW_RTREE< T, int, 2 >::Insert(), KIRTREE::COW_RTREE< T, int, 2 >::insertSimple(), KIRTREE::COW_RTREE< T, int, 2 >::Remove(), and KIRTREE::COW_RTREE< T, int, 2 >::removeImpl().
|
inlineprivate |
Free a node through the allocator that actually owns its memory.
Without this, freeing a parent-allocated node through the clone's allocator would corrupt the page bitset and leak the slot.
Definition at line 517 of file dynamic_rtree_cow.h.
Referenced by KIRTREE::COW_RTREE< T, int, 2 >::releaseNode().
|
inline |
Insert an item.
If nodes along the path are shared, they are copied first.
Definition at line 136 of file dynamic_rtree_cow.h.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
inlineprivate |
Simplified insertion (no forced reinsert, just split on overflow).
Sufficient for PNS router's incremental modifications to cloned trees.
Definition at line 549 of file dynamic_rtree_cow.h.
Referenced by KIRTREE::COW_RTREE< T, int, 2 >::Insert(), and KIRTREE::COW_RTREE< T, int, 2 >::insertSimple().
|
delete |
|
inlinenoexcept |
Definition at line 88 of file dynamic_rtree_cow.h.
|
inlineprivate |
Release a reference to a node.
If refcount drops to 0, free it through the allocator that owns the node's memory.
Definition at line 495 of file dynamic_rtree_cow.h.
Referenced by KIRTREE::COW_RTREE< T, int, 2 >::ensureWritable(), KIRTREE::COW_RTREE< T, int, 2 >::releaseNode(), KIRTREE::COW_RTREE< T, int, 2 >::releaseTree(), KIRTREE::COW_RTREE< T, int, 2 >::Remove(), and KIRTREE::COW_RTREE< T, int, 2 >::removeImpl().
|
inlineprivate |
Release the entire tree rooted at aNode.
Definition at line 540 of file dynamic_rtree_cow.h.
Referenced by KIRTREE::COW_RTREE< T, int, 2 >::operator=(), KIRTREE::COW_RTREE< T, int, 2 >::RemoveAll(), and KIRTREE::COW_RTREE< T, int, 2 >::~COW_RTREE().
|
inline |
Remove an item.
If nodes along the path are shared, they are copied first.
Definition at line 157 of file dynamic_rtree_cow.h.
|
inline |
Definition at line 209 of file dynamic_rtree_cow.h.
Referenced by KIRTREE::COW_RTREE< T, int, 2 >::BulkLoad().
|
inlineprivate |
Definition at line 751 of file dynamic_rtree_cow.h.
Referenced by KIRTREE::COW_RTREE< T, int, 2 >::Remove(), and KIRTREE::COW_RTREE< T, int, 2 >::removeImpl().
|
inline |
Search for items whose bounding boxes overlap the query rectangle.
Read-only, no CoW needed.
Definition at line 198 of file dynamic_rtree_cow.h.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
inlineprivate |
Definition at line 800 of file dynamic_rtree_cow.h.
Referenced by KIRTREE::COW_RTREE< T, int, 2 >::Search(), and KIRTREE::COW_RTREE< T, int, 2 >::searchImpl().
|
inlineprivate |
Simple split for CoW insertion: median split along longest axis.
Definition at line 609 of file dynamic_rtree_cow.h.
Referenced by KIRTREE::COW_RTREE< T, int, 2 >::insertSimple().
|
inline |
Definition at line 350 of file dynamic_rtree_cow.h.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
private |
Definition at line 828 of file dynamic_rtree_cow.h.
Referenced by KIRTREE::COW_RTREE< T, int, 2 >::Clone().
|
private |
Definition at line 827 of file dynamic_rtree_cow.h.
Referenced by KIRTREE::COW_RTREE< T, int, 2 >::Clone().
|
private |
Definition at line 829 of file dynamic_rtree_cow.h.
Referenced by KIRTREE::COW_RTREE< T, int, 2 >::Clone().
|
private |
Definition at line 826 of file dynamic_rtree_cow.h.
Referenced by KIRTREE::COW_RTREE< T, int, 2 >::Clone().