pub fn truncate(&mut self, new_len: usize) {
        if new_len >= self.len() {
            return
        }

        for i in 0 .. new_len {
            let parent = self.meta[i].parent();
            let mut current = self.meta[i].link();
            if parent >= new_len {
                // We make `i` the new root.
                self.meta[i].set_parent(i);
                self.meta[i].set_rank(1);

                let mut previous = i;
                // The last index we saw before we went out of the new bounds.
                let mut index_before_oob = if current >= new_len {
                    Some(previous)
                } else {
                    None
                };

                while current != i {
                    if current >= new_len {
                        // If the current is above the new length we update this value if needed.
                        if index_before_oob.is_none() {
                            index_before_oob = Some(previous);
                        }
                    } else if let Some(index) = index_before_oob {
                        // If we are back in bounds for the first time we update the link.
                        self.meta[index].set_link(current);
                        index_before_oob = None;
                    }

                    self.meta[current].set_parent(i);

                    previous = current;
                    current = self.meta[current].link();
                }

                if let Some(index) = index_before_oob {
                    self.meta[index].set_link(i);
                }
            } else if current >= new_len {
                while current >= new_len {
                    current = self.meta[current].link();
                }
                self.meta[i].set_link(current);
            }
        }

        self.data.truncate(new_len);
        self.meta.truncate(new_len);
    }
/// Shortens the `PartitionVec<T>`, keeping the first `new_len` elements and
/// dropping the rest.
///
/// If `new_len` is greater than or equal to the collections current length,
/// this has no effect.
///
/// Note that this method has no effect on the allocated capacity of the
/// collection.
///
/// # Examples
///
/// ```
/// # #[macro_use]
/// # extern crate partitions;
/// #
/// # fn main() {
/// let mut partition_vec = partition_vec![
///     'a' => 0,
///     'b' => 1,
///     'c' => 0,
///     'd' => 1,
///     'e' => 2,
/// ];
///
/// partition_vec.truncate(3);
/// assert!(partition_vec.len() == 3);
/// assert!(partition_vec.capacity() == 5);
/// assert!(partition_vec.len_of_set(0) == 2);
/// assert!(partition_vec.len_of_set(1) == 1);
/// assert!(partition_vec.len_of_set(2) == 2);
/// # }
/// ```
Shortens the `PartitionVec`, keeping the first `new_len` elements and
dropping the rest.

If `new_len` is greater than or equal to the collections current length,
this has no effect.

Note that this method has no effect on the allocated capacity of the
collection.
Shortens the ` PartitionVec ` keeping the first ` new_len ` elements and dropping the rest . If ` new_len ` is greater than or equal to the collections current length this has no effect . Note that this method has no effect on the allocated capacity of the collection .
pub fn truncate(&mut self, new_len: usize) {
        if new_len >= self.len() {
            return
        }
        for i in 0 .. new_len {
            let parent = self.meta[i].parent();
            let mut current = self.meta[i].link();
            if parent >= new_len {
                // We make `i` the new root.
                self.meta[i].set_parent(i);
                self.meta[i].set_rank(1);
                let mut previous = i;
                // The last index we saw before we went out of the new bounds.
                let mut index_before_oob = if current >= new_len {
                    Some(previous)
                } else {
                    None
                };
                while current != i {
                    if current >= new_len {
                        // If the current is above the new length we update this value if needed.
                        if index_before_oob.is_none() {
                            index_before_oob = Some(previous);
                        }
                    } else if let Some(index) = index_before_oob {
                        // If we are back in bounds for the first time we update the link.
                        self.meta[index].set_link(current);
                        index_before_oob = None;
                    }
                    self.meta[current].set_parent(i);
                    previous = current;
                    current = self.meta[current].link();
                }
                if let Some(index) = index_before_oob {
                    self.meta[index].set_link(i);
                }
            } else if current >= new_len {
                while current >= new_len {
                    current = self.meta[current].link();
                }
                self.meta[i].set_link(current);
            }
        }
        self.data.truncate(new_len);
        self.meta.truncate(new_len);
    }
pub fn truncate ( & mut self , new_len : usize ) { if new_len >= self . len ( ) { return } for i in 0 .. new_len { let parent = self . meta [ i ] . parent ( ) ; let mut current = self . meta [ i ] . link ( ) ; if parent >= new_len { // We make `i` the new root. self . meta [ i ] . set_parent ( i ) ; self . meta [ i ] . set_rank ( 1 ) ; let mut previous = i ; // The last index we saw before we went out of the new bounds. let mut index_before_oob = if current >= new_len { Some ( previous ) } else { None } ; while current != i { if current >= new_len { // If the current is above the new length we update this value if needed. if index_before_oob . is_none ( ) { index_before_oob = Some ( previous ) ; } } else if let Some ( index ) = index_before_oob { // If we are back in bounds for the first time we update the link. self . meta [ index ] . set_link ( current ) ; index_before_oob = None ; } self . meta [ current ] . set_parent ( i ) ; previous = current ; current = self . meta [ current ] . link ( ) ; } if let Some ( index ) = index_before_oob { self . meta [ index ] . set_link ( i ) ; } } else if current >= new_len { while current >= new_len { current = self . meta [ current ] . link ( ) ; } self . meta [ i ] . set_link ( current ) ; } } self . data . truncate ( new_len ) ; self . meta . truncate ( new_len ) ; }
Shortens the `PartitionVec<T>`, keeping the first `new_len` elements and
dropping the rest.
Shortens the ` PartitionVec<T > ` keeping the first ` new_len ` elements and dropping the rest .
&mut self
new_len
usize
&mut self
new_len
usize
examples
None
#[macro_use]
None
extern crate partitions;
None
fn main() {


partition_vec.truncate(3);
assert!(partition_vec.len() == 3);
assert!(partition_vec.capacity() == 5);
assert!(partition_vec.len_of_set(0) == 2);
assert!(partition_vec.len_of_set(1) == 1);
assert!(partition_vec.len_of_set(2) == 2).
partition_vec . truncate ( 3 ) ; assert! ( partition_vec . len () == 3 ) ; assert! ( partition_vec . capacity () == 5 ) ; assert! ( partition_vec . len_of_set ( 0 ) == 2 ) ; assert! ( partition_vec . len_of_set ( 1 ) == 1 ) ; assert! ( partition_vec . len_of_set ( 2 ) == 2 ) .
}
None