<commit_before>

use std::ops::Add;
use std::ops::Sub;
//use std::ops::Mul;
use std::cmp;

#[derive(Debug, Eq)]
pub struct BaseN {
    pub base: usize,
    pub vec: Vec<u8>
}

impl BaseN {

    /// Creates new BaseN 
    pub fn new(base: usize) -> BaseN/*<T>*/ {
        BaseN { base: base, vec: Vec::new() }
    }

    /// Creates new BaseN with initial vector capacity
    pub fn with_capacity(base: usize, capacity: usize) -> BaseN {
        BaseN { base: base, vec: Vec::with_capacity(capacity) }
    }

    /// Creates new BaseN with existing base and vec
    pub fn with_existing(base: usize, vec: Vec<u8>) -> BaseN {
        BaseN { base: base, vec: vec }
    }

    /// Creates a new BaseN from usize value
    pub fn from_usize(base: usize, val: usize) -> Result<BaseN, &'static str> {

        let mut new_vec:Vec<u8> = Vec::new();
        let mut val10: usize = val;
        loop {
            let val = val10 / base;
            match val {
                0 => {
                    new_vec.push(val10 as u8);
                    break;
                }
                _ => {
                    let remainder = val10 % base;
                    //println!("{}", remainder);
                    new_vec.push(remainder as u8);
                    val10 = val;
                }
            }
        }
        let new_basen: BaseN = BaseN { base: base, vec: new_vec };

        Ok(new_basen)
    }

    /// Converts existing mutable BaseN to new base
    pub fn to_base_mut(&mut self, new_base: usize) -> Result<bool, &'static str> {

        if self.base == new_base {
            return Ok(true);
        }

        let mut val10: usize = self.to_usize().unwrap();

        loop {
            let val = val10 / new_base;
            match val {
                0 => {
                    self.vec.push(val10 as u8);
                    break;
                }
                _ => {
                    let remainder = val10 % new_base;
                    self.vec.push(remainder as u8);
                    val10 = val;
                }
            }
        }

        Ok(true)
    }


    /// Converts to a new BaseN copy
    pub fn to_base(&self, new_base: usize) -> Result<BaseN, &'static str> {

        //TODO: If base is same, just return existing??
        if self.base == new_base {
            return Ok(self.clone());
        }

        // TODO: Create copy, convert mutable, or both?
        //let new_basen = BaseN::new(new_base);

        //println!("converting base {} to base {}", self.base, new_base);
        let val10: usize = self.to_usize().unwrap();
        //println!("{}", val10);

        BaseN::from_usize(new_base, val10)
        
    }

    /// Converts existing BaseN to a usize
    pub fn to_usize(&self) -> Result<usize, &'static str> {
        let mut val10: usize = 0;
        for (i, x) in self.vec.iter().enumerate() {
            val10 = val10 + (*x as usize) * self.base.pow(i as u32);
        }
        Ok(val10)
    }

}

//impl Copy for BaseN { }

impl PartialEq for BaseN {
    fn eq(&self, other: &BaseN) -> bool {
        (self.vec == other.vec)
            && (self.base == other.base)
    }
}

impl Clone for BaseN {
    fn clone(&self) -> Self {
        BaseN { base: self.base, vec: self.vec.clone() }
    }

    fn clone_from(&mut self, source: &Self) {
        self.vec.clone_from(&source.vec);
        self.base = source.base;
    }
}<commit_msg>Implement eq for different bases<commit_after>

use std::ops::Add;
use std::ops::Sub;
//use std::ops::Mul;
use std::cmp;

#[derive(Debug, Eq)]
pub struct BaseN {
    pub base: usize,
    pub vec: Vec<u8>
}

impl BaseN {

    /// Creates new BaseN 
    pub fn new(base: usize) -> BaseN/*<T>*/ {
        BaseN { base: base, vec: Vec::new() }
    }

    /// Creates new BaseN with initial vector capacity
    pub fn with_capacity(base: usize, capacity: usize) -> BaseN {
        BaseN { base: base, vec: Vec::with_capacity(capacity) }
    }

    /// Creates new BaseN with existing base and vec
    pub fn with_existing(base: usize, vec: Vec<u8>) -> BaseN {
        BaseN { base: base, vec: vec }
    }

    /// Creates a new BaseN from usize value
    pub fn from_usize(base: usize, val: usize) -> Result<BaseN, &'static str> {

        let mut new_vec:Vec<u8> = Vec::new();
        let mut val10: usize = val;
        loop {
            let val = val10 / base;
            match val {
                0 => {
                    new_vec.push(val10 as u8);
                    break;
                }
                _ => {
                    let remainder = val10 % base;
                    //println!("{}", remainder);
                    new_vec.push(remainder as u8);
                    val10 = val;
                }
            }
        }
        let new_basen: BaseN = BaseN { base: base, vec: new_vec };

        Ok(new_basen)
    }

    /// Converts existing mutable BaseN to new base
    pub fn to_base_mut(&mut self, new_base: usize) -> Result<bool, &'static str> {

        if self.base == new_base {
            return Ok(true);
        }

        let mut val10: usize = self.to_usize().unwrap();

        loop {
            let val = val10 / new_base;
            match val {
                0 => {
                    self.vec.push(val10 as u8);
                    break;
                }
                _ => {
                    let remainder = val10 % new_base;
                    self.vec.push(remainder as u8);
                    val10 = val;
                }
            }
        }

        Ok(true)
    }


    /// Converts to a new BaseN copy
    pub fn to_base(&self, new_base: usize) -> Result<BaseN, &'static str> {

        //TODO: If base is same, just return existing??
        if self.base == new_base {
            return Ok(self.clone());
        }

        // TODO: Create copy, convert mutable, or both?
        //let new_basen = BaseN::new(new_base);

        //println!("converting base {} to base {}", self.base, new_base);
        let val10: usize = self.to_usize().unwrap();
        //println!("{}", val10);

        BaseN::from_usize(new_base, val10)
        
    }

    /// Converts existing BaseN to a usize
    pub fn to_usize(&self) -> Result<usize, &'static str> {
        let mut val10: usize = 0;
        for (i, x) in self.vec.iter().enumerate() {
            val10 = val10 + (*x as usize) * self.base.pow(i as u32);
        }
        Ok(val10)
    }

}

//impl Copy for BaseN { }

impl PartialEq for BaseN {
    fn eq(&self, other: &BaseN) -> bool {
        if self.base == other.base {
            (self.vec == other.vec)
        } else {
            self.vec == other.to_base(self.base).unwrap().vec

        }
    }
}

impl Clone for BaseN {
    fn clone(&self) -> Self {
        BaseN { base: self.base, vec: self.vec.clone() }
    }

    fn clone_from(&mut self, source: &Self) {
        self.vec.clone_from(&source.vec);
        self.base = source.base;
    }
}
{'fraction_non_alphanumeric': 0.13067281371560294, 'fraction_numerical': 0.013254574268837343, 'mean_word_length': 1.4962243797195254, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2676210', 'n_tokens_mistral': 2256, 'n_tokens_neox': 2191, 'n_words': 604}