C API

Event windows guide

Keep the last events or groups of facts, expire them explicitly and compare the resulting answers.

The Event windows reference describes the types and calls in <maelys/datalog_window.h>.

An event window borrows two idle sessions and uses memory supplied by the caller. Keep a bounded history of accepted events, then query the policy against the facts that remain: use a single-fact window for generated occurrence IDs, or a group window for events containing several complete facts.

Event windows are available from C only in v0.26.0; the Python and TypeScript bindings do not expose them.

1. Create a window in caller-owned memory

The context creates two distinct idle sessions for this single-fact window. It lends both sessions to the window until release: do not solve with them, share them, or free them while the window is open. Initialize every options field by name; there is no window-options _INIT macro. The four static slots are reserved for complete facts supplied through window_replace_static(), independently of the two event slots. This example leaves those static slots empty. Measure storage at run time, allocate it, then initialize the window. Keep the memory alive and at the same address until release.

Example
CODE
const maelys_datalog_window_options_t options = {
    .struct_size = sizeof(maelys_datalog_window_options_t),
    .static_fact_capacity = 4,
    .flags = MAELYS_DATALOG_WINDOW_EXPIRATION
};
size_t bytes = 0, alignment = 0;
maelys_datalog_status_t status = maelys_datalog_window_storage_requirements_configured(
    event_capacity, text_capacity, &options, &bytes, &alignment);
printf("storage planning status: %s\n", maelys_datalog_status_name(status));
check_status(status);
window_storage = malloc(bytes);
check_storage(window_storage, alignment);
status = maelys_datalog_window_init_configured(window_storage, bytes,
    event_capacity, text_capacity, &options, 0, sessions[0], sessions[1], &window, &diagnostic);
printf("window initialization status: %s\n", maelys_datalog_status_name(status));
check_status(status);
storage planning status: ok
window initialization status: ok
Reference context · step 1
CODE
/* Common C reference declarations; concatenated before the page extension. */
#include <maelys/datalog.h>
#include <maelys/datalog_builders.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>

/* The page extension owns cleanup; no constructor is hidden in the runner. */
static void cleanup_context(void);
static int cleanup_failed = 0;

static void check_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        fprintf(stderr, "API call failed: %s\n", maelys_datalog_status_name(status));
        exit(EXIT_FAILURE);
    }
}

/* Label each output line without changing the text buffer. */
static void print_text_lines(const char *label, const char *text) {
    while (*text != '\0') {
        const char *end = strchr(text, '\n');
        printf("%s: ", label);
        fwrite(text, 1, end ? (size_t)(end - text) : strlen(text), stdout);
        putchar('\n');
        if (end == NULL) break;
        text = end + 1;
    }
}

/* Cleanup failures must not recursively invoke check_status. */
static void cleanup_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        cleanup_failed = 1;
        fprintf(stderr, "Context cleanup failed: %s\n", maelys_datalog_status_name(status));
    }
}

/* Event windows borrow two idle sessions; each adapter has its own pair. */
#include <maelys/datalog_window.h>
#include <stdint.h>
#include <inttypes.h>

static maelys_datalog_policy_t *policy = NULL;
static maelys_datalog_session_t *sessions[4] = { NULL, NULL, NULL, NULL };
static maelys_datalog_window_t *window = NULL;
static maelys_datalog_group_window_t *group_window = NULL;
static void *window_storage = NULL, *group_storage = NULL;
static const size_t event_capacity = 2, text_capacity = 512;
static const maelys_datalog_group_window_capacities_t capacities = { 2, 8, 8, 512 };
static const maelys_datalog_value_t terms[] = {
    MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf")
};
static const maelys_datalog_fact_t facts[] = {
    { "owns", 2, { MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf") } },
    { "blocked", 1, { MAELYS_DATALOG_SYMBOL("mallory") } }
};
static const maelys_datalog_fact_t static_facts[] = {
    { "user", 1, { MAELYS_DATALOG_SYMBOL("alice") } }
};
static void cleanup_context(void) {
    if (window != NULL) {
        maelys_datalog_status_t status = maelys_datalog_window_free(window);
        cleanup_status(status);
        if (status != MAELYS_DATALOG_STATUS_OK) return;
        window = NULL;
    }
    if (group_window != NULL) {
        maelys_datalog_status_t status = maelys_datalog_group_window_free(group_window);
        cleanup_status(status);
        if (status != MAELYS_DATALOG_STATUS_OK) return;
        group_window = NULL;
    }
    for (size_t i = 0; i < 4; ++i) {
        if (sessions[i] != NULL) { cleanup_status(maelys_datalog_session_free(sessions[i])); sessions[i] = NULL; }
    }
    free(window_storage); window_storage = NULL;
    free(group_storage); group_storage = NULL;
    if (policy != NULL) { cleanup_status(maelys_datalog_policy_free(policy)); policy = NULL; }
}
static void check_storage(void *storage, size_t alignment) {
    if (storage == NULL || alignment == 0 || (uintptr_t)storage % alignment != 0) {
        fputs("Storage allocation failed\n", stderr); exit(EXIT_FAILURE);
    }
}
static void create_group_window(const maelys_datalog_window_options_t *options) {
    size_t bytes = 0, alignment = 0;
    check_status(maelys_datalog_group_window_storage_requirements_configured(
        &capacities, options, &bytes, &alignment));
    group_storage = malloc(bytes);
    check_storage(group_storage, alignment);
    check_status(maelys_datalog_group_window_init_configured(group_storage, bytes,
        &capacities, options, 0, sessions[2], sessions[3], &group_window, NULL));
}
static size_t observed_count(maelys_datalog_result_t *result) {
    maelys_datalog_fact_view_t rows[2];
    size_t count = 0;
    check_status(maelys_datalog_result_enumerate(result, "observed", 2, rows, 2, &count));
    return count;
}
static int allows_alice(maelys_datalog_result_t *result) {
    int present = 0;
    check_status(maelys_datalog_result_query(result, "allow", terms, 2, &present));
    return present;
}
int main(void) {
    if (atexit(cleanup_context) != 0) return EXIT_FAILURE;
    const maelys_datalog_predicate_t predicates[] = {
        MAELYS_DATALOG_EDB("user", 1), MAELYS_DATALOG_EDB("owns", 2),
        MAELYS_DATALOG_EDB("blocked", 1), MAELYS_DATALOG_EDB("access", 3),
        MAELYS_DATALOG_IDB_QUERY("allow", 2), MAELYS_DATALOG_IDB_QUERY("observed", 2)
    };
    const maelys_datalog_domain_t domain = MAELYS_DATALOG_DOMAIN_NO_ATOMS("documents", predicates);
    check_status(maelys_datalog_domain_register(&domain));
    const char *source = "allow(User, Doc) :- owns(User, Doc), not(blocked(User)).\n"
        "observed(User, Doc) :- access(Occurrence, User, Doc).";
    maelys_datalog_diagnostic_t diagnostic = MAELYS_DATALOG_DIAGNOSTIC_INIT;
    check_status(maelys_datalog_policy_load_inline("documents", "event-windows-context",
        source, strlen(source), &policy, &diagnostic));
    for (size_t i = 0; i < 4; ++i) check_status(maelys_datalog_session_create(policy, 0, &sessions[i]));
    {
        /* API_REFERENCE_EXAMPLE */
    }
    cleanup_context();
    if (cleanup_failed) return EXIT_FAILURE;
    return EXIT_SUCCESS;
}

2. Keep the last N accepted events

The single-fact window keeps arrival order and adds a generated occurrence ID before the supplied terms. The starting ID above is zero. With room for two events, three accepted pushes retain IDs 1 and 2, so the oldest retained occurrence is 1. The policy projects the user and document terms into observed pairs: these two events have the same payload and produce one distinct observed pair.

Example
CODE
for (size_t i = 0; i < 3; ++i) {
    status = maelys_datalog_window_push(window, "access", terms, 2, NULL, &diagnostic);
    printf("event push status: %s\n", maelys_datalog_status_name(status));
    check_status(status);
}
const maelys_datalog_fact_t *events = NULL;
size_t count = 0;
check_status(maelys_datalog_window_events(window, &events, &count));
printf("retained events: %zu\n", count);
printf("oldest retained occurrence: %" PRId64 "\n", events[0].terms[0].as.integer);
maelys_datalog_result_t *event_result = NULL;
check_status(maelys_datalog_window_result(window, &event_result));
printf("distinct observed pairs: %zu\n", observed_count(event_result));
event push status: ok
event push status: ok
event push status: ok
retained events: 2
oldest retained occurrence: 1
distinct observed pairs: 1
Reference context · step 2
CODE
/* Common C reference declarations; concatenated before the page extension. */
#include <maelys/datalog.h>
#include <maelys/datalog_builders.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>

/* The page extension owns cleanup; no constructor is hidden in the runner. */
static void cleanup_context(void);
static int cleanup_failed = 0;

static void check_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        fprintf(stderr, "API call failed: %s\n", maelys_datalog_status_name(status));
        exit(EXIT_FAILURE);
    }
}

