pub fn push(&mut self, mut cidr: Ipv6Cidr) {
        if let Err(mut index) = self.cidr_array.binary_search(&cidr) {
            if self.cidr_array.is_empty() {
                self.cidr_array.push(cidr);
            } else {
                let pushable = if index == 0 {
                    true
                } else {
                    let previous_cidr = self.cidr_array.get(index - 1).unwrap();

                    !previous_cidr.contains(&cidr.first())
                };

                if pushable {
                    loop {
                        if index == self.cidr_array.len() {
                            break;
                        }

                        let next = self.cidr_array.get(index).unwrap();

                        if cidr.contains(next.first()) {
                            self.cidr_array.remove(index);
                        } else {
                            break;
                        }
                    }

                    let mut merging = true;

                    while merging {
                        merging = false;

                        if index < self.cidr_array.len() {
                            let next_cidr = self.cidr_array.get(index).unwrap();

                            let next_bits = next_cidr.get_bits();
                            let bits = cidr.get_bits();

                            if bits == next_bits {
                                let next_prefix = next_cidr.get_prefix();
                                let prefix = cidr.get_prefix();

                                let d = next_prefix ^ prefix;

                                let bits_dec_u128 = u128::from(bits - 1);

                                if d == 1 << ((bits_dec_u128 / 8) * 8 + 7) >> (bits_dec_u128 % 8) {
                                    cidr =
                                        Ipv6Cidr::from_prefix_and_bits(prefix, bits - 1).unwrap();

                                    self.cidr_array.remove(index);

                                    merging = true;
                                }
                            }
                        }

                        if index > 0 {
                            let index_dec = index - 1;

                            let previous_cidr = self.cidr_array.get_mut(index_dec).unwrap();

                            let previous_bits = previous_cidr.get_bits();
                            let bits = cidr.get_bits();

                            if bits == previous_bits {
                                let previous_prefix = previous_cidr.get_prefix();
                                let prefix = cidr.get_prefix();

                                let d = prefix ^ previous_prefix;

                                let bits_dec_u128 = u128::from(bits - 1);

                                if d == 1 << ((bits_dec_u128 / 8) * 8 + 7) >> (bits_dec_u128 % 8) {
                                    self.cidr_array.remove(index_dec);

                                    index = index_dec;

                                    cidr = Ipv6Cidr::from_prefix_and_bits(
                                        previous_prefix,
                                        previous_bits - 1,
                                    )
                                    .unwrap();

                                    merging = true;
                                }
                            }
                        }
                    }

                    self.cidr_array.insert(index, cidr);
                }
            }
        }
    }
/// Push a CIDR into this combiner.
Push a CIDR into this combiner.
Push a CIDR into this combiner .
pub fn push(&mut self, mut cidr: Ipv6Cidr) {
        if let Err(mut index) = self.cidr_array.binary_search(&cidr) {
            if self.cidr_array.is_empty() {
                self.cidr_array.push(cidr);
            } else {
                let pushable = if index == 0 {
                    true
                } else {
                    let previous_cidr = self.cidr_array.get(index - 1).unwrap();
                    !previous_cidr.contains(&cidr.first())
                };
                if pushable {
                    loop {
                        if index == self.cidr_array.len() {
                            break;
                        }
                        let next = self.cidr_array.get(index).unwrap();
                        if cidr.contains(next.first()) {
                            self.cidr_array.remove(index);
                        } else {
                            break;
                        }
                    }
                    let mut merging = true;
                    while merging {
                        merging = false;
                        if index < self.cidr_array.len() {
                            let next_cidr = self.cidr_array.get(index).unwrap();
                            let next_bits = next_cidr.get_bits();
                            let bits = cidr.get_bits();
                            if bits == next_bits {
                                let next_prefix = next_cidr.get_prefix();
                                let prefix = cidr.get_prefix();
                                let d = next_prefix ^ prefix;
                                let bits_dec_u128 = u128::from(bits - 1);
                                if d == 1 << ((bits_dec_u128 / 8) * 8 + 7) >> (bits_dec_u128 % 8) {
                                    cidr =
                                        Ipv6Cidr::from_prefix_and_bits(prefix, bits - 1).unwrap();
                                    self.cidr_array.remove(index);
                                    merging = true;
                                }
                            }
                        }
                        if index > 0 {
                            let index_dec = index - 1;
                            let previous_cidr = self.cidr_array.get_mut(index_dec).unwrap();
                            let previous_bits = previous_cidr.get_bits();
                            let bits = cidr.get_bits();
                            if bits == previous_bits {
                                let previous_prefix = previous_cidr.get_prefix();
                                let prefix = cidr.get_prefix();
                                let d = prefix ^ previous_prefix;
                                let bits_dec_u128 = u128::from(bits - 1);
                                if d == 1 << ((bits_dec_u128 / 8) * 8 + 7) >> (bits_dec_u128 % 8) {
                                    self.cidr_array.remove(index_dec);
                                    index = index_dec;
                                    cidr = Ipv6Cidr::from_prefix_and_bits(
                                        previous_prefix,
                                        previous_bits - 1,
                                    )
                                    .unwrap();
                                    merging = true;
                                }
                            }
                        }
                    }
                    self.cidr_array.insert(index, cidr);
                }
            }
        }
    }
