<commit_before>//pub const FINGERPRINT_SIZE: usize = 1;
pub const BUCKET_SIZE: usize = 4;

// Fingerprint Size is 1 byte so lets remove the Vec
#[derive(PartialEq, Copy, Clone)]
pub struct Fingerprint (pub u8);

pub struct Bucket (pub Vec<Fingerprint>);

impl Bucket {

    pub fn new() -> Bucket {
        Bucket(vec![])
    }

    pub fn insert(&mut self, fp: Fingerprint) -> bool {
        if self.0.len() < BUCKET_SIZE {
            self.0.push(fp);
            true
        } else {
            false
        }
    }

    pub fn delete(&mut self, fp: Fingerprint) -> bool {
        for i in 0..self.0.len() {
            if self.0[i] == fp {
                self.0.remove(i);
                return true;
            }
        }
        false
    }

    pub fn get_fingerprint_index(&mut self, fp: Fingerprint) -> usize {
        for i in 0..self.0.len() {
            if self.0[i] == fp {
                return i;
            }
        }
        BUCKET_SIZE + 1
    }
}<commit_msg>cleanup: Bucket `delete` and `new`<commit_after>//pub const FINGERPRINT_SIZE: usize = 1;
pub const BUCKET_SIZE: usize = 4;

// Fingerprint Size is 1 byte so lets remove the Vec
#[derive(PartialEq, Copy, Clone)]
pub struct Fingerprint (pub u8);

pub struct Bucket (pub Vec<Fingerprint>);

impl Bucket {

    pub fn new() -> Bucket {
        Bucket(Vec::with_capacity(BUCKET_SIZE))
    }

    pub fn insert(&mut self, fp: Fingerprint) -> bool {
        if self.0.len() < BUCKET_SIZE {
            self.0.push(fp);
            true
        } else {
            false
        }
    }

    /// Deletes the given fingerprint from the bucket. Since the order inside
    /// the bucket doesn't matter, we can use `swap_remove` to keep the runtime
    /// in O(1).
    pub fn delete(&mut self, fp: Fingerprint) -> bool {
        let pos = self.0.iter().position(|e| *e == fp);
        match pos {
            Some(index) => { self.0.swap_remove(index); true }
            None => false
        }
    }

    pub fn get_fingerprint_index(&mut self, fp: Fingerprint) -> usize {
        for i in 0..self.0.len() {
            if self.0[i] == fp {
                return i;
            }
        }
        BUCKET_SIZE + 1
    }
}
{'fraction_non_alphanumeric': 0.1230140717203813, 'fraction_numerical': 0.012256014525646845, 'mean_word_length': 1.6878048780487804, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '5344237', 'n_tokens_mistral': 731, 'n_tokens_neox': 716, 'n_words': 210}