/* Label each output line without changing the text buffer. */
static void print_text_lines(const char *label, const char *text) {
    while (*text != '\0') {
        const char *end = strchr(text, '\n');
        printf("%s: ", label);
        fwrite(text, 1, end ? (size_t)(end - text) : strlen(text), stdout);
        putchar('\n');
        if (end == NULL) break;
        text = end + 1;
    }
}

/* Cleanup failures must not recursively invoke check_status. */
static void cleanup_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        cleanup_failed = 1;
        fprintf(stderr, "Context cleanup failed: %s\n", maelys_datalog_status_name(status));
    }
}

/* Event windows borrow two idle sessions; each adapter has its own pair. */
#include <maelys/datalog_window.h>
#include <stdint.h>
#include <inttypes.h>

static maelys_datalog_policy_t *policy = NULL;
static maelys_datalog_session_t *sessions[4] = { NULL, NULL, NULL, NULL };
static maelys_datalog_window_t *window = NULL;
static maelys_datalog_group_window_t *group_window = NULL;
static void *window_storage = NULL, *group_storage = NULL;
static const size_t event_capacity = 2, text_capacity = 512;
static const maelys_datalog_group_window_capacities_t capacities = { 2, 8, 8, 512 };
static const maelys_datalog_value_t terms[] = {
    MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf")
};
static const maelys_datalog_fact_t facts[] = {
    { "owns", 2, { MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf") } },
    { "blocked", 1, { MAELYS_DATALOG_SYMBOL("mallory") } }
};
static const maelys_datalog_fact_t static_facts[] = {
    { "user", 1, { MAELYS_DATALOG_SYMBOL("alice") } }
};
static void cleanup_context(void) {
    if (window != NULL) {
        maelys_datalog_status_t status = maelys_datalog_window_free(window);
        cleanup_status(status);
        if (status != MAELYS_DATALOG_STATUS_OK) return;
        window = NULL;
    }
    if (group_window != NULL) {
        maelys_datalog_status_t status = maelys_datalog_group_window_free(group_window);
        cleanup_status(status);
        if (status != MAELYS_DATALOG_STATUS_OK) return;
        group_window = NULL;
    }
    for (size_t i = 0; i < 4; ++i) {
        if (sessions[i] != NULL) { cleanup_status(maelys_datalog_session_free(sessions[i])); sessions[i] = NULL; }
    }
    free(window_storage); window_storage = NULL;
    free(group_storage); group_storage = NULL;
    if (policy != NULL) { cleanup_status(maelys_datalog_policy_free(policy)); policy = NULL; }
}
static void check_storage(void *storage, size_t alignment) {
    if (storage == NULL || alignment == 0 || (uintptr_t)storage % alignment != 0) {
        fputs("Storage allocation failed\n", stderr); exit(EXIT_FAILURE);
    }
}
static void create_group_window(const maelys_datalog_window_options_t *options) {
    size_t bytes = 0, alignment = 0;
    check_status(maelys_datalog_group_window_storage_requirements_configured(
        &capacities, options, &bytes, &alignment));
    group_storage = malloc(bytes);
    check_storage(group_storage, alignment);
    check_status(maelys_datalog_group_window_init_configured(group_storage, bytes,
        &capacities, options, 0, sessions[2], sessions[3], &group_window, NULL));
}
static size_t observed_count(maelys_datalog_result_t *result) {
    maelys_datalog_fact_view_t rows[2];
    size_t count = 0;
    check_status(maelys_datalog_result_enumerate(result, "observed", 2, rows, 2, &count));
    return count;
}
static int allows_alice(maelys_datalog_result_t *result) {
    int present = 0;
    check_status(maelys_datalog_result_query(result, "allow", terms, 2, &present));
    return present;
}
int main(void) {
    if (atexit(cleanup_context) != 0) return EXIT_FAILURE;
    const maelys_datalog_predicate_t predicates[] = {
        MAELYS_DATALOG_EDB("user", 1), MAELYS_DATALOG_EDB("owns", 2),
        MAELYS_DATALOG_EDB("blocked", 1), MAELYS_DATALOG_EDB("access", 3),
        MAELYS_DATALOG_IDB_QUERY("allow", 2), MAELYS_DATALOG_IDB_QUERY("observed", 2)
    };
    const maelys_datalog_domain_t domain = MAELYS_DATALOG_DOMAIN_NO_ATOMS("documents", predicates);
    check_status(maelys_datalog_domain_register(&domain));
    const char *source = "allow(User, Doc) :- owns(User, Doc), not(blocked(User)).\n"
        "observed(User, Doc) :- access(Occurrence, User, Doc).";
    maelys_datalog_diagnostic_t diagnostic = MAELYS_DATALOG_DIAGNOSTIC_INIT;
    check_status(maelys_datalog_policy_load_inline("documents", "event-windows-context",
        source, strlen(source), &policy, &diagnostic));
    for (size_t i = 0; i < 4; ++i) check_status(maelys_datalog_session_create(policy, 0, &sessions[i]));
    {

const maelys_datalog_window_options_t options = {
    .struct_size = sizeof(maelys_datalog_window_options_t),
    .static_fact_capacity = 4,
    .flags = MAELYS_DATALOG_WINDOW_EXPIRATION
};
size_t bytes = 0, alignment = 0;
maelys_datalog_status_t status = maelys_datalog_window_storage_requirements_configured(
    event_capacity, text_capacity, &options, &bytes, &alignment);
check_status(status);
window_storage = malloc(bytes);
check_storage(window_storage, alignment);
status = maelys_datalog_window_init_configured(window_storage, bytes,
    event_capacity, text_capacity, &options, 0, sessions[0], sessions[1], &window, &diagnostic);
check_status(status);

/* API_REFERENCE_EXAMPLE */
    }
    cleanup_context();
    if (cleanup_failed) return EXIT_FAILURE;
    return EXIT_SUCCESS;
}

A group is one accepted event containing complete facts. The first group below contains owns(alice, roadmap.pdf) and blocked(mallory), with deadline 20. The second group contains blocked(alice), with deadline 10, so alice is denied access before expiration. The group window uses a separate pair of idle sessions prepared in the context. Group IDs stay in window metadata instead of being added to the facts. Equal facts supplied by several retained groups appear once in the combined input, and remain until the last supplying group is removed. Static facts can also keep a fact present independently of the groups.

Example
CODE
create_group_window(&options);
status = maelys_datalog_group_window_push_until(group_window, facts,
    sizeof(facts) / sizeof(facts[0]), 20, NULL, &diagnostic);
printf("ownership group status: %s\n", maelys_datalog_status_name(status));
check_status(status);
maelys_datalog_group_window_usage_t usage;
check_status(maelys_datalog_group_window_state(group_window, &usage));
printf("initial group contributions: %zu\n", usage.contributions);
const maelys_datalog_fact_t blocked[] = {
    { "blocked", 1, { MAELYS_DATALOG_SYMBOL("alice") } }
};
status = maelys_datalog_group_window_push_until(group_window, blocked,
    sizeof(blocked) / sizeof(blocked[0]), 10, NULL, &diagnostic);
printf("block group status: %s\n", maelys_datalog_status_name(status));
check_status(status);
maelys_datalog_result_t *result = NULL;
check_status(maelys_datalog_group_window_result(group_window, &result));
int before = allows_alice(result);
printf("access before expiration: %s\n", before ? "yes" : "no");
ownership group status: ok
initial group contributions: 2
block group status: ok
access before expiration: no
Reference context · step 3
CODE
/* Common C reference declarations; concatenated before the page extension. */
#include <maelys/datalog.h>
#include <maelys/datalog_builders.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>

/* The page extension owns cleanup; no constructor is hidden in the runner. */
static void cleanup_context(void);
static int cleanup_failed = 0;

static void check_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        fprintf(stderr, "API call failed: %s\n", maelys_datalog_status_name(status));
        exit(EXIT_FAILURE);
    }
}

