55 #ifndef _ZOLTAN2_GIDLOOKUPHELPER 56 #define _ZOLTAN2_GIDLOOKUPHELPER 61 #include <Teuchos_Hashtable.hpp> 75 template <
typename T,
typename lno_t>
80 RCP<const Environment> env_;
81 ArrayRCP<const T> gidList_;
84 map<T, lno_t> indexMap_;
86 RCP<Teuchos::Hashtable<double, lno_t> > indexHash_;
92 const ArrayRCP<const T> &gidList);
110 return indexHash_->size();
112 return indexMap_.size();
120 void getIndices(ArrayRCP<lno_t> &indices)
const;
123 template<
typename T,
typename lno_t>
125 env_(rcp(new
Environment)), gidList_(), useHashTable_(false),
126 indexMap_(), indexHash_()
129 template<
typename T,
typename lno_t>
131 const RCP<const Environment> &env,
132 const ArrayRCP<const T> &gidList):
134 gidList_(gidList), useHashTable_(false), indexMap_(), indexHash_()
136 lno_t len = gidList_.size();
142 useHashTable_ =
true;
144 const T *ids = gidList_.getRawPtr();
148 for (
lno_t i=0; i < gidList.size(); i++){
149 typename map<T, lno_t>::iterator rec = indexMap_.find(*ids);
150 if (rec == indexMap_.end())
155 catch (
const std::exception &e){
156 env_->localMemoryAssertion(__FILE__, __LINE__, len,
false);
160 typedef typename Teuchos::Hashtable<double, lno_t> id2index_hash_t;
161 id2index_hash_t *p = NULL;
164 p =
new id2index_hash_t(len);
166 catch (
const std::exception &e){
167 env_->localMemoryAssertion(__FILE__, __LINE__, len,
false);
170 for (
lno_t i=0; i < len; i++){
173 if (!p->containsKey(key))
179 indexHash_ = rcp<id2index_hash_t>(p);
183 template<
typename T,
typename lno_t>
191 idx = indexHash_->get(key);
193 catch (
const std::exception &e) {
198 typename map<T, lno_t>::const_iterator next = indexMap_.find(gid);
199 if (next == indexMap_.end())
202 idx = (*next).second;
205 env_->localInputAssertion(__FILE__, __LINE__,
"invalid global id",
211 template<
typename T,
typename lno_t>
213 ArrayRCP<lno_t> &indices)
const 217 ArrayRCP<lno_t> indexList = arcp(idx, 0, numIds,
true);
219 if (numIds == gidList_.size()){
220 for (
lno_t i=0; i < gidList_.size(); i++){
225 const T *ids = gidList_.getRawPtr();
228 for (
lno_t i=0; i < gidList_.size(); i++){
229 typename set<T>::iterator rec = allGids.find(ids[i]);
230 if (rec == allGids.end()){
231 allGids.insert(ids[i]);
242 #endif // _ZOLTAN2_GIDLOOKUPHELPER
lno_t size() const
the number of unique gids in the list.
fast typical checks for valid arguments
Defines basic traits for user global identifiers.
The functions to be defined for users' global ID types.
static double key(const T c)
Return a double which is a unique key for the value.
lno_t lookup(const T gid) const
the index of the global id in the gidList passed into the constructor.
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
void getIndices(ArrayRCP< lno_t > &indices) const
Return a list of the indices in gidList that were included in the lookup table (all if there were no ...
Gathering definitions used in software development.
Defines the Environment class.
#define Z2_THROW_OUTSIDE_ERROR(env)
Throw an error returned from outside the Zoltan2 library.
A class to do GID lookups.
GidLookupHelper()
Construct an empty lookup helper.