Implementation:InternLM Lmdeploy Interval
| Knowledge Sources | |
|---|---|
| Domains | Data_Structures, Core_Infrastructure |
| Last Updated | 2026-02-07 15:00 GMT |
Overview
Provides a half-open integer interval class [first, last) with intersection, union, dilation/erosion, and size query operations.
Description
The Interval class represents a half-open integer range [first_, last_). It supports construction from a single start value (open-ended, using INT_MAX), a pair of endpoints, or a start plus Size wrapper. Key operations include: empty() for checking if the interval has zero or negative extent, size() returning a Size struct, begin()/end() for the endpoints, operator& for intersection, operator| for union (bounding box), and left/right dilation via int | Interval and Interval | int. The Size nested struct wraps an int with an explicit conversion operator and comparison support.
Usage
Used in TurboMind for representing token index ranges, sequence position windows, and KV-cache slot ranges during attention computation and sequence scheduling.
Code Reference
Source Location
- Repository: InternLM_Lmdeploy
- File: src/turbomind/core/interval.h
- Lines: 1-95
Signature
namespace turbomind {
class Interval {
public:
struct Size {
int x;
explicit operator int() const noexcept;
};
Interval(); // empty [0, 0)
explicit Interval(int first); // [first, INT_MAX)
Interval(int first, int last); // [first, last)
Interval(int first, Size size); // [first, first+size)
bool empty() const noexcept;
explicit operator bool() const noexcept;
Size size() const noexcept;
int begin() const noexcept;
int end() const noexcept;
friend Interval operator&(const Interval& a, const Interval& b); // intersection
friend Interval operator|(const Interval& a, const Interval& b); // union
friend Interval operator|(int x, const Interval& a); // dilate left
friend Interval operator|(const Interval& a, int x); // dilate right
};
} // namespace turbomind
Import
#include "src/turbomind/core/interval.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| first | int | Yes | Start of the interval (inclusive) |
| last | int | Conditional | End of the interval (exclusive); or use Size |
| size | Size | Conditional | Extent of the interval |
Outputs
| Name | Type | Description |
|---|---|---|
| empty() | bool | True if the interval has zero or negative extent |
| size() | Size | Number of integers in the interval |
| begin() | int | First element (inclusive) |
| end() | int | Past-the-end element (exclusive) |
Usage Examples
#include "src/turbomind/core/interval.h"
using turbomind::Interval;
Interval a(10, 20); // [10, 20)
Interval b(15, 25); // [15, 25)
auto inter = a & b; // [15, 20) - intersection
auto uni = a | b; // [10, 25) - union
int sz = (int)a.size(); // 10
// Dilate right by 5
auto dilated = a | 5; // [10, 25)