/* Label each output line without changing the text buffer. */
static void print_text_lines(const char *label, const char *text) {
    while (*text != '\0') {
        const char *end = strchr(text, '\n');
        printf("%s: ", label);
        fwrite(text, 1, end ? (size_t)(end - text) : strlen(text), stdout);
        putchar('\n');
        if (end == NULL) break;
        text = end + 1;
    }
}

/* Cleanup failures must not recursively invoke check_status. */
static void cleanup_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        cleanup_failed = 1;
        fprintf(stderr, "Context cleanup failed: %s\n", maelys_datalog_status_name(status));
    }
}

/* Event windows borrow two idle sessions; each adapter has its own pair. */
#include <maelys/datalog_window.h>
#include <stdint.h>
#include <inttypes.h>

static maelys_datalog_policy_t *policy = NULL;
static maelys_datalog_session_t *sessions[4] = { NULL, NULL, NULL, NULL };
static maelys_datalog_window_t *window = NULL;
static maelys_datalog_group_window_t *group_window = NULL;
static void *window_storage = NULL, *group_storage = NULL;
static const size_t event_capacity = 2, text_capacity = 512;
static const maelys_datalog_group_window_capacities_t capacities = { 2, 8, 8, 512 };
static const maelys_datalog_value_t terms[] = {
    MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf")
};
static const maelys_datalog_fact_t facts[] = {
    { "owns", 2, { MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf") } },
    { "blocked", 1, { MAELYS_DATALOG_SYMBOL("mallory") } }
};
static const maelys_datalog_fact_t static_facts[] = {
    { "user", 1, { MAELYS_DATALOG_SYMBOL("alice") } }
};
static void cleanup_context(void) {
    if (window != NULL) {
        maelys_datalog_status_t status = maelys_datalog_window_free(window);
        cleanup_status(status);
        if (status != MAELYS_DATALOG_STATUS_OK) return;
        window = NULL;
    }
    if (group_window != NULL) {
        maelys_datalog_status_t status = maelys_datalog_group_window_free(group_window);
        cleanup_status(status);
        if (status != MAELYS_DATALOG_STATUS_OK) return;
        group_window = NULL;
    }
    for (size_t i = 0; i < 4; ++i) {
        if (sessions[i] != NULL) { cleanup_status(maelys_datalog_session_free(sessions[i])); sessions[i] = NULL; }
    }
    free(window_storage); window_storage = NULL;
    free(group_storage); group_storage = NULL;
    if (policy != NULL) { cleanup_status(maelys_datalog_policy_free(policy)); policy = NULL; }
}
static void check_storage(void *storage, size_t alignment) {
    if (storage == NULL || alignment == 0 || (uintptr_t)storage % alignment != 0) {
        fputs("Storage allocation failed\n", stderr); exit(EXIT_FAILURE);
    }
}
static void create_group_window(const maelys_datalog_window_options_t *options) {
    size_t bytes = 0, alignment = 0;
    check_status(maelys_datalog_group_window_storage_requirements_configured(
        &capacities, options, &bytes, &alignment));
    group_storage = malloc(bytes);
    check_storage(group_storage, alignment);
    check_status(maelys_datalog_group_window_init_configured(group_storage, bytes,
        &capacities, options, 0, sessions[2], sessions[3], &group_window, NULL));
}
static size_t observed_count(maelys_datalog_result_t *result) {
    maelys_datalog_fact_view_t rows[2];
    size_t count = 0;
    check_status(maelys_datalog_result_enumerate(result, "observed", 2, rows, 2, &count));
    return count;
}
static int allows_alice(maelys_datalog_result_t *result) {
    int present = 0;
    check_status(maelys_datalog_result_query(result, "allow", terms, 2, &present));
    return present;
}
int main(void) {
    if (atexit(cleanup_context) != 0) return EXIT_FAILURE;
    const maelys_datalog_predicate_t predicates[] = {
        MAELYS_DATALOG_EDB("user", 1), MAELYS_DATALOG_EDB("owns", 2),
        MAELYS_DATALOG_EDB("blocked", 1), MAELYS_DATALOG_EDB("access", 3),
        MAELYS_DATALOG_IDB_QUERY("allow", 2), MAELYS_DATALOG_IDB_QUERY("observed", 2)
    };
    const maelys_datalog_domain_t domain = MAELYS_DATALOG_DOMAIN_NO_ATOMS("documents", predicates);
    check_status(maelys_datalog_domain_register(&domain));
    const char *source = "allow(User, Doc) :- owns(User, Doc), not(blocked(User)).\n"
        "observed(User, Doc) :- access(Occurrence, User, Doc).";
    maelys_datalog_diagnostic_t diagnostic = MAELYS_DATALOG_DIAGNOSTIC_INIT;
    check_status(maelys_datalog_policy_load_inline("documents", "event-windows-context",
        source, strlen(source), &policy, &diagnostic));
    for (size_t i = 0; i < 4; ++i) check_status(maelys_datalog_session_create(policy, 0, &sessions[i]));
    {

const maelys_datalog_window_options_t options = {
    .struct_size = sizeof(maelys_datalog_window_options_t),
    .static_fact_capacity = 4,
    .flags = MAELYS_DATALOG_WINDOW_EXPIRATION
};
size_t bytes = 0, alignment = 0;
maelys_datalog_status_t status = maelys_datalog_window_storage_requirements_configured(
    event_capacity, text_capacity, &options, &bytes, &alignment);
check_status(status);
window_storage = malloc(bytes);
check_storage(window_storage, alignment);
status = maelys_datalog_window_init_configured(window_storage, bytes,
    event_capacity, text_capacity, &options, 0, sessions[0], sessions[1], &window, &diagnostic);
check_status(status);

for (size_t i = 0; i < 3; ++i) {
    status = maelys_datalog_window_push(window, "access", terms, 2, NULL, &diagnostic);
    check_status(status);
}
const maelys_datalog_fact_t *events = NULL;
size_t count = 0;
check_status(maelys_datalog_window_events(window, &events, &count));
maelys_datalog_result_t *event_result = NULL;
check_status(maelys_datalog_window_result(window, &event_result));

/* API_REFERENCE_EXAMPLE */
    }
    cleanup_context();
    if (cleanup_failed) return EXIT_FAILURE;
    return EXIT_SUCCESS;
}

4. Expire groups explicitly

Expiration uses absolute deadlines in units chosen by the application. No clock is read, and pushing a group does not advance time. group_window_expire(10) explicitly removes all timed groups whose deadlines are at or before 10, even when deadlines arrived out of order. The ownership group with deadline 20 remains; the group blocking alice with deadline 10 disappears. The supplied time must not go backwards from the last time successfully passed to group_window_expire().

Example
CODE
size_t expired = 0;
status = maelys_datalog_group_window_expire(group_window, 10, &expired, &diagnostic);
printf("expiration status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("groups expired: %zu\n", expired);
check_status(maelys_datalog_group_window_result(group_window, &result));
int after = allows_alice(result);
printf("access after expiration: %s\n", after ? "yes" : "no");
expiration status: ok
groups expired: 1
access after expiration: yes
Reference context · step 4
CODE
/* Common C reference declarations; concatenated before the page extension. */
#include <maelys/datalog.h>
#include <maelys/datalog_builders.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>

/* The page extension owns cleanup; no constructor is hidden in the runner. */
static void cleanup_context(void);
static int cleanup_failed = 0;

static void check_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        fprintf(stderr, "API call failed: %s\n", maelys_datalog_status_name(status));
        exit(EXIT_FAILURE);
    }
}

/* Label each output line without changing the text buffer. */
static void print_text_lines(const char *label, const char *text) {
    while (*text != '\0') {
        const char *end = strchr(text, '\n');
        printf("%s: ", label);
        fwrite(text, 1, end ? (size_t)(end - text) : strlen(text), stdout);
        putchar('\n');
        if (end == NULL) break;
        text = end + 1;
    }
}

/* Cleanup failures must not recursively invoke check_status. */
static void cleanup_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        cleanup_failed = 1;
        fprintf(stderr, "Context cleanup failed: %s\n", maelys_datalog_status_name(status));
    }
}

