2019-08-16 22:35:19 +08:00
|
|
|
#[derive(Default, Clone)]
|
2019-06-24 23:29:14 +08:00
|
|
|
pub struct ReorderedAttrs {
|
|
|
|
count: usize,
|
|
|
|
reorders: Vec<Option<u16>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ReorderedAttrs {
|
2019-07-01 20:34:06 +08:00
|
|
|
pub fn new() -> ReorderedAttrs {
|
2019-10-18 19:05:28 +08:00
|
|
|
ReorderedAttrs {
|
|
|
|
count: 0,
|
|
|
|
reorders: Vec::new(),
|
|
|
|
}
|
2019-07-01 20:34:06 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 23:29:14 +08:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|