Flecs: Table sorting
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.1 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
Table sorting
C API » Macro API

Convenience macros for sorting tables. More...

Collaboration diagram for Table sorting:

## Macros
#define | ecs_sort_table(id)
| Declare a table sort function.
#define | ecs_compare(id)
| Declare a comparison function.
#define | ECS_SORT_TABLE_WITH_COMPARE(id, op_name, compare_fn, ...)
| Declare an efficient table sorting operation that uses the provided compare function.
#define | ECS_SORT_TABLE(id, ...)
| Declare an efficient table sorting operation that uses the default component comparison operator.
#define | ECS_COMPARE(id, ...)
| Declare component comparison operations.

## Detailed Description

Convenience macros for sorting tables.

## Macro Definition Documentation

## ◆ ECS_COMPARE

#define ECS_COMPARE | ( |  | id,
|  |  | ... )

Value:
int ecs_compare(id)(ecs_entity_t e1, const void* ptr1, ecs_entity_t e2, const void* ptr2) { \
__VA_ARGS__ \
}
ecs_entity_t
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:381
ecs_compare
#define ecs_compare(id)
Declare a comparison function.
Definition flecs_c.h:799

Declare component comparison operations.

Parameters: ecs_entity_t e1, const void* ptr1, ecs_entity_t e2, const void* ptr2 Example:

ECS_COMPARE(MyType, { const MyType* p1 = ptr1; const MyType* p2 = ptr2; return p1->value - p2->value; });
ECS_COMPARE
#define ECS_COMPARE(id,...)
Declare component comparison operations.
Definition flecs_c.h:907

Definition at line 907 of file flecs_c.h.

## ◆ ecs_compare

#define ecs_compare | ( |  | id | ) |

Value:
ecs_id(id##_compare_fn)
ecs_id
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.

Declare a comparison function.

Definition at line 799 of file flecs_c.h.

## ◆ ECS_SORT_TABLE

#define ECS_SORT_TABLE | ( |  | id,
|  |  | ... )

Value:
ECS_SORT_TABLE_WITH_COMPARE(id, ecs_sort_table(id), ecs_compare(id), __VA_ARGS__)
ecs_sort_table
#define ecs_sort_table(id)
Declare a table sort function.
Definition flecs_c.h:796
ECS_SORT_TABLE_WITH_COMPARE
#define ECS_SORT_TABLE_WITH_COMPARE(id, op_name, compare_fn,...)
Declare an efficient table sorting operation that uses the provided compare function.
Definition flecs_c.h:824

Declare an efficient table sorting operation that uses the default component comparison operator.

For best results, use LTO or make the comparison operator visible in the same compilation unit. Variadic arguments are prepended before generated functions; use them to declare static or exported functions. Example:

ECS_COMPARE(MyType, { const MyType* p1 = ptr1; const MyType* p2 = ptr2; return p1->value - p2->value; });
ECS_SORT_TABLE(MyType)
ECS_SORT_TABLE
#define ECS_SORT_TABLE(id,...)
Declare an efficient table sorting operation that uses the default component comparison operator.
Definition flecs_c.h:894

Definition at line 894 of file flecs_c.h.

## ◆ ecs_sort_table

#define ecs_sort_table | ( |  | id | ) |

Value:
ecs_id(id##_sort_table)

Declare a table sort function.

Definition at line 796 of file flecs_c.h.

## ◆ ECS_SORT_TABLE_WITH_COMPARE

#define ECS_SORT_TABLE_WITH_COMPARE | ( |  | id,
|  |  | op_name,
|  |  | compare_fn,
|  |  | ... )

Declare an efficient table sorting operation that uses the provided compare function.

For best results, use LTO or make the function body visible in the same compilation unit. Variadic arguments are prepended before generated functions; use them to declare static or exported functions. Parameters of the comparison function: ecs_entity_t e1, const void* ptr1, ecs_entity_t e2, const void* ptr2 Parameters of the sort functions: ecs_world_t *world ecs_table_t *table ecs_entity_t *entities void *ptr int32_t elem_size int32_t lo int32_t hi ecs_order_by_action_t order_by - Pointer to the original comparison function. You are not supposed to use it. Example:

int CompareMyType(ecs_entity_t e1, const void* ptr1, ecs_entity_t e2, const void* ptr2) { const MyType* p1 = ptr1; const MyType* p2 = ptr2; return p1->value - p2->value; }
ECS_SORT_TABLE_WITH_COMPARE(MyType, MyCustomCompare, CompareMyType)

Definition at line 824 of file flecs_c.h.