/* Event windows borrow two idle sessions; each adapter has its own pair. */
#include <maelys/datalog_window.h>
#include <stdint.h>
#include <inttypes.h>

static maelys_datalog_policy_t *policy = NULL;
static maelys_datalog_session_t *sessions[4] = { NULL, NULL, NULL, NULL };
static maelys_datalog_window_t *window = NULL;
static maelys_datalog_group_window_t *group_window = NULL;
static void *window_storage = NULL, *group_storage = NULL;
static const size_t event_capacity = 2, text_capacity = 512;
static const maelys_datalog_group_window_capacities_t capacities = { 2, 8, 8, 512 };
static const maelys_datalog_value_t terms[] = {
    MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf")
};
static const maelys_datalog_fact_t facts[] = {
    { "owns", 2, { MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf") } },
    { "blocked", 1, { MAELYS_DATALOG_SYMBOL("mallory") } }
};
static const maelys_datalog_fact_t static_facts[] = {
    { "user", 1, { MAELYS_DATALOG_SYMBOL("alice") } }
};
static void cleanup_context(void) {
    if (window != NULL) {
        maelys_datalog_status_t status = maelys_datalog_window_free(window);
        cleanup_status(status);
        if (status != MAELYS_DATALOG_STATUS_OK) return;
        window = NULL;
    }
    if (group_window != NULL) {
        maelys_datalog_status_t status = maelys_datalog_group_window_free(group_window);
        cleanup_status(status);
        if (status != MAELYS_DATALOG_STATUS_OK) return;
        group_window = NULL;
    }
    for (size_t i = 0; i < 4; ++i) {
        if (sessions[i] != NULL) { cleanup_status(maelys_datalog_session_free(sessions[i])); sessions[i] = NULL; }
    }
    free(window_storage); window_storage = NULL;
    free(group_storage); group_storage = NULL;
    if (policy != NULL) { cleanup_status(maelys_datalog_policy_free(policy)); policy = NULL; }
}
static void check_storage(void *storage, size_t alignment) {
    if (storage == NULL || alignment == 0 || (uintptr_t)storage % alignment != 0) {
        fputs("Storage allocation failed\n", stderr); exit(EXIT_FAILURE);
    }
}
static void create_group_window(const maelys_datalog_window_options_t *options) {
    size_t bytes = 0, alignment = 0;
    check_status(maelys_datalog_group_window_storage_requirements_configured(
        &capacities, options, &bytes, &alignment));
    group_storage = malloc(bytes);
    check_storage(group_storage, alignment);
    check_status(maelys_datalog_group_window_init_configured(group_storage, bytes,
        &capacities, options, 0, sessions[2], sessions[3], &group_window, NULL));
}
static size_t observed_count(maelys_datalog_result_t *result) {
    maelys_datalog_fact_view_t rows[2];
    size_t count = 0;
    check_status(maelys_datalog_result_enumerate(result, "observed", 2, rows, 2, &count));
    return count;
}
static int allows_alice(maelys_datalog_result_t *result) {
    int present = 0;
    check_status(maelys_datalog_result_query(result, "allow", terms, 2, &present));
    return present;
}
int main(void) {
    if (atexit(cleanup_context) != 0) return EXIT_FAILURE;
    const maelys_datalog_predicate_t predicates[] = {
        MAELYS_DATALOG_EDB("user", 1), MAELYS_DATALOG_EDB("owns", 2),
        MAELYS_DATALOG_EDB("blocked", 1), MAELYS_DATALOG_EDB("access", 3),
        MAELYS_DATALOG_IDB_QUERY("allow", 2), MAELYS_DATALOG_IDB_QUERY("observed", 2)
    };
    const maelys_datalog_domain_t domain = MAELYS_DATALOG_DOMAIN_NO_ATOMS("documents", predicates);
    check_status(maelys_datalog_domain_register(&domain));
    const char *source = "allow(User, Doc) :- owns(User, Doc), not(blocked(User)).\n"
        "observed(User, Doc) :- access(Occurrence, User, Doc).";
    maelys_datalog_diagnostic_t diagnostic = MAELYS_DATALOG_DIAGNOSTIC_INIT;
    check_status(maelys_datalog_policy_load_inline("documents", "event-windows-context",
        source, strlen(source), &policy, &diagnostic));
    for (size_t i = 0; i < 4; ++i) check_status(maelys_datalog_session_create(policy, 0, &sessions[i]));
    {

const maelys_datalog_window_options_t options = {
    .struct_size = sizeof(maelys_datalog_window_options_t),
    .static_fact_capacity = 4,
    .flags = MAELYS_DATALOG_WINDOW_EXPIRATION
};
size_t bytes = 0, alignment = 0;
maelys_datalog_status_t status = maelys_datalog_window_storage_requirements_configured(
    event_capacity, text_capacity, &options, &bytes, &alignment);
check_status(status);
window_storage = malloc(bytes);
check_storage(window_storage, alignment);
status = maelys_datalog_window_init_configured(window_storage, bytes,
    event_capacity, text_capacity, &options, 0, sessions[0], sessions[1], &window, &diagnostic);
check_status(status);

for (size_t i = 0; i < 3; ++i) {
    status = maelys_datalog_window_push(window, "access", terms, 2, NULL, &diagnostic);
    check_status(status);
}
const maelys_datalog_fact_t *events = NULL;
size_t count = 0;
check_status(maelys_datalog_window_events(window, &events, &count));
maelys_datalog_result_t *event_result = NULL;
check_status(maelys_datalog_window_result(window, &event_result));

create_group_window(&options);
status = maelys_datalog_group_window_push_until(group_window, facts,
    sizeof(facts) / sizeof(facts[0]), 20, NULL, &diagnostic);
check_status(status);
maelys_datalog_group_window_usage_t usage;
check_status(maelys_datalog_group_window_state(group_window, &usage));
const maelys_datalog_fact_t blocked[] = {
    { "blocked", 1, { MAELYS_DATALOG_SYMBOL("alice") } }
};
status = maelys_datalog_group_window_push_until(group_window, blocked,
    sizeof(blocked) / sizeof(blocked[0]), 10, NULL, &diagnostic);
check_status(status);
maelys_datalog_result_t *result = NULL;
check_status(maelys_datalog_group_window_result(group_window, &result));
int before = allows_alice(result);

/* API_REFERENCE_EXAMPLE */
    }
    cleanup_context();
    if (cleanup_failed) return EXIT_FAILURE;
    return EXIT_SUCCESS;
}

5. Compare answers and release the windows

The application compares the two saved query answers; the window does not return a list of changes. A successful push, static-fact replacement, expiration that removes entries, or release invalidates borrowed results and views. Read a new result after such an update. Expiration with no due entry records only the new time and keeps those views valid. Release both windows before freeing their sessions and caller-owned memory; the context performs that final cleanup.

Example
CODE
printf("access became allowed: %s\n", !before && after ? "yes" : "no");
status = maelys_datalog_group_window_free(group_window);
printf("group release status: %s\n", maelys_datalog_status_name(status));
check_status(status);
group_window = NULL;
status = maelys_datalog_window_free(window);
printf("event release status: %s\n", maelys_datalog_status_name(status));
check_status(status);
window = NULL;
access became allowed: yes
group release status: ok
event release status: ok
Reference context · step 5
CODE
/* Common C reference declarations; concatenated before the page extension. */
#include <maelys/datalog.h>
#include <maelys/datalog_builders.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>

/* The page extension owns cleanup; no constructor is hidden in the runner. */
static void cleanup_context(void);
static int cleanup_failed = 0;

static void check_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        fprintf(stderr, "API call failed: %s\n", maelys_datalog_status_name(status));
        exit(EXIT_FAILURE);
    }
}

