我是 Rust 的新手,想在 Rust 中编写链表以获得乐趣。我对如何删除链表中的节点感到困惑。这是我的简单代码。
#[derive(Debug)]
struct Node{
v: usize,
next: Option<Box<Node>>,
}
struct LinkedList {
head: Option<Box<Node>>,
}
impl LinkedList {
fn remove(&mut self, v: usize) -> Option<usize> {
let mut current_node: &mut Option<Box<Node>> = &mut self.head;
loop {
match current_node {
None => break,
Some(node) => {
if node.v == v {
// current_node = what?
// ???????????????
break;
} else {
current_node = &mut node.next;
}
},
};
}
match current_node.take().map(|x| *x) {
Some(node) => {
*current_node …Run Code Online (Sandbox Code Playgroud) 我想获取此向量的哈希码:
let vec = vec![1,2,3];
let tmp = vec![1,2,3];
let mut hash = DefaultHasher::new();
vec.hash(&mut hash);
println!("{}", hash.finish());
tmp.hash(&mut hash);
println!("{}", hash.finish());
Run Code Online (Sandbox Code Playgroud)
但输出是:
13585085576907263210
8618793686565720431
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?我已多次尝试并始终获得相同的结果.我希望具有相同元素的向量散列到相同的哈希码.