1个不稳定版本
0.1.0 | 2023年7月22日 |
---|
#2158 in 算法
16KB
173 行
drain_at_sorted_unchecked
非常不安全但效率极高的函数,允许通过少量移动从向量中删除项目。
示例
use drain_at_sorted_unchecked::drain_at_sorted_unchecked;
fn main() {
let mut v = vec![0, 1, 2, 3, 4, 5, 6, 7, 8];
// Safety:
//
// [x] The indices are sorted in ascending order.
// [x] The indices are within bounds of the vector.
// [x] The indices are unique.
// [x] Items of type i32 are trivially movable.
unsafe { drain_at_sorted_unchecked(&mut v, [2,4,6]); }
assert_eq!(v, [0, 1, 3, 5, 7, 8]);
}
安全性
- 索引必须按升序排序。
- 索引必须在集合的范围内。
- 索引必须是唯一的。
- 项目必须是简单可移动的。
注意
目前算法仅实现为向量,因为作者需要。将算法扩展到其他连续集合(例如 heapless::Vec
或 arrayvec::ArrayVec
)应该是简单的。
该库经过了相当多的测试,但仍然存在一些细微的缺陷。如果您发现任何问题,请报告。
许可证
根据以下任一许可证许可:
- Apache许可证版本2.0,(LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任选其一。
贡献
除非您明确声明,否则您有意提交给作品以供包含在内的任何贡献,根据Apache-2.0许可证定义,应按上述方式双许可,无需任何附加条款或条件。