Skip to content

Commit

Permalink
add a batch_add feature to avoid sort for each virtual node addition
Browse files Browse the repository at this point in the history
  • Loading branch information
Di Zhao committed Oct 19, 2023
1 parent d4f749f commit 82f6b09
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ impl<T: Hash, S: BuildHasher> HashRing<T, S> {
self.ring.sort();
}

pub fn batch_add(&mut self, nodes:Vec<T> ) {
for node in nodes {
let key = get_key(&self.hash_builder, &node);
self.ring.push(Node::new(key, node));
}
self.ring.sort()
}

/// Remove `node` from the hash ring. Returns an `Option` that will contain the `node`
/// if it was in the hash ring or `None` if it was not present.
pub fn remove(&mut self, node: &T) -> Option<T> {
Expand Down

0 comments on commit 82f6b09

Please sign in to comment.