Skip to content

Commit

Permalink
assign and bind to deal with different types of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaAtulTewari committed Jun 13, 2024
1 parent 6478593 commit c3bf573
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
17 changes: 14 additions & 3 deletions include/pando-lib-galois/graphs/dist_local_csr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ class DistLocalCSR {

private:
constexpr static pando::GlobalRef<CSR> getCachedCSR(CSRCache cache, std::uint64_t i) {
return fmap(cache.getLocalRef(), operator[], i);
return applyFunc(cache.getLocalRef(), [i](HostIndexedMap<CSR> map) {
return map[i];
});
}

template <typename T>
Expand Down Expand Up @@ -500,9 +502,18 @@ class DistLocalCSR {
}

VertexDataRange vertexDataRange() noexcept {
return VertexDataRange{arrayOfCSRs, lift(getCSR(0), vertexData.begin),
lift(getCSR(arrayOfCSRs.size() - 1), vertexData.end), numVertices};
return VertexDataRange{arrayOfCSRs,
applyFunc(getCSR(0),
[](CSR csr) {
return csr.vertexData.begin();
}),
applyFunc(getCSR(arrayOfCSRs.size() - 1),
[](CSR csr) {
return csr.vertexData.end();
}),
numVertices};
}

EdgeDataRange edgeDataRange(VertexTopologyID vertex) noexcept {
return fmap(getCSR(vertex), edgeDataRange, vertex);
}
Expand Down
16 changes: 16 additions & 0 deletions include/pando-lib-galois/utility/gptr_monad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,20 @@
*ptrComputed##__LINE__ = tmp; \
} while (0)

#include <pando-rt/memory/global_ptr.hpp>

template <typename T, typename F>
auto bindFunc(pando::GlobalRef<T> ref, F func) {
T obj = ref;
auto ret = func(obj);
ref = obj;
return ret;
}

template <typename T, typename F>
auto applyFunc(pando::GlobalRef<T> ref, F func) {
T obj = ref;
return func(obj);
}

#endif // PANDO_LIB_GALOIS_UTILITY_GPTR_MONAD_HPP_

0 comments on commit c3bf573

Please sign in to comment.