Function ecs_search_offset


#include <include/flecs.h>

FLECS_API int32_t ecs_search_offset(const ecs_world_t *world, const ecs_table_t *table, int32_t offset, ecs_id_t id, ecs_id_t *id_out)


Search for component id in table type starting from an offset. This operation is the same as ecs_search, but starts searching from an offset in the table type.

This operation is typically called in a loop where the resulting index is used in the next iteration as offset:

int32_t index = -1; while ((index = ecs_search_offset(world, table, offset, id, NULL))) { // do stuff }

Depending on how the operation is used it is either linear or constant time. When the id has the form (id) or (rel, *) and the operation is invoked as in the above example, it is guaranteed to be constant time.

If the provided id has the form (*, tgt) the operation takes linear time. The reason for this is that ids for an target are not packed together, as they are sorted relationship first.

If the id at the offset does not match the provided id, the operation will do a linear search to find a matching id.


world - The world.

table - The table.

offset - Offset from where to start searching.

id - The id to search for.

id_out - If provided, it will be set to the found id (optional).

The index of the id in the table type.

Mentioned in


Line 4494 in include/flecs.h.