58 using BaseVertexID = std::remove_cv_t<VertexID>;
60 static_assert(std::is_integral_v<BaseVertexID>,
61 "The VertexID must be an integral type");
68 using Offset =
typename Neighbours::size_type;
71 using Start = std::vector<Offset>;
109 bool expandExistingIdxMap =
false);
123 return this->csr_.startPointers();
130 return this->csr_.columnIndices();
140 template <
typename Ret = const Start&>
143 return this->csr_.compressedIndexMap();
147 template <
class MessageBufferType>
148 void write(MessageBufferType& buffer)
const
150 this->csr_.write(buffer);
154 template <
class MessageBufferType>
155 void read(MessageBufferType& buffer)
161 .add(other.maxRowID(),
163 other.coordinateFormatRowIndices(),
164 other.columnIndices());
191 void add(VertexID v1, VertexID v2);
206 void add(VertexID maxRowIdx,
221 bool isValid()
const;
224 std::optional<BaseVertexID> maxRow()
const;
227 std::optional<BaseVertexID> maxCol()
const;
230 typename Neighbours::size_type numContributions()
const;
239 VertexID findMergedVertexID(VertexID v,
const std::unordered_map<VertexID, VertexID>& vertex_merges)
const;
242 std::unordered_map<VertexID, VertexID>
applyVertexMerges(
const std::unordered_map<VertexID, VertexID>& vertex_merges);
252 std::optional<VertexID> max_i_{};
255 std::optional<VertexID> max_j_{};
280 void merge(
const Connections& conns,
281 const Offset maxNumVertices,
282 const bool expandExistingIdxMap);
288 BaseVertexID maxRowID()
const;
291 BaseVertexID maxColID()
const;
294 const Start& startPointers()
const;
302 Neighbours coordinateFormatRowIndices()
const;
304 template <
typename Ret = const Start&>
305 std::enable_if_t<TrackCompressedIdx, Ret> compressedIndexMap()
const
307 return this->compressedIdx_;
311 template <
class MessageBufferType>
312 void write(MessageBufferType& buffer)
const
314 this->writeVector(this->ia_, buffer);
315 this->writeVector(this->ja_, buffer);
317 if constexpr (TrackCompressedIdx) {
318 this->writeVector(this->compressedIdx_, buffer);
321 buffer.write(this->numRows_);
322 buffer.write(this->numCols_);
326 template <
class MessageBufferType>
327 void read(MessageBufferType& buffer)
329 this->readVector(buffer, this->ia_);
330 this->readVector(buffer, this->ja_);
332 if constexpr (TrackCompressedIdx) {
333 this->readVector(buffer, this->compressedIdx_);
336 buffer.read(this->numRows_);
337 buffer.read(this->numCols_);
344 struct EmptyPlaceHolder {};
358 std::conditional_t<TrackCompressedIdx, Start, EmptyPlaceHolder> compressedIdx_{};
361 BaseVertexID numRows_{};
365 BaseVertexID numCols_{};
371 template <
typename T,
class A,
class MessageBufferType>
372 void writeVector(
const std::vector<T,A>& vec,
373 MessageBufferType& buffer)
const
375 const auto n = vec.size();
378 for (
const auto& x : vec) {
383 template <
class MessageBufferType,
typename T,
class A>
384 void readVector(MessageBufferType& buffer,
385 std::vector<T,A>& vec)
387 auto n = 0 * vec.size();
392 for (
auto& x : vec) {
431 BaseVertexID maxRowID,
432 BaseVertexID maxColID,
433 bool expandExistingIdxMap);
445 void compress(
const Offset maxNumVertices);
453 void sortColumnIndicesPerRow();
464 void condenseDuplicates();
483 void preparePushbackRowGrouping(
const int numRows,
497 void groupAndTrackColumnIndicesByRow(
const Neighbours& rowIdx,
526 void condenseAndTrackUniqueColumnsForSingleRow(
typename Neighbours::const_iterator begin,
527 typename Neighbours::const_iterator end);
538 void remapCompressedIndex(
Start&& compressedIdx,
539 std::optional<typename Start::size_type> numOrigNNZ = std::nullopt);
545 Connections uncompressed_;
551 std::unordered_map<VertexID, VertexID> parent_{};
554 std::unordered_map<VertexID, VertexID> vertex_mapping_{};
557 VertexID find(VertexID v);
560 void unionSets(VertexID a, VertexID b);