Skip to content

Commit

Permalink
chore: refactor update_version on tree
Browse files Browse the repository at this point in the history
  • Loading branch information
arriqaaq committed Oct 25, 2024
1 parent 62bb437 commit 03f45a7
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/art.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,16 @@ impl<P: KeyTrait, V: Clone> Tree<P, V> {
}
}

fn update_version(&mut self, version: u64) {
self.version = if version == 0 {
self.version + 1
} else if version > self.version {
version
} else {
self.version
};
}

fn insert_common(
&mut self,
key: &P,
Expand Down Expand Up @@ -1058,13 +1068,8 @@ impl<P: KeyTrait, V: Clone> Tree<P, V> {

self.root = Some(new_root);
self.size += 1;
self.version = if version == 0 {
self.version + 1
} else if version > self.version {
version
} else {
self.version
};
self.update_version(version);

Ok(())
}

Expand Down Expand Up @@ -1101,13 +1106,7 @@ impl<P: KeyTrait, V: Clone> Tree<P, V> {
)));
}
self.size += 1;
self.version = if version == 0 {
self.version + 1
} else if version > self.version {
version
} else {
self.version
};
self.update_version(version);

Ok(())
}
Expand Down

0 comments on commit 03f45a7

Please sign in to comment.