Function group_by

Summary

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

(1) template <typename T>
    Base & group_by(uint64_t(*rank)(flecs::world_t *, flecs::table_t *table, flecs::id_t id, void *ctx))

(2) Base & group_by(flecs::entity_t component, uint64_t(*rank)(flecs::world_t *, flecs::table_t *table, flecs::id_t id, void *ctx))

Function overload

Synopsis

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

template <typename T>
Base & group_by(uint64_t(*rank)(flecs::world_t *, flecs::table_t *table, flecs::id_t id, void *ctx))

Description

Group and sort matched tables. Similar yo ecs_query_order_by, but instead of sorting individual entities, this operation only sorts matched tables. This can be useful of a query needs to enforce a certain iteration order upon the tables it is iterating, for example by giving a certain component or tag a higher priority.

The sorting function assigns a "rank" to each type, which is then used to sort the tables. Tables with higher ranks will appear later in the iteration.

Resorting happens when a query iterator is obtained, and only if the set of matched tables for a query has changed. If table sorting is enabled together with entity sorting, table sorting takes precedence, and entities will be sorted within each set of tables that are assigned the same rank.

Template Parameters

T - The component used to determine the group rank.

Parameters

rank - The rank action.

Mentioned in

Source

Lines 75-79 in include/flecs/addons/cpp/mixins/query/builder_i.hpp.

template <typename T>
Base& group_by(uint64_t(*rank)(flecs::world_t*, flecs::table_t *table, flecs::id_t id, void* ctx)) {
    ecs_group_by_action_t rnk = reinterpret_cast<ecs_group_by_action_t>(rank);
    return this->group_by(_::cpp_type<T>::id(this->world_v()), rnk);
}

Synopsis

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

Base & group_by(flecs::entity_t component, uint64_t(*rank)(flecs::world_t *, flecs::table_t *table, flecs::id_t id, void *ctx))

Description

Group and sort matched tables. Same as group_by<T>, but with component identifier.

Parameters

component - The component used to determine the group rank.

rank - The rank action.

Mentioned in

Source

Lines 87-91 in include/flecs/addons/cpp/mixins/query/builder_i.hpp.

Base& group_by(flecs::entity_t component, uint64_t(*rank)(flecs::world_t*, flecs::table_t *table, flecs::id_t id, void* ctx)) {
    m_desc->group_by = reinterpret_cast<ecs_group_by_action_t>(rank);
    m_desc->group_by_id = component;
    return *this;
}