【发布时间】:2022-01-09 04:37:24
【问题描述】:
我想要一个排序数组,它有一个 f64 作为键,一个 f64 作为值。 我需要通过找到正确的键来更新、删除和插入这个数组。 我需要获得前 1000 个排序条目,以及第一个条目。 这些操作必须很快。
通过阅读the documentation,我认为 BTreeMap 对我有好处。
但是,当我尝试插入其中时,我收到了以下错误消息:
the trait bound `f64: Ord` is not satisfied
the trait `Ord` is not implemented for `f64`rustcE0277
推荐使用 Rust 的方法是什么?
我的代码:
use std::collections::BTreeMap;
pub struct MyStruct {
pub map: BTreeMap<f64, f64>
}
impl MyStruct {
pub fn new() -> MyStruct {
MyStruct {
map: BTreeMap::new()
}
}
}
fn main() {
let mut my_struct = MyStruct::new();
my_struct.map.insert(1.0, 2.0);
}
【问题讨论】:
标签: rust