<commit_before>use hash_map::HashMap;
use core::hash;
use core::cmp;

pub type DispatchFn<T> = fn(&T) -> bool;


pub struct DispatchTable<T: cmp::Eq + hash::Hash> {
    table: HashMap<T, DispatchFn<T>>,
}

impl<T: cmp::Eq + hash::Hash> DispatchTable<T> {
    pub fn new(size: usize) -> Self {
        DispatchTable { table: HashMap::new(size) }
    }

    pub fn dispatch(&mut self, event: &T) -> bool {
        match self.table.get(event) {
            Some(func) => func(event),
            None => false,
        }
    }

    pub fn register(&mut self, event: T, func: DispatchFn<T>) {
        self.table.insert(event, func);
    }

    pub fn unregister(&mut self, event: T) {
        self.table.remove(event);
    }<commit_msg>Dispatch function does not need to be mut<commit_after>use hash_map::HashMap;
use core::hash;
use core::cmp;

pub type DispatchFn<T> = fn(&T) -> bool;


pub struct DispatchTable<T: cmp::Eq + hash::Hash> {
    table: HashMap<T, DispatchFn<T>>,
}

impl<T: cmp::Eq + hash::Hash> DispatchTable<T> {
    pub fn new(size: usize) -> Self {
        DispatchTable { table: HashMap::new(size) }
    }

    pub fn dispatch(&self, event: &T) -> bool {
        match self.table.get(event) {
            Some(func) => func(event),
            None => false,
        }
    }

    pub fn register(&mut self, event: T, func: DispatchFn<T>) {
        self.table.insert(event, func);
    }

    pub fn unregister(&mut self, event: T) {
        self.table.remove(event);
    }
{'fraction_non_alphanumeric': 0.1586021505376344, 'fraction_numerical': 0.0, 'mean_word_length': 2.6765432098765434, 'pattern_counts': {'":': 0, '<': 17, '<?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': '731335', 'n_tokens_mistral': 519, 'n_tokens_neox': 511, 'n_words': 128}