| Crates.io | rb-interval-map |
| lib.rs | rb-interval-map |
| version | 0.1.2 |
| created_at | 2024-08-22 07:59:49.813963+00 |
| updated_at | 2024-08-22 08:23:48.377142+00 |
| description | `rb-interval-map` is a map based on interval tree. |
| homepage | https://github.com/xline-kv/interval_map |
| repository | https://github.com/xline-kv/interval_map |
| max_upload_size | |
| id | 1347404 |
| size | 136,051 |
interval_map is a map based on interval tree. It fully implements the insertion and deletion functionality of a red-black tree, ensuring that each modification operation requires at most $O(logN)$ time complexity.
The implementation of the interval tree in interval_map references "Introduction to Algorithms" (3rd ed., Section 14.3: Interval trees, pp. 348–354).
To safely and efficiently handle insertion and deletion operations in Rust, interval_map innovatively uses arrays to simulate pointers for managing the parent-child references in the red-black tree. This approach also ensures that interval_map has the Send and Unpin traits, allowing it to be safely transferred between threads and to maintain a fixed memory location during asynchronous operations.
interval_map implements an IntervalMap struct:
Interval<T> as the key, where T can be any type that implements Ord trait. Therefore, intervals such as $[1, 2)$ and $["aaa", "bbb")$ are allowedinterval_map supports insert, delete, and iter fns. Traversal is performed in the order of Interval<T> . For instance, with intervals of type Interval<u32>:
So the order of intervals in IntervalMap is $[1,4)<[1,5)<[2,5)$.
Currently, interval_map only supports half-open intervals, i.e., $[...,...)$.
The benchmark was conducted on a platform with AMD R7 7840H + DDR5 5600MHz. The result are as follows:
| insert | 100 | 1000 | 10, 000 | 100, 000 |
|---|---|---|---|---|
| Total time | 5.4168 µs | 80.518 µs | 2.2823 ms | 36.528 ms |
| insert_and_remove | 100 | 1000 | 10, 000 | 100, 000 |
|---|---|---|---|---|
| Total time | 10.333 µs | 223.43 µs | 4.9358 ms | 81.634 ms |