ris
A Rust crate to compute the Longest Increasing Subsequence (LIS) and other monotonic subsequences.
It runs in O(N log N) time and operates in #![no_std] environments (requires alloc).
Features
- Computes the values, indices, or length of the longest increasing subsequence.
- Supports custom monotonic conditions, allowing you to extract strictly decreasing, non-decreasing, and non-increasing sequences.
- Provides extension traits for standard slices (
[T]) and iterators. - Requires no standard library (
#![no_std]), utilizing onlyallocfor memory management.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Performance
The following benchmark compares ris with other LIS crates: longest-increasing-subsequence and lis.
Usage
Slice Extension
You can use the LisExt trait to compute subsequences directly on arrays and slices.
use LisExt;
Other Monotonic Subsequences
The LisExt trait includes convenience methods to find other types of monotonic subsequences.
use LisExt;
You can also provide a custom closure using the _by or _by_key methods.
use LisExt;
Iterator Extension
The IteratorLisExt trait allows consuming an iterator directly to compute a subsequence.
use IteratorLisExt;
License
This project is dual-licensed under either the MIT license or the Apache License, Version 2.0, at your option.