HPCombi
High Performance Combinatorics in C++ using vector instructions v1.0.0
Loading...
Searching...
No Matches
vect16.hpp
Go to the documentation of this file.
1//****************************************************************************//
2// Copyright (C) 2016-2024 Florent Hivert <Florent.Hivert@lisn.fr>, //
3// //
4// This file is part of HP-Combi <https://github.com/libsemigroups/HPCombi> //
5// //
6// HP-Combi is free software: you can redistribute it and/or modify it //
7// under the terms of the GNU General Public License as published by the //
8// Free Software Foundation, either version 3 of the License, or //
9// (at your option) any later version. //
10// //
11// HP-Combi is distributed in the hope that it will be useful, but WITHOUT //
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or //
13// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License //
14// for more details. //
15// //
16// You should have received a copy of the GNU General Public License along //
17// with HP-Combi. If not, see <https://www.gnu.org/licenses/>. //
18//****************************************************************************//
19
20#ifndef HPCOMBI_VECT16_HPP_
21#define HPCOMBI_VECT16_HPP_
22
23#include <cstddef> // for size_t
24#include <cstdint> // for uint8_t, uint64_t, int8_t
25#include <initializer_list> // for initializer_list
26#include <iosfwd> // for ostream
27#include <memory> // for hash
28#include <type_traits> // for is_trivial
29
30#include "epu8.hpp"
31
32namespace HPCombi {
33
34struct alignas(16) Vect16 {
35 static constexpr size_t size() { return 16; }
36 using array = typename decltype(Epu8)::array;
38
39 Vect16() = default;
40 constexpr Vect16(epu8 x) : v(x) {}
41 Vect16(std::initializer_list<uint8_t> il, uint8_t def = 0)
42 : v(Epu8(il, def)) {}
43 constexpr operator epu8() const { return v; }
44
46 const array &as_array() const { return HPCombi::as_array(v); }
47
48 const uint8_t &operator[](uint64_t i) const { return as_array()[i]; }
49 uint8_t &operator[](uint64_t i) { return as_array()[i]; }
50
51 size_t first_diff(const Vect16 &u, size_t bound = size()) const {
52 return HPCombi::first_diff(v, u.v, bound);
53 }
54 size_t last_diff(const Vect16 &u, size_t bound = size()) const {
55 return HPCombi::last_diff(v, u.v, bound);
56 }
57
58 size_t first_zero(size_t bound = size()) const {
59 return HPCombi::first_zero(v, bound);
60 }
61 size_t last_zero(size_t bound = size()) const {
62 return HPCombi::last_zero(v, bound);
63 }
64 size_t first_non_zero(size_t bound = size()) const {
65 return HPCombi::first_non_zero(v, bound);
66 }
67 size_t last_non_zero(size_t bound = size()) const {
68 return HPCombi::last_non_zero(v, bound);
69 }
70
71 using value_type = uint8_t;
72 using iterator = typename array::iterator;
73 using const_iterator = typename array::const_iterator;
74
75 const_iterator cbegin() const { return as_array().begin(); }
76 const_iterator cend() const { return as_array().end(); }
77
78 iterator begin() { return as_array().begin(); }
79 iterator end() { return as_array().end(); }
80
81 const_iterator begin() const { return as_array().begin(); }
82 const_iterator end() const { return as_array().end(); }
83
84 bool operator==(const Vect16 &b) const { return HPCombi::equal(v, b.v); }
85
86 bool operator!=(const Vect16 &b) const {
87 return HPCombi::not_equal(v, b.v);
88 }
89
90 bool operator<(const Vect16 &b) const { return less(v, b.v); }
91 int8_t less_partial(const Vect16 &b, int k) const {
92 return HPCombi::less_partial(v, b.v, k);
93 }
94 Vect16 permuted(const Vect16 &b) const { return HPCombi::permuted(v, b.v); }
95 uint8_t sum() const { return HPCombi::horiz_sum(v); }
97 Vect16 eval16() const { return HPCombi::eval16(v); }
98
99 bool is_permutation() const { return HPCombi::is_permutation(v); }
100 bool is_permutation(size_t k) const {
101 return HPCombi::is_permutation(v, k);
102 }
103};
104
105static_assert(std::is_trivial<Vect16>(), "Vect16 is not a trivial class !");
106
107} // namespace HPCombi
108
109namespace std {
110
111inline std::ostream &operator<<(std::ostream &stream,
112 const HPCombi::Vect16 &ar) {
113 return operator<<(stream, ar.v);
114}
115
116template <> struct hash<HPCombi::Vect16> {
117 size_t operator()(const HPCombi::Vect16 &ar) const {
118 return std::hash<HPCombi::epu8>{}(ar.v);
119 }
120};
121
122} // namespace std
123
124#endif // HPCOMBI_VECT16_HPP_
Definition bmat8.hpp:41
uint64_t first_non_zero(epu8 v, int bnd) noexcept
return the index of the first non zero entry or 16 if there are none Only index smaller than bound ar...
Definition epu8_impl.hpp:126
epu8 permuted(epu8 a, epu8 b) noexcept
Permuting a HPCombi::epu8.
Definition epu8.hpp:72
epu8 partial_sums(epu8 v) noexcept
Horizontal partial sum of a HPCombi::epu8.
Definition epu8.hpp:246
bool is_permutation(epu8 v, const size_t k=16) noexcept
Definition epu8_impl.hpp:530
int8_t less_partial(epu8 a, epu8 b, int k) noexcept
Partial lexicographic comparison between two HPCombi::epu8.
Definition epu8_impl.hpp:113
uint64_t last_zero(epu8 v, int bnd) noexcept
return the index of the last zero entry or 16 if there are none Only index smaller than bound are tak...
Definition epu8_impl.hpp:123
bool equal(epu8 a, epu8 b) noexcept
Equality of HPCombi::epu8.
Definition epu8.hpp:63
epu8 eval16(epu8 v) noexcept
Evaluation of a HPCombi::epu8.
Definition epu8.hpp:408
uint8_t horiz_sum(epu8 v) noexcept
Horizontal sum of a HPCombi::epu8.
Definition epu8.hpp:217
bool less(epu8 a, epu8 b) noexcept
Lexicographic comparison between two HPCombi::epu8.
Definition epu8_impl.hpp:109
constexpr TPUBuild< epu8 > Epu8
Factory object acting as a class constructor for type HPCombi::epu8.
Definition epu8.hpp:53
uint64_t first_zero(epu8 v, int bnd) noexcept
return the index of the first zero entry or 16 if there are none Only index smaller than bound are ta...
Definition epu8_impl.hpp:120
uint8_t __attribute__((vector_size(16))) epu8
SIMD vector of 16 unsigned bytes.
Definition epu8.hpp:45
uint64_t last_non_zero(epu8 v, int bnd) noexcept
return the index of the last non zero entry or 16 if there are none Only index smaller than bound are...
Definition epu8_impl.hpp:129
uint64_t last_diff(epu8 a, epu8 b, size_t bound=16) noexcept
The last difference between two HPCombi::epu8.
Definition epu8.hpp:486
uint64_t first_diff(epu8 a, epu8 b, size_t bound=16) noexcept
The first difference between two HPCombi::epu8.
Definition epu8.hpp:446
TPUBuild< TPU >::array & as_array(TPU &v) noexcept
Cast a TPU to a c++ std::array.
Definition builder.hpp:139
bool not_equal(epu8 a, epu8 b) noexcept
Non equality of HPCombi::epu8.
Definition epu8.hpp:67
Definition bmat8.hpp:364
std::ostream & operator<<(std::ostream &os, HPCombi::BMat8 const &bm)
Definition bmat8_impl.hpp:508
Definition vect16.hpp:34
bool operator==(const Vect16 &b) const
Definition vect16.hpp:84
const_iterator begin() const
Definition vect16.hpp:81
iterator end()
Definition vect16.hpp:79
Vect16(std::initializer_list< uint8_t > il, uint8_t def=0)
Definition vect16.hpp:41
size_t last_diff(const Vect16 &u, size_t bound=size()) const
Definition vect16.hpp:54
size_t first_zero(size_t bound=size()) const
Definition vect16.hpp:58
typename array::const_iterator const_iterator
Definition vect16.hpp:73
const_iterator end() const
Definition vect16.hpp:82
int8_t less_partial(const Vect16 &b, int k) const
Definition vect16.hpp:91
size_t last_zero(size_t bound=size()) const
Definition vect16.hpp:61
uint8_t & operator[](uint64_t i)
Definition vect16.hpp:49
bool is_permutation() const
Definition vect16.hpp:99
bool operator<(const Vect16 &b) const
Definition vect16.hpp:90
const_iterator cbegin() const
Definition vect16.hpp:75
static constexpr size_t size()
Definition vect16.hpp:35
Vect16()=default
size_t first_non_zero(size_t bound=size()) const
Definition vect16.hpp:64
typename decltype(Epu8)::array array
Definition vect16.hpp:36
array & as_array()
Definition vect16.hpp:45
size_t first_diff(const Vect16 &u, size_t bound=size()) const
Definition vect16.hpp:51
iterator begin()
Definition vect16.hpp:78
bool is_permutation(size_t k) const
Definition vect16.hpp:100
epu8 v
Definition vect16.hpp:37
uint8_t value_type
Definition vect16.hpp:71
const uint8_t & operator[](uint64_t i) const
Definition vect16.hpp:48
const array & as_array() const
Definition vect16.hpp:46
bool operator!=(const Vect16 &b) const
Definition vect16.hpp:86
uint8_t sum() const
Definition vect16.hpp:95
size_t last_non_zero(size_t bound=size()) const
Definition vect16.hpp:67
Vect16 permuted(const Vect16 &b) const
Definition vect16.hpp:94
constexpr Vect16(epu8 x)
Definition vect16.hpp:40
Vect16 eval16() const
Definition vect16.hpp:97
Vect16 partial_sums() const
Definition vect16.hpp:96
const_iterator cend() const
Definition vect16.hpp:76
typename array::iterator iterator
Definition vect16.hpp:72
size_t operator()(const HPCombi::Vect16 &ar) const
Definition vect16.hpp:117