44 #ifndef TPETRA_DETAILS_FIXEDHASHTABLE_DECL_HPP
45 #define TPETRA_DETAILS_FIXEDHASHTABLE_DECL_HPP
47 #include "Tpetra_Details_Hash.hpp"
50 #include "Teuchos_Describable.hpp"
51 #include "Teuchos_FancyOStream.hpp"
52 #include "Teuchos_VerbosityLevel.hpp"
53 #include "Kokkos_Core.hpp"
83 template<
class KeyType,
88 typedef typename DeviceType::execution_space execution_space;
89 typedef typename DeviceType::memory_space memory_space;
90 typedef Kokkos::Device<execution_space, memory_space> device_type;
102 typedef typename Kokkos::View<
const offset_type*, Kokkos::LayoutLeft,
103 device_type> ptr_type;
110 typedef typename Kokkos::View<const Kokkos::pair<KeyType, ValueType>*,
111 Kokkos::LayoutLeft, device_type> val_type;
119 KOKKOS_INLINE_FUNCTION
bool hasContiguousValues ()
const {
120 return contiguousValues_;
127 typedef Kokkos::View<const KeyType*, Kokkos::LayoutLeft, device_type>
keys_type;
166 const ValueType startingValue);
180 const ValueType startingValue);
201 const KeyType firstContigKey,
202 const KeyType lastContigKey,
203 const ValueType startingValue);
221 const KeyType firstContigKey,
222 const KeyType lastContigKey,
223 const ValueType startingValue);
234 const Teuchos::ArrayView<const ValueType>& vals);
236 template<
class K,
class V,
class D>
244 template<
class InDeviceType>
246 typename std::enable_if<! std::is_same<DeviceType, InDeviceType>::value,
int>::type* = NULL)
248 using Kokkos::ViewAllocateWithoutInitializing;
249 typedef typename ptr_type::non_const_type nonconst_ptr_type;
250 typedef typename val_type::non_const_type nonconst_val_type;
260 nonconst_ptr_type ptr (ViewAllocateWithoutInitializing (
"Tpetra::FixedHashTable::ptr"),
261 src.ptr_.extent (0));
263 nonconst_val_type val (ViewAllocateWithoutInitializing (
"Tpetra::FixedHashTable::val"),
264 src.val_.extent (0));
271 this->minKey_ = src.minKey_;
272 this->maxKey_ = src.maxKey_;
273 this->minVal_ = src.minVal_;
274 this->maxVal_ = src.maxVal_;
275 this->firstContigKey_ = src.firstContigKey_;
276 this->lastContigKey_ = src.lastContigKey_;
277 this->contiguousValues_ = src.contiguousValues_;
278 this->checkedForDuplicateKeys_ = src.checkedForDuplicateKeys_;
279 this->hasDuplicateKeys_ = src.hasDuplicateKeys_;
283 KOKKOS_INLINE_FUNCTION ValueType
get (
const KeyType& key)
const {
284 const offset_type size = this->getSize ();
288 return Tpetra::Details::OrdinalTraits<ValueType>::invalid ();
293 if (this->hasContiguousValues () &&
294 key >= firstContigKey_ && key <= lastContigKey_) {
295 return static_cast<ValueType
> (key - firstContigKey_) + this->
minVal ();
301 const offset_type start = ptr_[hashVal];
302 const offset_type end = ptr_[hashVal+1];
303 for (offset_type k = start; k < end; ++k) {
304 if (val_[k].first == key) {
305 return val_[k].second;
311 return Tpetra::Details::OrdinalTraits<ValueType>::invalid ();
317 KOKKOS_INLINE_FUNCTION offset_type
numPairs ()
const {
323 if (this->hasContiguousValues ()) {
324 return val_.extent (0) +
static_cast<offset_type
> (lastContigKey_ - firstContigKey_);
327 return val_.extent (0);
339 KOKKOS_INLINE_FUNCTION KeyType
minKey ()
const {
351 KOKKOS_INLINE_FUNCTION KeyType
maxKey ()
const {
362 KOKKOS_INLINE_FUNCTION ValueType
minVal ()
const {
373 KOKKOS_INLINE_FUNCTION ValueType
maxVal ()
const {
402 describe (Teuchos::FancyOStream &out,
403 const Teuchos::EVerbosityLevel verbLevel=
404 Teuchos::Describable::verbLevel_default)
const;
443 KeyType firstContigKey_;
451 KeyType lastContigKey_;
459 bool contiguousValues_;
466 bool checkedForDuplicateKeys_;
471 bool hasDuplicateKeys_;
477 bool checkForDuplicateKeys ()
const;
480 KOKKOS_INLINE_FUNCTION offset_type getSize ()
const {
481 return ptr_.extent (0) == 0 ?
482 static_cast<offset_type
> (0) :
483 static_cast<offset_type
> (ptr_.extent (0) - 1);
486 typedef Kokkos::View<
const KeyType*,
487 typename ptr_type::HostMirror::array_layout,
488 typename ptr_type::HostMirror::execution_space,
489 Kokkos::MemoryUnmanaged> host_input_keys_type;
491 typedef Kokkos::View<
const ValueType*,
492 typename ptr_type::HostMirror::array_layout,
493 typename ptr_type::HostMirror::execution_space,
494 Kokkos::MemoryUnmanaged> host_input_vals_type;
504 const ValueType startingValue,
507 KeyType firstContigKey,
508 KeyType lastContigKey,
509 const bool computeInitContigKeys);
518 init (
const host_input_keys_type& keys,
519 const host_input_vals_type& vals,
Import KokkosSparse::OrdinalTraits, a traits class for "invalid" (flag) values of integer types,...
Declare and define Tpetra::Details::copyOffsets, an implementation detail of Tpetra (in particular,...
KOKKOS_INLINE_FUNCTION ValueType minVal() const
The minimum value in the table.
std::string description() const
Implementation of Teuchos::Describable interface.
bool hasDuplicateKeys()
Whether the table has any duplicate keys.
FixedHashTable(const FixedHashTable< KeyType, ValueType, InDeviceType > &src, typename std::enable_if<! std::is_same< DeviceType, InDeviceType >::value, int >::type *=NULL)
"Copy" constructor that takes a FixedHashTable with the same KeyType and ValueType,...
KOKKOS_INLINE_FUNCTION offset_type numPairs() const
Number of (key, value) pairs in the table.
Kokkos::View< const KeyType *, Kokkos::LayoutLeft, device_type > keys_type
Type of a 1-D Kokkos::View (array) used to store keys.
KOKKOS_INLINE_FUNCTION KeyType maxKey() const
The maximum key in the table.
KOKKOS_INLINE_FUNCTION ValueType maxVal() const
The maximum value in the table.
KOKKOS_INLINE_FUNCTION KeyType minKey() const
The minimum key in the table.
KOKKOS_INLINE_FUNCTION ValueType get(const KeyType &key) const
Get the value corresponding to the given key.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print this object with the given verbosity to the output stream.
Implementation details of Tpetra.
void copyOffsets(const OutputViewType &dst, const InputViewType &src)
Copy row offsets (in a sparse graph or matrix) from src to dst. The offsets may have different types.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
The hash function for FixedHashTable.
ResultType result_type
Type of the return value of the hash function.
static KOKKOS_INLINE_FUNCTION result_type hashFunc(const argument_type &key, const offset_type &size)
The hash function.
OffsetType offset_type
Type of offsets into the hash table's array of (key,value) pairs.