@@ -212,7 +212,7 @@ class HostEnvironmentDirectedGraph {
212
212
class Edge {
213
213
std::shared_ptr<detail::CUDAEnvironmentDirectedGraphBuffers> directed_graph;
214
214
const cudaStream_t stream;
215
- id_t source_vertex_id, destination_vertex_id ;
215
+ unsigned int edge_index ;
216
216
friend Edge EdgeMap::operator [](SrcDestPair);
217
217
friend struct Iterator ;
218
218
@@ -289,30 +289,21 @@ class HostEnvironmentDirectedGraph {
289
289
Iterator (std::shared_ptr<detail::CUDAEnvironmentDirectedGraphBuffers> _directed_graph, const cudaStream_t _stream, difference_type _index)
290
290
: directed_graph(std::move(_directed_graph))
291
291
, stream(_stream)
292
- , index(_index)
293
292
, edge(_directed_graph, _stream, _index) {}
294
293
reference operator *() const { return edge; }
295
294
pointer operator ->() const { return &edge; }
296
- Iterator& operator ++() { index ++; update_edge () ; return *this ; }
297
- Iterator operator ++(int ) { Iterator tmp = *this ; ++(*this ); tmp. update_edge (); return tmp; }
295
+ Iterator& operator ++() { edge. edge_index ++ ; return *this ; }
296
+ Iterator operator ++(int ) { Iterator tmp = *this ; ++(*this ); return tmp; }
298
297
299
- bool operator == (const Iterator& a, const Iterator& b ) const { return a. index == b. index ; }
300
- bool operator != (const Iterator& a, const Iterator& b ) const { return a. index != b. index ; }
298
+ bool operator == (const Iterator& other ) const { return edge. edge_index == other. edge . edge_index ; }
299
+ bool operator != (const Iterator& other ) const { return edge. edge_index != other. edge . edge_index ; }
301
300
302
301
Iterator begin () { return { directed_graph, stream, 0 }; }
303
302
Iterator end () { return { directed_graph, stream, directed_graph->getEdgeCount () }; }
304
303
305
304
private:
306
- void update_edge () {
307
- edge.source_vertex_id = directed_graph->getSourceVertexID (index , stream);
308
- edge.destination_vertex_id = directed_graph->getDestinationVertexID (index , stream);
309
- if (edge.source_vertex_id == ID_NOT_SET || edge.destination_vertex_id == ID_NOT_SET) {
310
- index = directed_graph->getEdgeCount ();
311
- }
312
- }
313
305
std::shared_ptr<detail::CUDAEnvironmentDirectedGraphBuffers> directed_graph;
314
306
cudaStream_t stream;
315
- difference_type index;
316
307
mutable Edge edge;
317
308
};
318
309
@@ -343,8 +334,6 @@ std::vector<T> HostEnvironmentDirectedGraph::VertexMap::Vertex::getPropertyArray
343
334
}
344
335
template <typename T>
345
336
void HostEnvironmentDirectedGraph::EdgeMap::Edge::setPropertyArray (const std::string& property_name, const std::vector<T>& property_value) const {
346
- // Get index
347
- const unsigned int edge_index = directed_graph->getEdgeIndex (source_vertex_id, destination_vertex_id);
348
337
size_type n = property_value.size ();
349
338
T* val = directed_graph->getEdgePropertyBuffer <T>(property_name, n, stream);
350
339
if (!property_value.size ()) {
@@ -355,8 +344,6 @@ void HostEnvironmentDirectedGraph::EdgeMap::Edge::setPropertyArray(const std::st
355
344
}
356
345
template <typename T>
357
346
std::vector<T> HostEnvironmentDirectedGraph::EdgeMap::Edge::getPropertyArray (const std::string& property_name) const {
358
- // Get index
359
- const unsigned int edge_index = directed_graph->getEdgeIndex (source_vertex_id, destination_vertex_id);
360
347
return directed_graph->getEdgePropertyArray <T>(property_name, edge_index, stream);
361
348
}
362
349
#endif
@@ -422,16 +409,12 @@ std::array<T, N> HostEnvironmentDirectedGraph::VertexMap::Vertex::getProperty(co
422
409
423
410
template <typename T>
424
411
void HostEnvironmentDirectedGraph::EdgeMap::Edge::setProperty (const std::string& property_name, const T property_value) {
425
- // Get index
426
- const unsigned int edge_index = directed_graph->getEdgeIndex (source_vertex_id, destination_vertex_id);
427
412
size_type element_ct = 1 ;
428
413
T* val = directed_graph->getEdgePropertyBuffer <T>(property_name, element_ct, stream);
429
414
val[edge_index] = property_value;
430
415
}
431
416
template <typename T, flamegpu::size_type N>
432
417
void HostEnvironmentDirectedGraph::EdgeMap::Edge::setProperty (const std::string& property_name, const size_type element_index, const T property_value) {
433
- // Get index
434
- const unsigned int edge_index = directed_graph->getEdgeIndex (source_vertex_id, destination_vertex_id);
435
418
size_type element_ct = N;
436
419
T* val = directed_graph->getEdgePropertyBuffer <T>(property_name, element_ct, stream);
437
420
if (element_index >= element_ct) {
@@ -442,25 +425,19 @@ void HostEnvironmentDirectedGraph::EdgeMap::Edge::setProperty(const std::string&
442
425
}
443
426
template <typename T, flamegpu::size_type N>
444
427
void HostEnvironmentDirectedGraph::EdgeMap::Edge::setProperty (const std::string& property_name, const std::array<T, N>& property_value) {
445
- // Get index
446
- const unsigned int edge_index = directed_graph->getEdgeIndex (source_vertex_id, destination_vertex_id);
447
428
size_type element_ct = N;
448
429
T* val = directed_graph->getEdgePropertyBuffer <T>(property_name, element_ct, stream);
449
430
std::array<T, N>* val2 = reinterpret_cast <std::array<T, N>*>(val);
450
431
val2[edge_index] = property_value;
451
432
}
452
433
template <typename T>
453
434
T HostEnvironmentDirectedGraph::EdgeMap::Edge::getProperty (const std::string& property_name) const {
454
- // Get index
455
- const unsigned int edge_index = directed_graph->getEdgeIndex (source_vertex_id, destination_vertex_id);
456
435
size_type element_ct = 1 ;
457
436
const T* rtn = const_cast <const detail::CUDAEnvironmentDirectedGraphBuffers*>(directed_graph.get ())->getEdgePropertyBuffer <T>(property_name, element_ct, stream);
458
437
return rtn[edge_index];
459
438
}
460
439
template <typename T, flamegpu::size_type N>
461
440
T HostEnvironmentDirectedGraph::EdgeMap::Edge::getProperty (const std::string& property_name, const size_type element_index) const {
462
- // Get index
463
- const unsigned int edge_index = directed_graph->getEdgeIndex (source_vertex_id, destination_vertex_id);
464
441
size_type element_ct = N;
465
442
const T* rtn = const_cast <const detail::CUDAEnvironmentDirectedGraphBuffers*>(directed_graph.get ())->getEdgePropertyBuffer <T>(property_name, element_ct, stream);
466
443
if (element_index >= element_ct) {
@@ -471,8 +448,6 @@ T HostEnvironmentDirectedGraph::EdgeMap::Edge::getProperty(const std::string& pr
471
448
}
472
449
template <typename T, flamegpu::size_type N>
473
450
std::array<T, N> HostEnvironmentDirectedGraph::EdgeMap::Edge::getProperty (const std::string& property_name) const {
474
- // Get index
475
- const unsigned int edge_index = directed_graph->getEdgeIndex (source_vertex_id, destination_vertex_id);
476
451
size_type element_ct = N;
477
452
const T *rtn = const_cast <const detail::CUDAEnvironmentDirectedGraphBuffers*>(directed_graph.get ())->getEdgePropertyBuffer <T>(property_name, element_ct, stream);
478
453
const std::array<T, N>* rtn2 = reinterpret_cast <const std::array<T, N>*>(rtn);
0 commit comments