Dense
-
template<typename RegType, template<typename> class MergeOp, std::size_t Size>
class Dense General Dense Sketch Container.
good reference for operator declarations: https://stackoverflow.com/questions/4421706/what-are-the-basic-rules-and-idioms-for-operator-overloading
Implements the container handling infrastructure of any sketch whose atomic elements include a fixed size set of of register values and supporting a merge operation consisting of the application of an element-wise operator on pairs of register vectors.
- Template Parameters:
RegType – The type held by each register.
MergeOp – An template merge operator to combine two sketches.
Size – The maximum number of registers. Must equal the embedding dimension of the transform to be used.
Public Functions
-
inline Dense(const self_type &rhs)
Copy constructor.
- Parameters:
rhs – The base Dense container to copy.
-
inline void compactify()
A no-op for dense containers.
-
inline void clear()
Set all registers to 0.
-
inline bool empty() const
Check if all registers are 0.
-
inline constexpr void merge(const self_type &rhs)
Merge other Dense registers into
this.- Parameters:
rhs – the other Dense. Care must be taken to ensure that one does not merge sketches of different types.
- Throws:
std::invalid_argument – if the register sizes do not match.
-
inline self_type &operator+=(const self_type &rhs)
Operator overload for convenience for embeddings without additional consistency checks.
-
inline constexpr registers_type::iterator begin()
Mutable begin iterator.
-
inline constexpr registers_type::const_iterator begin() const
Const begin iterator.
-
inline constexpr registers_type::const_iterator cbegin() const
Const begin iterator.
-
inline constexpr registers_type::iterator end()
Mutable end iterator.
-
inline constexpr registers_type::const_iterator end() const
Const end iterator.
-
inline constexpr registers_type::const_iterator cend()
Const end iterator.
-
inline constexpr const register_type &operator[](const std::uint64_t index) const
Const access Dense at
index.- Parameters:
index – The index of the underlying vector to index. Must be less than
size.- Returns:
constexpr const register_type& A const reference to
_registers[index].
-
inline register_type &operator[](const std::uint64_t index)
Access Dense at
index.- Parameters:
index – The index of the underlying vector to index. Must be less than
size.- Returns:
register_type& A reference to
_registers[index].
-
inline const registers_type ®isters() const
Get a reference to the raw registers vector.
- Returns:
const registers_type The register vector.
-
inline dense_registers_type scaled_registers(const double scaling_factor) const
Get a copy of the raw scaled registers vector.
- Parameters:
scaling_factor – the scalar scaling factor.
- Returns:
const registers_type The scaled register vector.
-
inline constexpr bool same_registers(const self_type &rhs) const
Checks whether another Dense container has the same register state.
- Parameters:
rhs – The other container.
- Returns:
true The registers agree.
- Returns:
false At least one register disagrees.
-
inline self_type &operator=(self_type rhs)
Copy-and-swap assignment operator.
- Parameters:
rhs – The other container.
- Returns:
self_type&
this, having been swapped withrhs.
Public Static Functions
-
static inline constexpr std::string name()
Returns a description of the type of container.
- Returns:
std::string “Dense”
-
static inline constexpr std::string full_name()
Returns a description of the fully-qualified type of container.
- Returns:
std::string “Dense”
-
static inline constexpr std::size_t size()
The size of the registers vector.
-
static inline constexpr std::size_t max_size()
The size of the registers vector.
-
static inline constexpr std::size_t embedding_size()
The size of the embedding. Equal to max_size()
-
static inline constexpr std::size_t reg_size()
The number of bytes used by each register.
Friends
-
inline friend void swap(self_type &lhs, self_type &rhs)
Swap two Dense containers.
- Parameters:
lhs – The left-hand container.
rhs – The right-hand container.
- inline friend constexpr friend self_type operator+ (self_type lhs, const self_type &rhs)
Merge two Dense containers.
- Parameters:
lhs – The left-hand container.
rhs – The right-hand container.
- Returns:
self_type The merge of the two container objects.
-
inline friend constexpr bool operator==(const self_type &lhs, const self_type &rhs)
Checks equality between two Dense containers.
- Parameters:
lhs – The left-hand container.
rhs – The right-hand container.
- Returns:
true The registers agree.
- Returns:
false At least one register disagrees.
-
inline friend constexpr bool operator!=(const self_type &lhs, const self_type &rhs)
CHecks inequality between two Dense containers.
- Parameters:
lhs – The left-hand container.
rhs – The right-hand container.
- Returns:
true At least one register disagrees.
- Returns:
false The registers agree.
-
inline friend std::ostream &operator<<(std::ostream &os, const self_type &sk)
Serialize a Dense container to human-readable output stream.
Output format is a space-delmined list of (key, value) pairs.
Note
Intended for debugging only.
- Parameters:
os – The output stream.
sk – The Dense object.
- Returns:
std::ostream& The new stream state.
-
template<typename RetType>
inline friend RetType accumulate(const self_type &sk, const RetType init) Accumulate sum of register values.
- Template Parameters:
RetType – The value type to return.
- Parameters:
sk – The Dense to accumulate.
init – Initial value of return.
- Returns:
RetType The sum over all register values +
init.