feat: Introduce on the fly attributes reordering with meilidb-core

This commit is contained in:
Clément Renault
2019-06-24 17:29:14 +02:00
parent 97cc3c7cce
commit b7ed22bc59
3 changed files with 29 additions and 5 deletions

View File

@ -0,0 +1,20 @@
#[derive(Default)]
pub struct ReorderedAttrs {
count: usize,
reorders: Vec<Option<u16>>,
}
impl ReorderedAttrs {
pub fn insert_attribute(&mut self, attribute: u16) {
self.reorders.resize(attribute as usize + 1, None);
self.reorders[attribute as usize] = Some(self.count as u16);
self.count += 1;
}
pub fn get(&self, attribute: u16) -> Option<u16> {
match self.reorders.get(attribute as usize) {
Some(Some(attribute)) => Some(*attribute),
_ => None,
}
}
}