/* Label each output line without changing the text buffer. */
static void print_text_lines(const char *label, const char *text) {
    while (*text != '\0') {
        const char *end = strchr(text, '\n');
        printf("%s: ", label);
        fwrite(text, 1, end ? (size_t)(end - text) : strlen(text), stdout);
        putchar('\n');
        if (end == NULL) break;
        text = end + 1;
    }
}

/* Cleanup failures must not recursively invoke check_status. */
static void cleanup_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        cleanup_failed = 1;
        fprintf(stderr, "Context cleanup failed: %s\n", maelys_datalog_status_name(status));
    }
}

/* Event windows borrow two idle sessions; each adapter has its own pair. */
#include <maelys/datalog_window.h>
#include <stdint.h>
#include <inttypes.h>

static maelys_datalog_policy_t *policy = NULL;
static maelys_datalog_session_t *sessions[4] = { NULL, NULL, NULL, NULL };
static maelys_datalog_window_t *window = NULL;
static maelys_datalog_group_window_t *group_window = NULL;
static void *window_storage = NULL, *group_storage = NULL;
static const size_t event_capacity = 2, text_capacity = 512;
static const maelys_datalog_group_window_capacities_t capacities = { 2, 8, 8, 512 };
static const maelys_datalog_value_t terms[] = {
    MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf")
};
static const maelys_datalog_fact_t facts[] = {
    { "owns", 2, { MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf") } },
    { "blocked", 1, { MAELYS_DATALOG_SYMBOL("mallory") } }
};
static const maelys_datalog_fact_t static_facts[] = {
    { "user", 1, { MAELYS_DATALOG_SYMBOL("alice") } }
};
static void cleanup_context(void) {
    if (window != NULL) {
        maelys_datalog_status_t status = maelys_datalog_window_free(window);
        cleanup_status(status);
        if (status != MAELYS_DATALOG_STATUS_OK) return;
        window = NULL;
    }
    if (group_window != NULL) {
        maelys_datalog_status_t status = maelys_datalog_group_window_free(group_window);
        cleanup_status(status);
        if (status != MAELYS_DATALOG_STATUS_OK) return;
        group_window = NULL;
    }
    for (size_t i = 0; i < 4; ++i) {
        if (sessions[i] != NULL) { cleanup_status(maelys_datalog_session_free(sessions[i])); sessions[i] = NULL; }
    }
    free(window_storage); window_storage = NULL;
    free(group_storage); group_storage = NULL;
    if (policy != NULL) { cleanup_status(maelys_datalog_policy_free(policy)); policy = NULL; }
}
static void check_storage(void *storage, size_t alignment) {
    if (storage == NULL || alignment == 0 || (uintptr_t)storage % alignment != 0) {
        fputs("Storage allocation failed\n", stderr); exit(EXIT_FAILURE);
    }
}
static void create_group_window(const maelys_datalog_window_options_t *options) {
    size_t bytes = 0, alignment = 0;
    check_status(maelys_datalog_group_window_storage_requirements_configured(
        &capacities, options, &bytes, &alignment));
    group_storage = malloc(bytes);
    check_storage(group_storage, alignment);
    check_status(maelys_datalog_group_window_init_configured(group_storage, bytes,
        &capacities, options, 0, sessions[2], sessions[3], &group_window, NULL));
}
static size_t observed_count(maelys_datalog_result_t *result) {
    maelys_datalog_fact_view_t rows[2];
    size_t count = 0;
    check_status(maelys_datalog_result_enumerate(result, "observed", 2, rows, 2, &count));
    return count;
}
static int allows_alice(maelys_datalog_result_t *result) {
    int present = 0;
    check_status(maelys_datalog_result_query(result, "allow", terms, 2, &present));
    return present;
}
int main(void) {
    if (atexit(cleanup_context) != 0) return EXIT_FAILURE;
    const maelys_datalog_predicate_t predicates[] = {
        MAELYS_DATALOG_EDB("user", 1), MAELYS_DATALOG_EDB("owns", 2),
        MAELYS_DATALOG_EDB("blocked", 1), MAELYS_DATALOG_EDB("access", 3),
        MAELYS_DATALOG_IDB_QUERY("allow", 2), MAELYS_DATALOG_IDB_QUERY("observed", 2)
    };
    const maelys_datalog_domain_t domain = MAELYS_DATALOG_DOMAIN_NO_ATOMS("documents", predicates);
    check_status(maelys_datalog_domain_register(&domain));
    const char *source = "allow(User, Doc) :- owns(User, Doc), not(blocked(User)).\n"
        "observed(User, Doc) :- access(Occurrence, User, Doc).";
    maelys_datalog_diagnostic_t diagnostic = MAELYS_DATALOG_DIAGNOSTIC_INIT;
    check_status(maelys_datalog_policy_load_inline("documents", "event-windows-context",
        source, strlen(source), &policy, &diagnostic));
    for (size_t i = 0; i < 4; ++i) check_status(maelys_datalog_session_create(policy, 0, &sessions[i]));
    {

const maelys_datalog_window_options_t options = {
    .struct_size = sizeof(maelys_datalog_window_options_t),
    .static_fact_capacity = 4,
    .flags = MAELYS_DATALOG_WINDOW_EXPIRATION
};
size_t bytes = 0, alignment = 0;
maelys_datalog_status_t status = maelys_datalog_window_storage_requirements_configured(
    event_capacity, text_capacity, &options, &bytes, &alignment);
check_status(status);
window_storage = malloc(bytes);
check_storage(window_storage, alignment);
status = maelys_datalog_window_init_configured(window_storage, bytes,
    event_capacity, text_capacity, &options, 0, sessions[0], sessions[1], &window, &diagnostic);
check_status(status);

for (size_t i = 0; i < 3; ++i) {
    status = maelys_datalog_window_push(window, "access", terms, 2, NULL, &diagnostic);
    check_status(status);
}
const maelys_datalog_fact_t *events = NULL;
size_t count = 0;
check_status(maelys_datalog_window_events(window, &events, &count));
maelys_datalog_result_t *event_result = NULL;
check_status(maelys_datalog_window_result(window, &event_result));

create_group_window(&options);
status = maelys_datalog_group_window_push_until(group_window, facts,
    sizeof(facts) / sizeof(facts[0]), 20, NULL, &diagnostic);
check_status(status);
maelys_datalog_group_window_usage_t usage;
check_status(maelys_datalog_group_window_state(group_window, &usage));
const maelys_datalog_fact_t blocked[] = {
    { "blocked", 1, { MAELYS_DATALOG_SYMBOL("alice") } }
};
status = maelys_datalog_group_window_push_until(group_window, blocked,
    sizeof(blocked) / sizeof(blocked[0]), 10, NULL, &diagnostic);
check_status(status);
maelys_datalog_result_t *result = NULL;
check_status(maelys_datalog_group_window_result(group_window, &result));
int before = allows_alice(result);

size_t expired = 0;
status = maelys_datalog_group_window_expire(group_window, 10, &expired, &diagnostic);
check_status(status);
check_status(maelys_datalog_group_window_result(group_window, &result));
int after = allows_alice(result);

/* API_REFERENCE_EXAMPLE */
    }
    cleanup_context();
    if (cleanup_failed) return EXIT_FAILURE;
    return EXIT_SUCCESS;
}

Use Session inputs when your application already computes explicit additions and removals. Those deltas do not provide the window's last-N retention or expiration rules.

Storage and failure behavior

The window stores its events in the memory supplied at creation and does not grow that memory automatically. Its two sessions and their results need their own memory; this is not a claim that the whole engine avoids allocation. Keep each window and its borrowed sessions for exclusive use until the window is released.

A failed update keeps the previous accepted facts, result and next event ID. If you prepared an explanation from the current result, release that explanation before changing the window; otherwise it can block publication of the new result. Only remove the caller-owned memory after releasing the window.

Complete example

The five fragments above appear below in exactly the same order as one program. The folded context registers the document-access vocabulary, loads the policy, and prepares a separate pair of idle sessions for each window.

Full program
CODE
/* Common C reference declarations; concatenated before the page extension. */
#include <maelys/datalog.h>
#include <maelys/datalog_builders.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>

/* The page extension owns cleanup; no constructor is hidden in the runner. */
static void cleanup_context(void);
static int cleanup_failed = 0;

static void check_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        fprintf(stderr, "API call failed: %s\n", maelys_datalog_status_name(status));
        exit(EXIT_FAILURE);
    }
}

/* Label each output line without changing the text buffer. */
static void print_text_lines(const char *label, const char *text) {
    while (*text != '\0') {
        const char *end = strchr(text, '\n');
        printf("%s: ", label);
        fwrite(text, 1, end ? (size_t)(end - text) : strlen(text), stdout);
        putchar('\n');
        if (end == NULL) break;
        text = end + 1;
    }
}

/* Cleanup failures must not recursively invoke check_status. */
static void cleanup_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        cleanup_failed = 1;
        fprintf(stderr, "Context cleanup failed: %s\n", maelys_datalog_status_name(status));
    }
}

/* Event windows borrow two idle sessions; each adapter has its own pair. */
#include <maelys/datalog_window.h>
#include <stdint.h>
#include <inttypes.h>

static maelys_datalog_policy_t *policy = NULL;
static maelys_datalog_session_t *sessions[4] = { NULL, NULL, NULL, NULL };
static maelys_datalog_window_t *window = NULL;
static maelys_datalog_group_window_t *group_window = NULL;
static void *window_storage = NULL, *group_storage = NULL;
static const size_t event_capacity = 2, text_capacity = 512;
static const maelys_datalog_group_window_capacities_t capacities = { 2, 8, 8, 512 };
static const maelys_datalog_value_t terms[] = {
    MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf")
};
static const maelys_datalog_fact_t facts[] = {
    { "owns", 2, { MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf") } },
    { "blocked", 1, { MAELYS_DATALOG_SYMBOL("mallory") } }
};
static const maelys_datalog_fact_t static_facts[] = {
    { "user", 1, { MAELYS_DATALOG_SYMBOL("alice") } }
};
static void cleanup_context(void) {
    if (window != NULL) {
        maelys_datalog_status_t status = maelys_datalog_window_free(window);
        cleanup_status(status);
        if (status != MAELYS_DATALOG_STATUS_OK) return;
        window = NULL;
    }
    if (group_window != NULL) {
        maelys_datalog_status_t status = maelys_datalog_group_window_free(group_window);
        cleanup_status(status);
        if (status != MAELYS_DATALOG_STATUS_OK) return;
        group_window = NULL;
    }
    for (size_t i = 0; i < 4; ++i) {
        if (sessions[i] != NULL) { cleanup_status(maelys_datalog_session_free(sessions[i])); sessions[i] = NULL; }
    }
    free(window_storage); window_storage = NULL;
    free(group_storage); group_storage = NULL;
    if (policy != NULL) { cleanup_status(maelys_datalog_policy_free(policy)); policy = NULL; }
}
static void check_storage(void *storage, size_t alignment) {
    if (storage == NULL || alignment == 0 || (uintptr_t)storage % alignment != 0) {
        fputs("Storage allocation failed\n", stderr); exit(EXIT_FAILURE);
    }
}
static void create_group_window(const maelys_datalog_window_options_t *options) {
    size_t bytes = 0, alignment = 0;
    check_status(maelys_datalog_group_window_storage_requirements_configured(
        &capacities, options, &bytes, &alignment));
    group_storage = malloc(bytes);
    check_storage(group_storage, alignment);
    check_status(maelys_datalog_group_window_init_configured(group_storage, bytes,
        &capacities, options, 0, sessions[2], sessions[3], &group_window, NULL));
}
static size_t observed_count(maelys_datalog_result_t *result) {
    maelys_datalog_fact_view_t rows[2];
    size_t count = 0;
    check_status(maelys_datalog_result_enumerate(result, "observed", 2, rows, 2, &count));
    return count;
}
static int allows_alice(maelys_datalog_result_t *result) {
    int present = 0;
    check_status(maelys_datalog_result_query(result, "allow", terms, 2, &present));
    return present;
}
int main(void) {
    if (atexit(cleanup_context) != 0) return EXIT_FAILURE;
    const maelys_datalog_predicate_t predicates[] = {
        MAELYS_DATALOG_EDB("user", 1), MAELYS_DATALOG_EDB("owns", 2),
        MAELYS_DATALOG_EDB("blocked", 1), MAELYS_DATALOG_EDB("access", 3),
        MAELYS_DATALOG_IDB_QUERY("allow", 2), MAELYS_DATALOG_IDB_QUERY("observed", 2)
    };
    const maelys_datalog_domain_t domain = MAELYS_DATALOG_DOMAIN_NO_ATOMS("documents", predicates);
    check_status(maelys_datalog_domain_register(&domain));
    const char *source = "allow(User, Doc) :- owns(User, Doc), not(blocked(User)).\n"
        "observed(User, Doc) :- access(Occurrence, User, Doc).";
    maelys_datalog_diagnostic_t diagnostic = MAELYS_DATALOG_DIAGNOSTIC_INIT;
    check_status(maelys_datalog_policy_load_inline("documents", "event-windows-context",
        source, strlen(source), &policy, &diagnostic));
    for (size_t i = 0; i < 4; ++i) check_status(maelys_datalog_session_create(policy, 0, &sessions[i]));
    {
        const maelys_datalog_window_options_t options = {
    .struct_size = sizeof(maelys_datalog_window_options_t),
    .static_fact_capacity = 4,
    .flags = MAELYS_DATALOG_WINDOW_EXPIRATION
};
size_t bytes = 0, alignment = 0;
maelys_datalog_status_t status = maelys_datalog_window_storage_requirements_configured(
    event_capacity, text_capacity, &options, &bytes, &alignment);
printf("storage planning status: %s\n", maelys_datalog_status_name(status));
check_status(status);
window_storage = malloc(bytes);
check_storage(window_storage, alignment);
status = maelys_datalog_window_init_configured(window_storage, bytes,
    event_capacity, text_capacity, &options, 0, sessions[0], sessions[1], &window, &diagnostic);
printf("window initialization status: %s\n", maelys_datalog_status_name(status));
check_status(status);
for (size_t i = 0; i < 3; ++i) {
    status = maelys_datalog_window_push(window, "access", terms, 2, NULL, &diagnostic);
    printf("event push status: %s\n", maelys_datalog_status_name(status));
    check_status(status);
}
const maelys_datalog_fact_t *events = NULL;
size_t count = 0;
check_status(maelys_datalog_window_events(window, &events, &count));
printf("retained events: %zu\n", count);
printf("oldest retained occurrence: %" PRId64 "\n", events[0].terms[0].as.integer);
maelys_datalog_result_t *event_result = NULL;
check_status(maelys_datalog_window_result(window, &event_result));
printf("distinct observed pairs: %zu\n", observed_count(event_result));
create_group_window(&options);
status = maelys_datalog_group_window_push_until(group_window, facts,
    sizeof(facts) / sizeof(facts[0]), 20, NULL, &diagnostic);
printf("ownership group status: %s\n", maelys_datalog_status_name(status));
check_status(status);
maelys_datalog_group_window_usage_t usage;
check_status(maelys_datalog_group_window_state(group_window, &usage));
printf("initial group contributions: %zu\n", usage.contributions);
const maelys_datalog_fact_t blocked[] = {
    { "blocked", 1, { MAELYS_DATALOG_SYMBOL("alice") } }
};
status = maelys_datalog_group_window_push_until(group_window, blocked,
    sizeof(blocked) / sizeof(blocked[0]), 10, NULL, &diagnostic);
printf("block group status: %s\n", maelys_datalog_status_name(status));
check_status(status);
maelys_datalog_result_t *result = NULL;
check_status(maelys_datalog_group_window_result(group_window, &result));
int before = allows_alice(result);
printf("access before expiration: %s\n", before ? "yes" : "no");
size_t expired = 0;
status = maelys_datalog_group_window_expire(group_window, 10, &expired, &diagnostic);
printf("expiration status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("groups expired: %zu\n", expired);
check_status(maelys_datalog_group_window_result(group_window, &result));
int after = allows_alice(result);
printf("access after expiration: %s\n", after ? "yes" : "no");
printf("access became allowed: %s\n", !before && after ? "yes" : "no");
status = maelys_datalog_group_window_free(group_window);
printf("group release status: %s\n", maelys_datalog_status_name(status));
check_status(status);
group_window = NULL;
status = maelys_datalog_window_free(window);
printf("event release status: %s\n", maelys_datalog_status_name(status));
check_status(status);
window = NULL;
    }
    cleanup_context();
    if (cleanup_failed) return EXIT_FAILURE;
    return EXIT_SUCCESS;
}

Usage guides