Function order_by

Summary

#include <include/flecs/addons/cpp/mixins/query/builder_i.hpp>

(1) template <typename T>
    Base & order_by(int(*compare)(flecs::entity_t, const T *, flecs::entity_t, const T *))

(2) Base & order_by(flecs::entity_t component, int(*compare)(flecs::entity_t, const void *, flecs::entity_t, const void *))

Function overload

Synopsis

#include <include/flecs/addons/cpp/mixins/query/builder_i.hpp>

template <typename T>
Base & order_by(int(*compare)(flecs::entity_t, const T *, flecs::entity_t, const T *))

Description

Sort the output of a query. This enables sorting of entities across matched tables. As a result of this operation, the order of entities in the matched tables may be changed. Resorting happens when a query iterator is obtained, and only if the table data has changed.

If multiple queries that match the same (down)set of tables specify different sorting functions, resorting is likely to happen every time an iterator is obtained, which can significantly slow down iterations.

The sorting function will be applied to the specified component. Resorting only happens if that component has changed, or when the entity order in the table has changed. If no component is provided, resorting only happens when the entity order changes.

Template Parameters

T - The component used to sort.

Parameters

compare - The compare function used to sort the components.

Mentioned in

Source

Lines 40-44 in include/flecs/addons/cpp/mixins/query/builder_i.hpp.

template <typename T>
Base& order_by(int(*compare)(flecs::entity_t, const T*, flecs::entity_t, const T*)) {
    ecs_order_by_action_t cmp = reinterpret_cast<ecs_order_by_action_t>(compare);
    return this->order_by(_::cpp_type<T>::id(this->world_v()), cmp);
}

Synopsis

#include <include/flecs/addons/cpp/mixins/query/builder_i.hpp>

Base & order_by(flecs::entity_t component, int(*compare)(flecs::entity_t, const void *, flecs::entity_t, const void *))

Description

Sort the output of a query. Same as order_by<T>, but with component identifier.

Parameters

component - The component used to sort.

compare - The compare function used to sort the components.

Mentioned in

Source

Lines 52-56 in include/flecs/addons/cpp/mixins/query/builder_i.hpp.

Base& order_by(flecs::entity_t component, int(*compare)(flecs::entity_t, const void*, flecs::entity_t, const void*)) {
    m_desc->order_by = reinterpret_cast<ecs_order_by_action_t>(compare);
    m_desc->order_by_component = component;
    return *this;
}