6#include "GaudiKernel/MsgStream.h"
21template<
class SetA,
class SetB,
typename Compare = std::less<>>
23share_element(SetA&& setA, SetB&& setB, Compare comp = Compare{}){
24 auto xA = setA.begin();
25 auto xB = setB.begin();
26 while (xA != setA.end() && xB != setB.end()){
29 }
else if (
comp(*xB, *xA)) {
44 if (--indices)
return std::bit_width(indices);
59 if (v.size()==1)
return 0;
65 auto it = std::ranges::find(v, value);
66 if (it != v.end())
return std::distance(v.begin(), it);
79 return (std::ranges::find(v, value)!=v.end());
96 set(minimum, maximum);
110 previous = current - 1;
126 previous = current - 1;
133 previous = values.back();
144 previous = values[
index];
175 if ((
index == values.size() - 1) || (
index == 0 && current != values.front())) {
177 next = values.front();
188 next = values[
index];
197 if (
m_empty or other.m_empty)
return true;
203 if (
isBounded() and other.isEnumerated() ){
205 for (
const auto & v:
ev) {
211 for (
const auto & v:
ev){
212 if ((v >= other.m_minimum) and (v <= other.m_maximum))
return (
true);
218 return share_element(
get_values(), other.get_values());
240 if (minimum == maximum) {
259 if (std::ranges::binary_search(*p, value))
return;
261 std::ranges::sort(*p);
278 std::ranges::sort (*p);
328 set(other.get_values ());
345IdentifierField::operator std::string ()
const {
350 const auto & [minimum, maximum] =
get_minmax();
351 if (minimum == maximum) {
352 result = std::to_string(minimum);
362 result = std::format(
"{}:{}", minimum, maximum);
364 catch (
const std::format_error& e) {
377 if (
m_data != other.m_data)
return false;
394 out <<
"indices " <<
m_size <<
" ";
396 out <<
"next " <<
m_next <<
" ";
401 out <<
"both_bounded ";
403 out <<
"enumerated ";
414 out <<
"has_previous ";
420 out <<
"has_wrap_around ";
428 std::ostringstream os;
470 m_indexes = std::vector<size_type>(size, 0);
473 auto &v = std::get<element_vector>(
m_data);
474 for (
const auto & thisValue: v) {
475 if (
const auto idx=(thisValue -
m_minimum); idx < (int)size) {
479 std::cout <<
"size, value, index, i "
480 << size <<
" " << thisValue <<
" "
481 <<
index <<
" " << i++ <<
" min, max "
500 while (std::isspace(is.peek())){is.ignore();}
506 if (c ==
'+') is.ignore();
512 std::vector<int>
vec(1,v);
514 vec.insert(
vec.end(), restOfList.begin(), restOfList.end());
516 }
else if (c ==
':'){
527 std::string
msg{
"Stream extraction for IdentifierField: "};
531 throw std::invalid_argument(
msg);
std::vector< size_t > vec
std::ostream & operator<<(std::ostream &out, const IdentifierField &c)
std::istream & operator>>(std::istream &is, IdentifierField &idf)
boost::container::small_vector< element_type, 12 >::size_type size_type
This is the individual specification for the range of one ExpandedIdentifier IdentifierField.
ExpandedIdentifier::size_type size_type
bool operator==(const IdentifierField &other) const
static constexpr auto minimum_possible
IdentifierField()=default
Create a wild-card value.
size_type get_indices() const
std::pair< element_type, element_type > BoundedRange
void show(std::ostream &out) const
void set_previous(int previous)
bool get_previous(element_type current, element_type &previous) const
Returns false if previous/next is at end of range, or not possible.
void add_value(element_type value)
void set(element_type minimum, element_type maximum)
static constexpr auto maximum_possible
bool overlaps_with(const IdentifierField &other) const
Check whether two IdentifierFields overlap (Are there any values which satisfy the constraints of bot...
std::vector< element_type > element_vector
std::pair< element_type, element_type > get_minmax() const
continuation_mode m_continuation_mode
bool check_for_both_bounded()
Check mode - switch from enumerated to both_bounded if possible.
size_type get_value_index(element_type value) const
bool isEnumerated() const
void operator|=(const IdentifierField &other)
Find the union of two fields.
void optimize()
Optimize - try to switch mode to both_bounded, set up lookup table for finding index from value.
bool get_next(element_type current, element_type &next) const
ExpandedIdentifier::element_type element_type
void create_index_table()
Create index table from value table.
bool match(element_type value) const
The basic match operation Given a value, test to see if it satisfies the constraints for this field.
static constexpr int m_maxNumberOfIndices
element_type get_value_at(size_type index) const
const element_vector & get_values() const
size_type get_bits() const
Return the number of bits needed to store a value of this field.
std::variant< element_vector, BoundedRange > m_data
bool isDigit(const char c)
IdentifierField::element_type parseStreamDigits(std::istream &is)
IdentifierField::element_vector parseStreamList(std::istream &is)
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.