19#ifndef ESPRESSO_BONDLIST_HPP
20#define ESPRESSO_BONDLIST_HPP
25#include <boost/container/vector.hpp>
26#include <boost/iterator/iterator_facade.hpp>
27#include <boost/range/algorithm/copy.hpp>
28#include <boost/serialization/access.hpp>
29#include <boost/serialization/array.hpp>
30#include <boost/version.hpp>
53 : m_id(id), m_partners(partners) {}
59 return m_id == rhs.m_id and boost::equal(m_partners, rhs.m_partners);
90 using storage_iterator = storage_type::const_iterator;
98 static storage_iterator find_end(storage_iterator it) {
107 friend boost::serialization::access;
108 template <
class Archive>
void serialize(Archive &ar,
long int ) {
109 if (Archive::is_loading::value) {
112 m_storage.resize(
size);
115 if (Archive::is_saving::value) {
116 auto size = m_storage.size();
120 ar &boost::serialization::make_array(m_storage.data(), m_storage.size());
125 :
public boost::iterator_facade<Iterator, BondView,
126 boost::forward_traversal_tag, BondView> {
128 explicit Iterator(storage_iterator it) : m_it(it) {}
132 storage_iterator m_it;
135 friend boost::iterator_core_access;
136 void increment() { m_it = std::next(find_end(m_it)); }
137 bool equal(Iterator
const &other)
const {
return this->m_it == other.m_it; }
139 auto const id_pos = find_end(m_it);
140 auto const partners_begin = m_it;
141 auto const partners_end = id_pos;
142 auto const dist = std::distance(partners_begin, partners_end);
150 using reference = std::add_lvalue_reference_t<BondView>;
161 if (
this != std::addressof(rhs)) {
162 m_storage = rhs.m_storage;
169 if (
this != std::addressof(rhs)) {
170 std::swap(m_storage, rhs.m_storage);
191 boost::copy(bond.
partner_ids(), std::back_inserter(m_storage));
193 m_storage.push_back(-(bond.
bond_id() + 1));
202 return Iterator{m_storage.erase(
pos.m_it, std::next(find_end(
pos.m_it)))};
221 bool empty()
const {
return m_storage.empty(); }
227 swap(lhs.m_storage, rhs.m_storage);
242 return (bond.bond_id() == bond_id) and
243 (bond.partner_ids()[0] == partner_id);
bool pair_bond_exists_on(BondList const &bonds, int partner_id, int bond_id)
Check if there is a specific bond in a bond list.
__shared__ int pos[MAXDEPTH *THREADS5/WARPSIZE]
Iterator(storage_iterator it)
BondList(BondList const &)=default
const_iterator erase(const_iterator pos)
Erase a bond from the list.
BondList(BondList &&)=default
BondList & operator=(BondList const &rhs)
friend void swap(BondList &lhs, BondList &rhs)
const_iterator begin() const
Iterator to the beginning of the range of bonds in the list.
std::add_const_t< reference > const_reference
Utils::compact_vector< int > storage_type
void insert(BondView const &bond)
Add a bond to the list.
auto size() const
Number of bonds.
std::ptrdiff_t difference_type
void clear()
Erase all bonds from the list.
const_iterator end() const
Iterator past the end of the range of bonds in the list.
bool empty() const
Check if the are any bonds in the list.
std::add_lvalue_reference_t< BondView > reference
BondList & operator=(BondList &&rhs) noexcept
Immutable view on a bond.
BondView(int id, Utils::Span< const int > partners)
bool operator!=(BondView const &rhs) const
bool operator==(BondView const &rhs) const
Utils::Span< const int > const & partner_ids() const
A stripped-down version of std::span from C++17.
DEVICE_QUALIFIER constexpr Span< T > make_span(T *p, std::size_t N)