use std::{
+ cmp::Ordering,
collections::{HashMap, HashSet},
fmt::Debug,
- ops::{Bound, RangeBounds}, cmp::Ordering,
+ ops::{Bound, RangeBounds},
};
use encoding_rs::Encoding;
use crate::{
format::Spec,
identifier::{ByIdentifier, HasIdentifier, Identifier},
- raw::{Alignment, CategoryLabels, Measure, MissingValues, VarType, self, RawStr, Decoder},
+ raw::{self, Alignment, CategoryLabels, Decoder, Measure, MissingValues, RawStr, VarType},
};
pub type DictIndex = usize;
pub encoding: &'static Encoding,
}
+pub struct DuplicateVariableName;
+
impl Dictionary {
pub fn new(encoding: &'static Encoding) -> Self {
Self {
}
}
- pub fn add_var(&mut self, variable: Variable) -> Result<(), ()> {
+ pub fn add_var(&mut self, variable: Variable) -> Result<(), DuplicateVariableName> {
if self.variables.insert(ByIdentifier::new(variable)) {
Ok(())
} else {
- Err(())
+ Err(DuplicateVariableName)
}
}
if from_index != to_index {
self.variables.move_index(from_index, to_index);
self.update_dict_indexes(&|index| {
+ #[allow(clippy::collapsible_else_if)]
if index == from_index {
Some(to_index)
} else if from_index < to_index {
F: Fn(DictIndex) -> Option<DictIndex>,
{
update_dict_index_vec(&mut self.split_file, f);
- self.weight = self.weight.map(|index| f(index)).flatten();
- self.filter = self.filter.map(|index| f(index)).flatten();
+ self.weight = self.weight.and_then(f);
+ self.filter = self.filter.and_then(f);
self.vectors = self
.vectors
.drain()
vector_by_id
.0
.with_updated_dict_indexes(f)
- .map(|vector| ByIdentifier::new(vector))
+ .map(ByIdentifier::new)
})
.collect();
self.mrsets = self
mrset_by_id
.0
.with_updated_dict_indexes(f)
- .map(|mrset| ByIdentifier::new(mrset))
+ .map(ByIdentifier::new)
})
.collect();
self.variable_sets = self
var_set_by_id
.0
.with_updated_dict_indexes(f)
- .map(|var_set| ByIdentifier::new(var_set))
+ .map(ByIdentifier::new)
})
.collect();
}
alignment: Alignment::default_for_type(var_type),
leave,
short_names: Vec::new(),
- attributes: HashSet::new()
+ attributes: HashSet::new(),
}
}
}