Skip to content

Commit

Permalink
Merge pull request #24 from LegionMammal978/master
Browse files Browse the repository at this point in the history
Remove unnecessary unsafe block in `IpTrie::insert()`
  • Loading branch information
sticnarf authored May 5, 2022
2 parents f1710d9 + 6d845c1 commit ffe0135
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,34 +459,32 @@ where
// Insert into all-zero network has no effect.
return;
}
root as *mut IpTrieNode
root
} else {
self.root = Some(IpTrieNode::new());
self.root.as_mut().unwrap() as *mut IpTrieNode
self.root.as_mut().unwrap()
};

unsafe {
let bits = network.prefix_bits();
for bit in bits {
let i = bit as usize;
let child = &mut (*node).children[i];
match child {
Some(child) => {
if child.is_leaf() {
// This means the network to be inserted
// is already in the trie.
return;
}
node = &mut **child as *mut IpTrieNode;
}
None => {
(*node).children[i] = Some(Box::new(IpTrieNode::new()));
node = (*node).children[i].as_mut().unwrap().as_mut() as *mut IpTrieNode;
let bits = network.prefix_bits();
for bit in bits {
let i = bit as usize;
let child = &mut node.children[i];
match child {
Some(child) => {
if child.is_leaf() {
// This means the network to be inserted
// is already in the trie.
return;
}
node = child;
}
None => {
*child = Some(Box::new(IpTrieNode::new()));
node = child.as_mut().unwrap();
}
}
(*node).children = [None, None];
}
node.children = [None, None];
}

fn search(&self, network: N) -> Option<N> {
Expand Down

0 comments on commit ffe0135

Please sign in to comment.