pub fn push ( & mut self , mut cidr : Ipv6Cidr ) { if let Err ( mut index ) = self . cidr_array . binary_search ( & cidr ) { if self . cidr_array . is_empty ( ) { self . cidr_array . push ( cidr ) ; } else { let pushable = if index == 0 { true } else { let previous_cidr = self . cidr_array . get ( index - 1 ) . unwrap ( ) ; ! previous_cidr . contains ( & cidr . first ( ) ) } ; if pushable { loop { if index == self . cidr_array . len ( ) { break ; } let next = self . cidr_array . get ( index ) . unwrap ( ) ; if cidr . contains ( next . first ( ) ) { self . cidr_array . remove ( index ) ; } else { break ; } } let mut merging = true ; while merging { merging = false ; if index < self . cidr_array . len ( ) { let next_cidr = self . cidr_array . get ( index ) . unwrap ( ) ; let next_bits = next_cidr . get_bits ( ) ; let bits = cidr . get_bits ( ) ; if bits == next_bits { let next_prefix = next_cidr . get_prefix ( ) ; let prefix = cidr . get_prefix ( ) ; let d = next_prefix ^ prefix ; let bits_dec_u128 = u128 :: from ( bits - 1 ) ; if d == 1 << ( ( bits_dec_u128 / 8 ) * 8 + 7 ) >> ( bits_dec_u128 % 8 ) { cidr = Ipv6Cidr :: from_prefix_and_bits ( prefix , bits - 1 ) . unwrap ( ) ; self . cidr_array . remove ( index ) ; merging = true ; } } } if index > 0 { let index_dec = index - 1 ; let previous_cidr = self . cidr_array . get_mut ( index_dec ) . unwrap ( ) ; let previous_bits = previous_cidr . get_bits ( ) ; let bits = cidr . get_bits ( ) ; if bits == previous_bits { let previous_prefix = previous_cidr . get_prefix ( ) ; let prefix = cidr . get_prefix ( ) ; let d = prefix ^ previous_prefix ; let bits_dec_u128 = u128 :: from ( bits - 1 ) ; if d == 1 << ( ( bits_dec_u128 / 8 ) * 8 + 7 ) >> ( bits_dec_u128 % 8 ) { self . cidr_array . remove ( index_dec ) ; index = index_dec ; cidr = Ipv6Cidr :: from_prefix_and_bits ( previous_prefix , previous_bits - 1 , ) . unwrap ( ) ; merging = true ; } } } } self . cidr_array . insert ( index , cidr ) ; } } } }
Push a CIDR into this combiner.
Push a CIDR into this combiner .
&mut self
cidr
Ipv6Cidr
&mut self
cidr
Ipv6Cidr