Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions FunRootAna/LazyFunctionalVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class FunctionalInterface {
// the implementation is suboptimal, that is, it involves inexed access to one of the containers, it is therefore better if one of them is staged
template<typename Other>
auto zip(const Other& c) const {
static_assert(Container::is_finite or Other::is_finite, "Can't combine infinite containers");
// static_assert(Container::is_finite or Other::is_finite, "Can't combine infinite containers");
return ZipView<Container, Other>(m_actual_container, c);
}

Expand Down Expand Up @@ -937,7 +937,7 @@ class ZipView : public FunctionalInterface<ZipView<Container1, Container2>, type
static constexpr bool is_permanent = Container1::is_permanent && Container2::is_permanent;
static constexpr bool is_finite = Container1::is_finite or Container2::is_finite;

static_assert(details::has_fast_element_access_tag<Container1>::value or details::has_fast_element_access_tag<Container2>::value, "At least one container needs to to provide fast element access, consider calling stage() ");
// static_assert(details::has_fast_element_access_tag<Container1>::value or details::has_fast_element_access_tag<Container2>::value, "At least one container needs to to provide fast element access, consider calling stage() ");

ZipView(const Container1& c1, const Container2& c2)
: interface(*this),
Expand All @@ -947,7 +947,7 @@ class ZipView : public FunctionalInterface<ZipView<Container1, Container2>, type
template<typename F>
void foreach_imp(F f, details::foreach_instructions how = {}) const {
size_t index = 0;
if (details::has_fast_element_access_tag<Container2>::value) {
if constexpr (details::has_fast_element_access_tag<Container2>::value) {
m_foreach_imp_provider1.foreach_imp([f, &index, this](typename Container1::argument_type el1) {
auto el2_option = m_foreach_imp_provider2.element_at(index);
if (el2_option.has_value() == false) // reached end of container 2
Expand All @@ -959,7 +959,8 @@ class ZipView : public FunctionalInterface<ZipView<Container1, Container2>, type
return true;
}, how);
}
else {
// - Pierwszy kontener ma szybki dostęp
else if constexpr (details::has_fast_element_access_tag<Container1>::value) {
m_foreach_imp_provider2.foreach_imp([f, &index, this](typename Container2::argument_type el2) {
auto el1_option = m_foreach_imp_provider1.element_at(index);
if (el1_option.has_value() == false)
Expand All @@ -970,6 +971,28 @@ class ZipView : public FunctionalInterface<ZipView<Container1, Container2>, type
index++;
return true;
}, how);
}
// - Oba to strumienie
// Posiadają metodę get_generator() (jak klasa Series)
else {
auto gen1 = m_foreach_imp_provider1.get_generator();
auto gen2 = m_foreach_imp_provider2.get_generator();

while (true) {
auto val1 = gen1();
auto val2 = gen2();

// Jeśli którykolwiek strumień się wyczerpał => stop
if (!val1.has_value() || !val2.has_value()) {
break;
}

// Wywołanie funkcji użytkownika na obydwu wartościach
const bool go = f(std::make_pair(val1.value(), val2.value()));
if (!go) {
break;
}
}
}
}
private:
Expand Down Expand Up @@ -1196,6 +1219,17 @@ class Series : public FunctionalInterface<Series<T>, T > {
m_start(start),
m_stop(stop) {}

auto get_generator() const {
// Zwraca lambdę, która trzyma stan iteracji
return [gen = m_generator, current = m_start, stop = m_stop]() mutable -> std::optional<T> {
if (current >= stop) return {}; // Koniec strumienia

T val = current;
current = gen(current); // Obliczenia następnego stanu
return val;
};
}

template<typename F>
void foreach_imp(F f, details::foreach_instructions = {}) const {
T current = m_start;
Expand Down Expand Up @@ -1445,4 +1479,4 @@ class AccessView : public lfv::FunctionalInterface<AccessView<AccessDerivative>,
std::reference_wrapper<AccessDerivative> m_access;

};
#endif
#endif