10#ifndef TPETRA_DETAILS_FIXEDHASHTABLE_DECL_HPP
11#define TPETRA_DETAILS_FIXEDHASHTABLE_DECL_HPP
13#include "Tpetra_Details_Hash.hpp"
18#include "Teuchos_Describable.hpp"
19#include "Teuchos_FancyOStream.hpp"
20#include "Teuchos_VerbosityLevel.hpp"
22#include "Kokkos_Core.hpp"
23#include "KokkosKernels_ArithTraits.hpp"
53template <
class KeyType,
58 typedef typename DeviceType::execution_space execution_space;
59 typedef typename DeviceType::memory_space memory_space;
60 typedef Kokkos::Device<execution_space, memory_space> device_type;
63 typedef typename hash_type::offset_type offset_type;
72 typedef typename Kokkos::View<
const offset_type*, Kokkos::LayoutLeft,
81 typedef typename Kokkos::View<const Kokkos::pair<KeyType, ValueType>*,
82 Kokkos::LayoutLeft, device_type>
92 return contiguousValues_;
99 typedef Kokkos::View<const KeyType*, Kokkos::LayoutLeft, device_type>
keys_type;
206 const Teuchos::ArrayView<const ValueType>&
vals);
208 template <
class K,
class V,
class D>
216 template <
class InDeviceType>
218 typename std::enable_if<!std::is_same<DeviceType, InDeviceType>::value,
int>::type* =
NULL) {
219 using Kokkos::ViewAllocateWithoutInitializing;
241 Kokkos::deep_copy(execution_space(),
val, src.val_);
245 this->minKey_ = src.minKey_;
246 this->maxKey_ = src.maxKey_;
247 this->minVal_ = src.minVal_;
248 this->maxVal_ = src.maxVal_;
249 this->firstContigKey_ = src.firstContigKey_;
250 this->lastContigKey_ = src.lastContigKey_;
251 this->contiguousValues_ = src.contiguousValues_;
252 this->checkedForDuplicateKeys_ = src.checkedForDuplicateKeys_;
253 this->hasDuplicateKeys_ = src.hasDuplicateKeys_;
258 const offset_type
size = this->getSize();
262 return Tpetra::Details::OrdinalTraits<ValueType>::invalid();
267 if (this->hasContiguousValues() &&
268 key >= firstContigKey_ &&
key <= lastContigKey_) {
272 const typename hash_type::result_type
hashVal =
273 hash_type::hashFunc(
key,
size);
275 const offset_type start = ptr_[
hashVal];
277 for (offset_type
k = start;
k <
end; ++
k) {
279 return val_[
k].second;
285 return Tpetra::Details::OrdinalTraits<ValueType>::invalid();
297 if (this->hasContiguousValues()) {
298 return val_.extent(0) +
static_cast<offset_type
>(lastContigKey_ - firstContigKey_);
300 return val_.extent(0);
376 const Teuchos::EVerbosityLevel
verbLevel =
377 Teuchos::Describable::verbLevel_default)
const;
391 KeyType minKey_ = ::KokkosKernels::ArithTraits<KeyType>::max();
398 KeyType maxKey_ = ::KokkosKernels::ArithTraits<KeyType>::max();
404 ValueType minVal_ = ::KokkosKernels::ArithTraits<ValueType>::max();
418 KeyType firstContigKey_ = ::KokkosKernels::ArithTraits<KeyType>::max();
426 KeyType lastContigKey_ = ::KokkosKernels::ArithTraits<KeyType>::max();
434 bool contiguousValues_ =
true;
442 bool checkedForDuplicateKeys_ =
true;
447 bool hasDuplicateKeys_ =
false;
453 bool checkForDuplicateKeys()
const;
457 return ptr_.extent(0) == 0 ?
static_cast<offset_type
>(0) :
static_cast<offset_type>(ptr_.extent(0) - 1);
460 typedef Kokkos::View<
const KeyType*,
461 typename ptr_type::host_mirror_type::array_layout,
462 typename ptr_type::host_mirror_type::execution_space,
463 Kokkos::MemoryUnmanaged>
464 host_input_keys_type;
467 typename ptr_type::host_mirror_type::array_layout,
468 typename ptr_type::host_mirror_type::execution_space,
469 Kokkos::MemoryUnmanaged>
470 host_input_vals_type;
494 init(
const host_input_keys_type& keys,
495 const host_input_vals_type&
vals,
Import KokkosSparse::OrdinalTraits, a traits class for "invalid" (flag) values of integer types,...
Declaration of Tpetra::Details::Profiling, a scope guard for Kokkos Profiling.
Declare and define Tpetra::Details::copyOffsets, an implementation detail of Tpetra (in particular,...
Struct that holds views of the contents of a CrsMatrix.
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.
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_DEFAULTED_FUNCTION FixedHashTable()=default
Default constructor; makes an empty 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.
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,...
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.