MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ publish()

template<typename PointT >
void MayaFlux::Kinesis::SpatialIndex< PointT >::publish ( )

Atomically publish the current write-side state as a new read snapshot.

Call once per frame after all mutations are complete. Readers see the previous snapshot until this call completes.

Definition at line 165 of file SpatialIndex.cpp.

166{
167 auto snap = std::make_unique<SpatialSnapshot<PointT>>();
168 snap->cell_size = m_cell_size;
169
170 if constexpr (detail::PointTraits<PointT>::fixed_dimension) {
171 snap->dimensions = detail::PointTraits<PointT>::dimensions;
172 } else {
173 snap->dimensions = m_positions.empty()
174 ? 0
176 }
177
178 auto live_count = static_cast<uint32_t>(m_id_to_slot.size());
179 snap->positions.reserve(live_count);
180 snap->slot_to_id.reserve(live_count);
181 snap->id_to_slot.reserve(live_count);
182
183 for (const auto& [id, slot] : m_id_to_slot) {
184 auto new_slot = static_cast<uint32_t>(snap->positions.size());
185 snap->positions.push_back(m_positions[slot]);
186 snap->slot_to_id.push_back(id);
187 snap->id_to_slot[id] = new_slot;
188 }
189
190 if (m_use_grid) {
191 rebuild_grid(*snap);
192 }
193
194#ifdef MAYAFLUX_PLATFORM_MACOS
195 auto* old = m_snapshot.exchange(snap.release(), std::memory_order_acq_rel);
196 if (old) {
197 retire_snapshot(old);
198 }
199#else
200 m_snapshot.store(
201 std::shared_ptr<const SpatialSnapshot<PointT>>(snap.release()),
202 std::memory_order_release);
203#endif
204}
uint32_t id
std::vector< PointT > m_positions
void rebuild_grid(SpatialSnapshot< PointT > &snap) const
std::atomic< std::shared_ptr< const SpatialSnapshot< PointT > > > m_snapshot
std::unordered_map< uint32_t, uint32_t > m_id_to_slot
uint32_t get_dimensions(const PointT &p)

References MayaFlux::Kinesis::detail::get_dimensions(), and id.

+ Here is the call graph for this function: