diff --git a/src/transaction.rs b/src/transaction.rs index 0120c11..9017354 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -13,7 +13,7 @@ use crate::{ }; use self::nodes::{ - Branch, KeyPosition, KeyPositionAdjecent, Leaf, Node, NodeRef, StoredLeafRef, TrieRoot, + Branch, KeyPosition, KeyPositionAdjacent, Leaf, Node, NodeRef, StoredLeafRef, TrieRoot, }; pub struct Transaction { @@ -178,7 +178,7 @@ impl, V> Transaction { NodeRef::ModBranch(branch) => match branch.key_position(key_hash) { KeyPosition::Left => node_ref = &branch.left, KeyPosition::Right => node_ref = &branch.right, - KeyPosition::Adjecent(_) => return Ok(None), + KeyPosition::Adjacent(_) => return Ok(None), }, NodeRef::ModLeaf(leaf) => { if leaf.key_hash == *key_hash { @@ -209,7 +209,7 @@ impl, V> Transaction { Node::Branch(branch) => match branch.key_position(key_hash) { KeyPosition::Left => stored_idx = branch.left, KeyPosition::Right => stored_idx = branch.right, - KeyPosition::Adjecent(_) => return Ok(None), + KeyPosition::Adjacent(_) => return Ok(None), }, Node::Leaf(leaf) => { if leaf.key_hash == *key_hash { @@ -264,7 +264,7 @@ impl, V> Transaction { node_ref = &mut branch.right; continue; } - KeyPosition::Adjecent(pos) => { + KeyPosition::Adjacent(pos) => { branch.new_adjacent_leaf( pos, Box::new(Leaf { @@ -349,11 +349,11 @@ impl, V: PortableHash + Clone> Transaction { /// We match the standard library's `Entry` API for the most part. /// /// Note: Use of `entry` renders the trie path even if the entry is not modified. - /// This will incures allocations, now and unessisary rehashing later when calculating the root hash. + /// This incurs allocations, now and unnecessary rehashing later when calculating the root hash. /// For this reason you should prefer `get` if you have a high probability of not modifying the entry. #[inline] pub fn entry<'txn>(&'txn mut self, key_hash: &KeyHash) -> Result, TrieError> { - let mut key_position = KeyPositionAdjecent::PrefixOfWord(usize::MAX); + let mut key_position = KeyPositionAdjacent::PrefixOfWord(usize::MAX); match self.current_root { TrieRoot::Empty => Ok(Entry::VacantEmptyTrie(VacantEntryEmptyTrie { @@ -367,7 +367,7 @@ impl, V: PortableHash + Clone> Transaction { NodeRef::ModBranch(branch) => match branch.key_position(key_hash) { KeyPosition::Left => false, KeyPosition::Right => true, - KeyPosition::Adjecent(pos) => { + KeyPosition::Adjacent(pos) => { key_position = pos; break; } @@ -411,11 +411,11 @@ impl, V: PortableHash + Clone> Transaction { // This convoluted return makes the borrow checker happy. if let NodeRef::ModLeaf(leaf) = &*node_ref { if leaf.key_hash != *key_hash { - // This is bassically a logical null + // This is a logical null // TODO we should break VacantEntry into two types VacantEntryBranch and VacantEntryLeaf debug_assert_eq!( key_position, - KeyPositionAdjecent::PrefixOfWord(usize::MAX) + KeyPositionAdjacent::PrefixOfWord(usize::MAX) ); return Ok(Entry::Vacant(VacantEntry { @@ -620,7 +620,7 @@ impl<'a, V> OccupiedEntry<'a, V> { pub struct VacantEntry<'a, V> { parent: &'a mut NodeRef, key_hash: KeyHash, - key_position: KeyPositionAdjecent, + key_position: KeyPositionAdjacent, } impl<'a, V> VacantEntry<'a, V> { diff --git a/src/transaction/nodes.rs b/src/transaction/nodes.rs index 64b45f2..670aa30 100644 --- a/src/transaction/nodes.rs +++ b/src/transaction/nodes.rs @@ -267,13 +267,13 @@ impl fmt::Debug for Branch { #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)] pub enum KeyPosition { - Adjecent(KeyPositionAdjecent), + Adjacent(KeyPositionAdjacent), Right, Left, } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)] -pub enum KeyPositionAdjecent { +pub enum KeyPositionAdjacent { /// The delta bit occurs before the existing branch's discriminant bit in the same word. /// `branch.mask.word_idx() == PrefixOfWord(word_idx)`. PrefixOfWord(usize), @@ -303,7 +303,7 @@ impl Branch { .find(|(branch_word, (_, key_word))| branch_word != key_word); if let Some((_, (idx, _))) = prefix_diff { - return KeyPosition::Adjecent(KeyPositionAdjecent::PrefixVec(idx)); + return KeyPosition::Adjacent(KeyPositionAdjacent::PrefixVec(idx)); } // If sub wraps around to the last word, the prior word is 0. @@ -311,7 +311,7 @@ impl Branch { let prior_word = key_hash.0.get(prior_word_idx).unwrap_or(&0); if self.prior_word != *prior_word { - return KeyPosition::Adjecent(KeyPositionAdjecent::PriorWord(prior_word_idx)); + return KeyPosition::Adjacent(KeyPositionAdjacent::PriorWord(prior_word_idx)); } let hash_segment = key_hash.0[word_idx]; @@ -321,7 +321,7 @@ impl Branch { } else if self.mask.is_right_descendant(hash_segment) { KeyPosition::Right } else { - KeyPosition::Adjecent(KeyPositionAdjecent::PrefixOfWord(word_idx)) + KeyPosition::Adjacent(KeyPositionAdjacent::PrefixOfWord(word_idx)) } } @@ -369,7 +369,7 @@ impl Branch> { #[inline] pub(crate) fn new_adjacent_leaf( self: &mut Box, - key_position: KeyPositionAdjecent, + key_position: KeyPositionAdjacent, leaf: Box>, ) { self.new_adjacent_leaf_ret(key_position, leaf); @@ -378,15 +378,15 @@ impl Branch> { /// Store a new leaf adjacent to an existing branch. /// New branch will be stored in the old branch's Box. /// The old branch will be moved to a new Box, under the new branch. - // inline(always) is used to increace the odds of the compiler removing the return when unused. + // inline(always) is used to increase the odds of the compiler removing the return when unused. #[inline(always)] pub(crate) fn new_adjacent_leaf_ret<'a>( self: &'a mut Box, - key_position: KeyPositionAdjecent, + key_position: KeyPositionAdjacent, leaf: Box>, ) -> &'a mut Leaf { let (mask, prior_word, prefix, leaf_word) = match key_position { - KeyPositionAdjecent::PrefixOfWord(word_idx) => { + KeyPositionAdjacent::PrefixOfWord(word_idx) => { debug_assert_eq!(self.mask.word_idx(), word_idx); let branch_word = self.mask.left_prefix; @@ -414,7 +414,7 @@ impl Branch> { leaf_word, ) } - KeyPositionAdjecent::PriorWord(word_idx) => { + KeyPositionAdjacent::PriorWord(word_idx) => { debug_assert_eq!(word_idx, self.mask.word_idx() - 1); let branch_word = self.prior_word; @@ -429,7 +429,7 @@ impl Branch> { (mask, *prior_word, mem::take(&mut self.prefix), leaf_word) } - KeyPositionAdjecent::PrefixVec(word_idx) => { + KeyPositionAdjacent::PrefixVec(word_idx) => { debug_assert!(self.mask.word_idx() - word_idx >= 2); debug_assert!(!self.prefix.is_empty());