Skip to content

Commit

Permalink
#1554: vrt_coll: remove ColT from mapping functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lifflander committed Oct 19, 2021
1 parent 56df696 commit f9f2bd6
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 174 deletions.
7 changes: 3 additions & 4 deletions src/vt/context/runnable_context/collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@

namespace vt { namespace vrt { namespace collection {

template <typename ColT, typename IndexT>
struct CollectionBase;
template <typename IndexT>
struct Indexable;

}}} /* end namespace vt::vrt::collection */

Expand All @@ -69,8 +69,7 @@ struct Collection final : Base {
*
* \param[in] elm the collection element to extract the index and proxy
*/
template <typename ColT>
explicit Collection(vrt::collection::CollectionBase<ColT, IndexT>* elm);
explicit Collection(vrt::collection::Indexable<IndexT>* elm);

/**
* \brief Set the collection context
Expand Down
5 changes: 2 additions & 3 deletions src/vt/context/runnable_context/collection.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@
#define INCLUDED_VT_CONTEXT_RUNNABLE_CONTEXT_COLLECTION_IMPL_H

#include "vt/context/runnable_context/collection.h"
#include "vt/vrt/collection/types/base.h"
#include "vt/vrt/collection/types/indexable.h"
#include "vt/vrt/collection/holders/collection_context_holder.h"

namespace vt { namespace ctx {

template <typename IndexT>
template <typename ColT>
/*explicit*/ Collection<IndexT>::Collection(
vrt::collection::CollectionBase<ColT, IndexT>* elm
vrt::collection::Indexable<IndexT>* elm
) : idx_(elm->getIndex()),
proxy_(elm->getProxy())
{ }
Expand Down
4 changes: 2 additions & 2 deletions src/vt/vrt/collection/holders/col_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace vt { namespace vrt { namespace collection {
* the virtual overloaded function for running LB and destroying the collection
* from a type-erased base class.
*/
template <typename ColT, typename IndexT>
template <typename IndexT>
struct CollectionHolder : BaseHolder {

public:
Expand Down Expand Up @@ -92,7 +92,7 @@ struct CollectionHolder : BaseHolder {
ObjGroupProxyType map_object = no_obj_group; /**< The map object */
bool has_bounds = false; /**< Whether it as bounds */
IndexT bounds = {}; /**< The bounds */
Holder<ColT, IndexT> holder_; /**< Inner holder of elements */
Holder<IndexT> holder_; /**< Inner holder of elements */
};

}}} /* end namespace vt::vrt::collection */
Expand Down
8 changes: 4 additions & 4 deletions src/vt/vrt/collection/holders/col_holder.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@

namespace vt { namespace vrt { namespace collection {

template <typename ColT, typename IndexT>
CollectionHolder<ColT, IndexT>::CollectionHolder(
template <typename IndexT>
CollectionHolder<IndexT>::CollectionHolder(
HandlerType const in_map_fn, bool const in_has_dynamic_membership,
ObjGroupProxyType in_map_object, bool const in_has_bounds,
IndexT const in_bounds
Expand All @@ -61,8 +61,8 @@ CollectionHolder<ColT, IndexT>::CollectionHolder(
bounds(in_bounds)
{ }

template <typename ColT, typename IndexT>
void CollectionHolder<ColT, IndexT>::destroy() {
template <typename IndexT>
void CollectionHolder<IndexT>::destroy() {
holder_.destroyAll();
}

Expand Down
4 changes: 2 additions & 2 deletions src/vt/vrt/collection/holders/elm_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ namespace vt { namespace vrt { namespace collection {
* \brief The holder for the actual collection object that saves a unique_ptr to
* the element.
*/
template <typename ColT, typename IndexT>
template <typename IndexT>
struct ElementHolder {
using VirtualPtrType = std::unique_ptr<CollectionBase<ColT,IndexT>>;
using VirtualPtrType = std::unique_ptr<Indexable<IndexT>>;

explicit ElementHolder(VirtualPtrType in_vc_ptr_);
ElementHolder(ElementHolder&&) = default;
Expand Down
10 changes: 5 additions & 5 deletions src/vt/vrt/collection/holders/elm_holder.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@

namespace vt { namespace vrt { namespace collection {

template <typename ColT, typename IndexT>
ElementHolder<ColT, IndexT>::ElementHolder(VirtualPtrType in_vc_ptr_)
template <typename IndexT>
ElementHolder<IndexT>::ElementHolder(VirtualPtrType in_vc_ptr_)
: vc_ptr_(std::move(in_vc_ptr_))
{ }

template <typename ColT, typename IndexT>
typename ElementHolder<ColT, IndexT>::VirtualPtrType::pointer
ElementHolder<ColT, IndexT>::getRawPtr() const {
template <typename IndexT>
typename ElementHolder<IndexT>::VirtualPtrType::pointer
ElementHolder<IndexT>::getRawPtr() const {
vtAssert(vc_ptr_ != nullptr, "Must be valid pointer");
return vc_ptr_.get();
}
Expand Down
4 changes: 2 additions & 2 deletions src/vt/vrt/collection/holders/entire_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@

namespace vt { namespace vrt { namespace collection {

template <typename ColT, typename IndexT>
template <typename IndexT>
struct EntireHolder {
using InnerHolder = CollectionHolder<ColT, IndexT>;
using InnerHolder = CollectionHolder<IndexT>;
using InnerHolderPtr = std::shared_ptr<InnerHolder>;
using ProxyContainerType = std::unordered_map<
VirtualProxyType, InnerHolderPtr
Expand Down
14 changes: 7 additions & 7 deletions src/vt/vrt/collection/holders/entire_holder.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@

namespace vt { namespace vrt { namespace collection {

template <typename ColT, typename IndexT>
/*static*/ void EntireHolder<ColT, IndexT>::insert(
template <typename IndexT>
/*static*/ void EntireHolder<IndexT>::insert(
VirtualProxyType const& proxy, InnerHolderPtr ptr
) {
proxy_container_[proxy] = ptr;
}

template <typename ColT, typename IndexT>
/*static*/ void EntireHolder<ColT, IndexT>::remove(
template <typename IndexT>
/*static*/ void EntireHolder<IndexT>::remove(
VirtualProxyType const& proxy
) {
auto iter = proxy_container_.find(proxy);
Expand All @@ -72,9 +72,9 @@ template <typename ColT, typename IndexT>
}
}

template <typename ColT, typename IndexT>
/*static*/ typename EntireHolder<ColT, IndexT>::ProxyContainerType
EntireHolder<ColT, IndexT>::proxy_container_;
template <typename IndexT>
/*static*/ typename EntireHolder<IndexT>::ProxyContainerType
EntireHolder<IndexT>::proxy_container_;

}}} /* end namespace vt::vrt::collection */

Expand Down
6 changes: 3 additions & 3 deletions src/vt/vrt/collection/holders/holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ namespace vt { namespace vrt { namespace collection {
* proxy. Provides functionality to find, add, remove, and foreach over the
* collection elements.
*/
template <typename ColT, typename IndexT>
template <typename IndexT>
struct Holder {
template <typename T, typename U>
using ContType = std::unordered_map<T, U>;
using CollectionType = CollectionBase<ColT, IndexT>;
using CollectionType = Indexable<IndexT>;
using VirtualPtrType = std::unique_ptr<CollectionType>;
using LookupElementType = IndexT;
using InnerHolder = ElementHolder<ColT, IndexT>;
using InnerHolder = ElementHolder<IndexT>;
using TypedIndexContainer = ContType<LookupElementType, InnerHolder>;
using LBContFnType = std::function<void()>;
using LBContListType = std::list<LBContFnType>;
Expand Down
58 changes: 29 additions & 29 deletions src/vt/vrt/collection/holders/holder.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@

namespace vt { namespace vrt { namespace collection {

template <typename ColT, typename IndexT>
bool Holder<ColT, IndexT>::exists(IndexT const& idx ) {
template <typename IndexT>
bool Holder<IndexT>::exists(IndexT const& idx ) {
auto& container = vc_container_;
auto iter = container.find(idx);
return iter != container.end() and not iter->second.erased_;
}

template <typename ColT, typename IndexT>
void Holder<ColT, IndexT>::insert(IndexT const& idx, InnerHolder&& inner) {
template <typename IndexT>
void Holder<IndexT>::insert(IndexT const& idx, InnerHolder&& inner) {
vtAssert(!is_destroyed_, "Must not be destroyed to insert a new element");
vtAssert(!exists(idx), "Should not exist to insert element");

Expand Down Expand Up @@ -94,8 +94,8 @@ void Holder<ColT, IndexT>::insert(IndexT const& idx, InnerHolder&& inner) {
);
}

template <typename ColT, typename IndexT>
typename Holder<ColT, IndexT>::InnerHolder& Holder<ColT, IndexT>::lookup(
template <typename IndexT>
typename Holder<IndexT>::InnerHolder& Holder<IndexT>::lookup(
IndexT const& idx
) {
auto const& lookup = idx;
Expand All @@ -107,8 +107,8 @@ typename Holder<ColT, IndexT>::InnerHolder& Holder<ColT, IndexT>::lookup(
return iter->second;
}

template <typename ColT, typename IndexT>
typename Holder<ColT, IndexT>::VirtualPtrType Holder<ColT, IndexT>::remove(
template <typename IndexT>
typename Holder<IndexT>::VirtualPtrType Holder<IndexT>::remove(
IndexT const& idx
) {
auto const& lookup = idx;
Expand All @@ -124,21 +124,21 @@ typename Holder<ColT, IndexT>::VirtualPtrType Holder<ColT, IndexT>::remove(
return owned_ptr;
}

template <typename ColT, typename IndexT>
void Holder<ColT, IndexT>::destroyAll() {
template <typename IndexT>
void Holder<IndexT>::destroyAll() {
if (!is_destroyed_) {
vc_container_.clear();
is_destroyed_ = true;
}
}

template <typename ColT, typename IndexT>
bool Holder<ColT, IndexT>::isDestroyed() const {
template <typename IndexT>
bool Holder<IndexT>::isDestroyed() const {
return is_destroyed_;
}

template <typename ColT, typename IndexT>
void Holder<ColT, IndexT>::cleanupExists() {
template <typename IndexT>
void Holder<IndexT>::cleanupExists() {
auto& container = vc_container_;
for (auto iter = container.begin(); iter != container.end(); ) {
if (iter->second.erased_) {
Expand All @@ -150,8 +150,8 @@ void Holder<ColT, IndexT>::cleanupExists() {
}
}

template <typename ColT, typename IndexT>
void Holder<ColT, IndexT>::foreach(FuncApplyType fn) {
template <typename IndexT>
void Holder<IndexT>::foreach(FuncApplyType fn) {
static uint64_t num_reentrant = 0;

num_reentrant++;
Expand All @@ -171,36 +171,36 @@ void Holder<ColT, IndexT>::foreach(FuncApplyType fn) {
}
}

template <typename ColT, typename IndexT>
typename Holder<ColT,IndexT>::TypedIndexContainer::size_type
Holder<ColT,IndexT>::numElements() const {
template <typename IndexT>
typename Holder<IndexT>::TypedIndexContainer::size_type
Holder<IndexT>::numElements() const {
return vc_container_.size() - num_erased_not_removed_;
}

template <typename ColT, typename IndexT>
typename Holder<ColT,IndexT>::TypedIndexContainer::size_type
Holder<ColT,IndexT>::numElementsExpr(FuncExprType fn) const {
typename Holder<ColT,IndexT>::TypedIndexContainer::size_type num_in = 0;
template <typename IndexT>
typename Holder<IndexT>::TypedIndexContainer::size_type
Holder<IndexT>::numElementsExpr(FuncExprType fn) const {
typename Holder<IndexT>::TypedIndexContainer::size_type num_in = 0;
for (auto&& elm : vc_container_) {
num_in += fn(elm.first);
}
return num_in;
}

template <typename ColT, typename IndexT>
int Holder<ColT, IndexT>::addListener(listener::ListenFnType<IndexT> fn) {
template <typename IndexT>
int Holder<IndexT>::addListener(listener::ListenFnType<IndexT> fn) {
event_listeners_.push_back(fn);
return event_listeners_.size() - 1;
}

template <typename ColT, typename IndexT>
void Holder<ColT, IndexT>::removeListener(int element) {
template <typename IndexT>
void Holder<IndexT>::removeListener(int element) {
vtAssert(event_listeners_.size() > element, "Listener must exist");
event_listeners_[element] = nullptr;
}

template <typename ColT, typename IndexT>
void Holder<ColT, IndexT>::applyListeners(
template <typename IndexT>
void Holder<IndexT>::applyListeners(
listener::ElementEventEnum event, IndexT const& idx
) {
for (auto&& l : event_listeners_) {
Expand Down
Loading

0 comments on commit f9f2bd6

Please sign in to comment.