A high-performance C library for storing and querying time-based intervals. Built on top of qmap for efficient sorted storage and iteration.
libit allows you to:
- Store intervals: Record start/stop times for any entity (users, processes, events)
- Query overlaps: Find all intervals that intersect a given time range
- Split intervals: Decompose overlapping intervals into non-overlapping segments
- Persist data: Save intervals to disk and reload them later
- High capacity: Store up to 65,536 intervals per database
- High overlap support: Handle up to 4,096 concurrent overlapping entities
- Fast queries: Microsecond-level query performance
- File persistence: Built on qmap for reliable disk storage
- Clean API: Simple C interface with error handling
- Zero-copy iteration: Efficient traversal of query results
#include <ttypt/it.h>
// Create database (NULL = memory only, "data.qmap" = persisted)
unsigned itd = it_init(NULL);
// Record that entity 1 was active from time 1000 to 2000
it_start(itd, 1000, 1);
it_stop(itd, 2000, 1);
// Query: which entities were active between 1200 and 1800?
it_cur_t cur = it_iter(itd, 1200, 1800);
time_t min, max;
unsigned count, who;
while (it_next(&min, &max, &count, &who, &cur)) {
printf("Entity %u active [%ld, %ld)\n", who, min, max);
}# Clone and build
git clone https://github.com/tty-pt/libit.git
cd libit
make all
# Run tests
./test.sh
# Or run manually
LD_LIBRARY_PATH=./lib ./bin/test- qmap - Sorted key-value store with persistence
- qsys - System utilities library
- libc - Standard C library (already on your system)
These are automatically built and linked when you run make.
| Document | Description |
|---|---|
| QUICK_REFERENCE.md | API overview with code examples |
| CHANGELOG.md | Version history and changes |
| LIBIT_LIMITATIONS.md | Known limitations and workarounds |
| TESTING_SUMMARY.md | Test coverage and results |
| Function | Description |
|---|---|
it_init(fname) |
Create/open database (NULL = memory only) |
it_start(itd, time, id) |
Record interval start for entity |
it_stop(itd, time, id) |
Record interval stop for entity |
it_iter(itd, min, max) |
Create query iterator |
it_next(...) |
Get next result from iterator |
it_split(itd, min, max) |
Split overlapping intervals |
See include/ttypt/it.h for complete API documentation.
Current: v1.2.1
See CHANGELOG.md for release history.
See repository for details.
- qmap - Underlying storage engine
- Leon - Debugging assistance