Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursors that iterate over non-empty trails #107

Open
tuulos opened this issue Sep 29, 2016 · 0 comments
Open

Cursors that iterate over non-empty trails #107

tuulos opened this issue Sep 29, 2016 · 0 comments

Comments

@tuulos
Copy link
Member

tuulos commented Sep 29, 2016

Problem

The current API requires that you set the cursor explicitly for each trail using tdb_get_trail. When combined with event filters, it is possible that some trails yield no events. Hence, even empty trails require at least two function calls, tdb_get_trail(); tdb_cursor_next(). For language bindings that have a high function call overhead, e.g. CGo and Python, the cost of redundant function calls can be high.

Proposed Solutions

The problem with redundant function calls could be solved as follows:

  1. If it is desirable to know exactly which trails are iterated over, we could introduce

    uint64_t tdb_get_next_trail(tdb_cursor *cursor)
    

    which resets the cursor to the next non-empty trail and returns the trail_id. To iterate over all non-empty trails, use while((trail_id = tdb_get_next_trail(cursor))). Especially for highly selective filters, this is much more efficient than calling tdb_get_trail(); tdb_cursor_next() for every trail.

  2. If it is desirable to iterate over all events, e.g. to collect TrailDB-wide statistics, we could introduce

    const tdb_event *tdb_cursor_next_all(tdb_cursor *cursor, uint64_t *trail_id)
    

    To iterate overall all events, use while ((event = tdb_cursor_next_all(cursor, &trail_id)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant