pub(crate) fn insert(&mut self, nodes: &[Arc<N>]) -> Result<()> {
        let mut new = BTreeSet::new();
        for node in nodes {
            for vnid in 0..self.vnodes_per_node {
                let vn = VirtualNode::new(&mut self.hasher, Arc::clone(&node), vnid);
                // We need to not only check whether vn is already in the ring, but also whether
                // it is present among the vnodes we are about to extend the ring by.
                if self.vnodes.binary_search(&vn).is_ok() || !new.insert(vn.clone()) {
                    // FIXME: How to avoid cloning the VirtualNode ^ but also be able to use it in:
                    return Err(HashRingError::VirtualNodeAlreadyExists(format!("{}", vn)));
                }
                //trace!("vnode '{}' has been included in the ring extension", vn);
            }
        }
        // TODO: What happens with the reallocation here? It is completely uncontrolled for now.
        self.vnodes.extend(new);
        self.vnodes.sort_unstable();
        self.fix_replica_owners();
        Ok(())
    }
// First, initialize all vnodes for the given nodes into a new `BTreeSet`. Then, check whether
// any of them is already present in the current vnodes map to make sure no collision occurs.
// Finally, merge the new vnodes into the old ones.
//
// NOTE: If any of the newly created `VirtualNode`s collides with an already existing one,
// none of the new `nodes` is inserted in the ring.
First, initialize all vnodes for the given nodes into a new `BTreeSet`. Then, check whether
any of them is already present in the current vnodes map to make sure no collision occurs.
Finally, merge the new vnodes into the old ones.

If any of the newly created `VirtualNode`s collides with an already existing one,
none of the new `nodes` is inserted in the ring.
First initialize all vnodes for the given nodes into a new ` BTreeSet ` . Then check whether any of them is already present in the current vnodes map to make sure no collision occurs . Finally merge the new vnodes into the old ones . If any of the newly created ` VirtualNode ` s collides with an already existing one none of the new ` nodes ` is inserted in the ring .
pub(crate) fn insert(&mut self, nodes: &[Arc<N>]) -> Result<()> {
        let mut new = BTreeSet::new();
        for node in nodes {
            for vnid in 0..self.vnodes_per_node {
                let vn = VirtualNode::new(&mut self.hasher, Arc::clone(&node), vnid);
                // We need to not only check whether vn is already in the ring, but also whether
                // it is present among the vnodes we are about to extend the ring by.
                if self.vnodes.binary_search(&vn).is_ok() || !new.insert(vn.clone()) {
                    // FIXME: How to avoid cloning the VirtualNode ^ but also be able to use it in:
                    return Err(HashRingError::VirtualNodeAlreadyExists(format!("{}", vn)));
                }
                //trace!("vnode '{}' has been included in the ring extension", vn);
            }
        }
        // TODO: What happens with the reallocation here? It is completely uncontrolled for now.
        self.vnodes.extend(new);
        self.vnodes.sort_unstable();
        self.fix_replica_owners();
        Ok(())
    }
pub ( crate ) fn insert ( & mut self , nodes : & [ Arc < N > ] ) -> Result < ( ) > { let mut new = BTreeSet :: new ( ) ; for node in nodes { for vnid in 0 .. self . vnodes_per_node { let vn = VirtualNode :: new ( & mut self . hasher , Arc :: clone ( & node ) , vnid ) ; // We need to not only check whether vn is already in the ring, but also whether // it is present among the vnodes we are about to extend the ring by. if self . vnodes . binary_search ( & vn ) . is_ok ( ) || ! new . insert ( vn . clone ( ) ) { // FIXME: How to avoid cloning the VirtualNode ^ but also be able to use it in: return Err ( HashRingError :: VirtualNodeAlreadyExists ( format ! ( " " vn ) ) ) ; } //trace!("vnode '{}' has been included in the ring extension", vn); } } // TODO: What happens with the reallocation here? It is completely uncontrolled for now. self . vnodes . extend ( new ) ; self . vnodes . sort_unstable ( ) ; self . fix_replica_owners ( ) ; Ok ( ( ) ) }
First, initialize all vnodes for the given nodes into a new `BTreeSet`.
First initialize all vnodes for the given nodes into a new ` BTreeSet ` .
&mut self
nodes
&[Arc<N>]
&mut self
nodes
&[Arc<N>]