3 个版本 (破坏性)
| 0.3.0 | 2023年8月4日 |
|---|---|
| 0.2.0 | 2023年8月4日 |
| 0.1.0 | 2023年7月31日 |
#1901 在 数据结构
61KB
1.5K SLoC
Colony
一个无序数据结构,具有 O(1) 查找、删除、迭代和 O(1) 摊销插入。类似于选择其自己的键的更快的 HashMap。也类似于一个 Vec<Option<T>>,其中元素不是通过调用 Vec::remove 来删除,而是通过将元素设置为 None 来删除。
有关更多信息,请参阅 文档。
此crate部分是 plf::colony 的移植,它是一个 提议添加 到 C++ 标准库的名为 std::hive 的内容。
示例
let mut colony = Colony::new();
// Insert
let foo_handle = colony.insert("foo");
let bar_handle = colony.insert("bar");
// Remove
assert_eq!(colony.remove(foo_handle), Some("foo"));
// Lookup
assert_eq!(colony.get(foo_handle), None);
assert_eq!(colony.get(bar_handle), Some(&"bar"));
// Iteration
for (key, &value) in colony.iter() {
assert_eq!((key, value), (bar_handle, "bar"));
}