10 个不稳定版本 (3 个破坏性更新)
新功能 0.4.1 | 2024 年 8 月 13 日 |
---|---|
0.4.0 | 2024 年 8 月 13 日 |
0.3.5 | 2024 年 8 月 10 日 |
0.2.1 | 2024 年 8 月 6 日 |
0.1.0 | 2024 年 8 月 2 日 |
#381 在 数据结构
802 每月下载量
82KB
1K SLoC
Iter 谁?IterList!
这是一个基于游标 API 的双向链表。
也是一个迭代器!
O(1)
几乎所有(在游标周围)。
最初是为 Shard 制作的,但认为它对其他人也可能有用。
现在包含: atomic
模块!
你对高效的数据结构感到厌烦了吗?
你想要做一些无锁的操作吗?
拍拍帽子
好,这个小家伙现在 Send + Sync
,并且可以在线程之间原子性地修改!
使用 Result<Option<Result<...
示例
use iterlist::IterList;
let mut list = IterList::new();
list.push_prev(-1);
list.push_next(1);
list.push_next(2);
list.push_next(3);
assert_eq!(format!("{:?}", list), "[-1, 1, 2, 3]");
list.move_to(2);
assert_eq!(list.get_cursor(), Some(&2));
list.move_by(-2);
assert_eq!(list.index(), 0);
let mut cursor = list.as_cursor();
assert_eq!(cursor.next(), Some(&-1));
assert_eq!(cursor.next(), Some(&1));
assert_eq!(list.get(1), Some(&1));
list.move_by(2);
let (elem, _) = list.consume_forward().unwrap();
assert_eq!(elem, 2);
assert_eq!(format!("{:?}", list), "[-1, 1, 3]");
let num = list.fold(0, |acc, elem| acc + elem);
assert_eq!(num, 3);
我为什么要使用 IterList
?
- 你在遍历列表,同时删除/插入元素。(在我的测试中,它比
std::collections::VecDeque
略好一些) - 你希望在同一个列表上有多个独立的游标。
- 你需要一个可以移动并修改的迭代器。
- 它在大多数情况下也比
std::collections::LinkedList
快得多!
待办事项
-
append
- 将另一个列表追加到末尾。 -
prepend
- 将另一个列表预置于开头。 -
drain
- 从列表中删除一段元素(围绕游标)。 -
splice
- 用另一个列表替换一段元素(围绕游标)。 -
DoubleEndedIterator
用于Cursor
。 -
feature(atomic)
- 原子 IterList 和 Cursor。 -
feature(pool)
- 半池分配的列表,用于将元素分组到连续的内存中。 -
feature(no_std)
- 不支持 std。
如果您想添加任何这些功能,请随意!