loon is a lightweight, header-only C++ library designed for low memory footprint, low latency, and maximum performance. It provides optimized data structures and utilities that outperform standard STL counterparts while maintaining full STL compatibility.
- Zero-Cost Abstractions: Header-only design with no external dependencies.
- STL-Compliant: Drop-in replacements with familiar interfaces.
- Cache-Efficient: Optimized memory layout (SoA, pooling, alignment).
- Low Latency: Avoids dynamic allocation on critical paths; ideal for real-time systems.
- High Performance: Benchmarked against std:: types—faster insertion, lookup, and iteration.
Perfect for performance-critical applications in HFT, gaming, embedded systems, and real-time processing.
| Header | Description |
|---|---|
loon/lru.hpp |
LRU cache with O(1) get/put operations |
loon/redis_list.hpp |
Redis-style list with lpush/rpush/lpop/rpop/lrange |
loon/ring_buffer.hpp |
Fixed-size ring buffer (circular queue) with O(1) push/pop |
Add to your conanfile.txt:
[requires]
loon/0.1.0Or conanfile.py:
def requirements(self):
self.requires("loon/0.1.0")Copy the include/loon directory to your project and add it to your include path.
find_package(loon REQUIRED)
target_link_libraries(your_target PRIVATE loon::loon)#include <loon/lru.hpp>
loon::LRU<int, std::string> cache(100); // capacity of 100
cache.put(1, "hello");
cache.put(2, "world");
auto val = cache.get(1); // returns std::optional<std::reference_wrapper<V>>
if (val) {
std::cout << val->get() << std::endl; // "hello"
}
cache.exists(1); // true
cache.remove(1);
cache.size(); // 1LRU Cache Complexity:
| Operation | Time | Space |
|---|---|---|
get(key) |
O(1) | O(1) |
put(key, value) |
O(1) | O(1) |
exists(key) |
O(1) | O(1) |
remove(key) |
O(1) | O(1) |
size() |
O(1) | O(1) |
#include <loon/redis_list.hpp>
loon::RedisList<int> list;
list.lpush(1); // push to front
list.rpush(2); // push to back
list.lpush(0); // [0, 1, 2]
auto val = list.lpop(); // returns std::optional<T>, removes from front
auto vals = list.rpop(2); // pop multiple from back
auto range = list.lrange(0, -1); // get all elements (supports negative indices)
list.llen(); // sizeRedis List Complexity:
| Operation | Time | Space |
|---|---|---|
lpush(value) |
O(1) | O(1) |
rpush(value) |
O(1) | O(1) |
lpop() |
O(1) | O(1) |
rpop() |
O(1) | O(1) |
lpop(count) |
O(count) | O(count) |
rpop(count) |
O(count) | O(count) |
lrange(start, stop) |
O(stop - start) | O(stop - start) |
llen() / size() |
O(1) | O(1) |
empty() |
O(1) | O(1) |
#include <loon/ring_buffer.hpp>
loon::RingBuffer<int, 1024> buffer; // fixed capacity, reject when full
loon::RingBuffer<int, 1024> ring(true); // override oldest when full
buffer.push(42);
buffer.push(43);
auto val = buffer.pop(); // returns std::optional<int>, removes front
auto f = buffer.front(); // peek front without removing
auto b = buffer.back(); // peek back without removing
buffer.discard(); // drop front element without returning it
buffer.size(); // current element count
buffer.empty(); // true if no elements
buffer.full(); // true if at capacityRing Buffer Complexity:
| Operation | Time | Space |
|---|---|---|
push(value) |
O(1) | O(1) |
pop() |
O(1) | O(1) |
front() / back() |
O(1) | O(1) |
discard() |
O(1) | O(1) |
size() / empty() / full() |
O(1) | O(1) |
Performance notes: Stack-allocated std::array backing — zero heap allocation, fully contiguous memory layout. Ideal for real-time, embedded, and latency-critical applications.
- C++23 compatible compiler (GCC 13+, Clang 14+)
- CMake 3.20+
- Conan 2.x
# Setup Conan (one-time)
make conan-setup
# Install dependencies
make deps
# Build and run tests
make build
# Create and test Conan package
make packagemake help # Show all targets
make coverage # Generate coverage report
make check-format # Check code formatting
make format # Apply clang-format
make clean # Clean build filesMIT License - see LICENSE for details.