Use an actual hash.

This commit is contained in:
Nicolas Patry 2024-09-13 18:34:53 +02:00
parent 9e45a09a0a
commit 5fa332156f
No known key found for this signature in database
GPG Key ID: 64AF4752B2967863

View File

@ -6,10 +6,10 @@ use std::{
sync::Arc, sync::Arc,
}; };
fn hash_(slice: &[u32]) -> u32 { fn hash_(slice: &[u32]) -> u64 {
let mut s = std::hash::DefaultHasher::new(); let mut s = std::hash::DefaultHasher::new();
slice.hash(&mut s); slice.hash(&mut s);
s.finish() as u32 s.finish()
} }
pub struct RadixAllocator { pub struct RadixAllocator {
@ -517,10 +517,10 @@ impl RadixTrie {
} }
/// Add a node to the parent. /// Add a node to the parent.
fn add_node_to_parent(&mut self, parent_id: NodeId, first: u32, child_id: NodeId) { fn add_node_to_parent(&mut self, parent_id: NodeId, hash: u64, child_id: NodeId) {
// Unwrap here, passing in an unknown id is a programming error. // Unwrap here, passing in an unknown id is a programming error.
let parent = self.nodes.get_mut(parent_id).expect("Unknown parent node"); let parent = self.nodes.get_mut(parent_id).expect("Unknown parent node");
if parent.children.insert(first, child_id).is_none() { if parent.children.insert(hash, child_id).is_none() {
// Only increase reference count if child does not replace another child. // Only increase reference count if child does not replace another child.
self.incref(parent_id) self.incref(parent_id)
.expect("Failed to increase parent refcount"); .expect("Failed to increase parent refcount");
@ -594,7 +594,7 @@ impl RadixTrie {
#[derive(Debug)] #[derive(Debug)]
struct TrieNode { struct TrieNode {
blocks: Vec<u32>, blocks: Vec<u32>,
children: HashMap<u32, NodeId>, children: HashMap<u64, NodeId>,
key: Vec<u32>, key: Vec<u32>,
last_accessed: u64, last_accessed: u64,
parent: Option<NodeId>, parent: Option<NodeId>,