<commit_before>use std::collections::BTreeSet;
use std::collections::btree_set::Iter;
use std::iter::Iterator;
use super::entry::{Entry, Timestamp};

#[derive(Debug)]
pub struct Storage {
    entries: BTreeSet<Entry>,
}

impl Storage {
    pub fn new() -> Self {
        Storage { entries: BTreeSet::new() }
    }

    pub fn add_entry(&mut self, entry: Entry) {
        self.entries.insert(entry);
    }

    pub fn has_entry(&self, entry: &Entry) -> bool {
        self.entries.contains(entry)
    }

    pub fn remove_entry(&mut self, entry: &Entry) {
        self.entries.remove(entry);
    }

    pub fn expired_entries(&self) -> Vec<Entry> {
        let iter = ExpiredItems {
            iter: self.entries.iter(),
            timestamp: Timestamp::now(),
        };

        let mut entries = Vec::<Entry>::new();

        for entry in iter {
            entries.push(entry);
        }

        return entries;
    }
}

pub struct ExpiredItems<'a> {
    iter: Iter<'a, Entry>,
    timestamp: Timestamp,
}

impl<'a> Iterator for ExpiredItems<'a> {
    type Item = Entry;

    fn next(&mut self) -> Option<Entry> {
        let entry = maybe!(self.iter.next());

        if self.timestamp <= entry.timestamp() {<commit_msg>Make ExpiredItems iterator private<commit_after>use std::collections::BTreeSet;
use std::collections::btree_set::Iter;
use std::iter::Iterator;
use super::entry::{Entry, Timestamp};

#[derive(Debug)]
pub struct Storage {
    entries: BTreeSet<Entry>,
}

impl Storage {
    pub fn new() -> Self {
        Storage { entries: BTreeSet::new() }
    }

    pub fn add_entry(&mut self, entry: Entry) {
        self.entries.insert(entry);
    }

    pub fn has_entry(&self, entry: &Entry) -> bool {
        self.entries.contains(entry)
    }

    pub fn remove_entry(&mut self, entry: &Entry) {
        self.entries.remove(entry);
    }

    pub fn expired_entries(&self) -> Vec<Entry> {
        let iter = ExpiredItems {
            iter: self.entries.iter(),
            timestamp: Timestamp::now(),
        };

        let mut entries = Vec::<Entry>::new();

        for entry in iter {
            entries.push(entry);
        }

        return entries;
    }
}

struct ExpiredItems<'a> {
    iter: Iter<'a, Entry>,
    timestamp: Timestamp,
}

impl<'a> Iterator for ExpiredItems<'a> {
    type Item = Entry;

    fn next(&mut self) -> Option<Entry> {
        let entry = maybe!(self.iter.next());

        if self.timestamp <= entry.timestamp() {
{'fraction_non_alphanumeric': 0.14649939295831646, 'fraction_numerical': 0.0, 'mean_word_length': 2.546628407460545, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, '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': '3600322', 'n_tokens_mistral': 773, 'n_tokens_neox': 768, 'n_words': 186}