[
](LICENSE)
[
]()
loon – High-Performance, Header-Only Modern C++ Library
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.
Key Features:
- 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.
Components
Installation
Using Conan (recommended)
Add to your conanfile.txt:
Or conanfile.py:
def requirements(self):
self.requires("loon/0.1.0")
Header-only (manual)
Copy the include/loon directory to your project and add it to your include path.
Usage
CMake
find_package(loon REQUIRED)
target_link_libraries(your_target PRIVATE loon::loon)
LRU Cache
cache.put(1, "hello");
cache.put(2, "world");
auto val = cache.get(1);
if (val) {
std::cout << val->get() << std::endl;
}
cache.exists(1);
cache.remove(1);
cache.size();
A Least Recently Used (LRU) cache with O(1) access and eviction.
Thread-safe LRU (Least Recently Used) cache implementation.
LRU 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) |
Redis List
auto vals = list.
rpop(2);
auto range = list.
lrange(0, -1);
A Redis-compatible list supporting operations from both ends.
size_t lpush(const T &value)
Pushes a value to the front of the list (left push).
size_t llen() const
Returns the length of the list (Redis LLEN command).
std::optional< T > rpop()
Removes and returns the last element (right pop).
std::optional< T > lpop()
Removes and returns the first element (left pop).
std::vector< T > lrange(int start, int stop) const
Returns a range of elements without removing them.
size_t rpush(const T &value)
Pushes a value to the back of the list (right push).
Redis-compatible list data structure implementation.
Redis 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) |
Ring Buffer
A fixed-size circular buffer (ring buffer) with FIFO semantics.
std::optional< T > pop()
Removes and returns the front element.
size_t size() const
Returns the current number of elements.
bool empty() const
Checks if the buffer is empty.
bool full() const
Checks if the buffer is full.
std::optional< T > back()
Returns the back element without removing it.
std::optional< T > front()
Returns the front element without removing it.
bool discard()
Discards the front element without returning it.
bool push(const T &value)
Pushes a value to the back of the buffer.
Fixed-size ring buffer (circular queue) implementation.
Ring 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.
Building from Source
Prerequisites
- C++23 compatible compiler (GCC 13+, Clang 14+)
- CMake 3.20+
- Conan 2.x
Build and Test
# Setup Conan (one-time)
make conan-setup
# Install dependencies
make deps
# Build and run tests
make build
# Create and test Conan package
make package
Other Targets
make help # Show all targets
make coverage # Generate coverage report
make check-format # Check code formatting
make format # Apply clang-format
make clean # Clean build files
License
MIT License - see [LICENSE](LICENSE) for details.