use crate::feature::Rnum;
use std::collections::HashMap;
pub struct JoinPool {
counter: u16,
mapping: HashMap<(usize, usize), u16>,
}
impl JoinPool {
pub fn new() -> Self {
Self {
counter: 1,
mapping: HashMap::new(),
}
}
pub fn hit(&mut self, sid: usize, tid: usize) -> Rnum {
let key = if sid < tid { (sid, tid) } else { (tid, sid) };
let num = *self.mapping.entry(key).or_insert_with(|| {
let n = self.counter;
self.counter += 1;
n
});
Rnum::new(num as u8)
}
}