}
for dict_index in dict_indexes {
- let mut variable = &dictionary.variables[dict_index];
+ let variable = dictionary.variables.get_index_mut2(dict_index).unwrap();
for ValueLabel { value, label } in record.labels.iter().cloned() {
let value = match value {
raw::Value::Number(number) => Value::Number(number.map(|n| n.into())),
string.0[..variable.width.as_string_width().unwrap()].into()
}
};
+ variable.value_labels.insert(value, label);
}
}
}
}
}
+impl Hash for Value {
+ fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
+ match self {
+ Value::Number(number) => number.map(|x| OrderedFloat(x)).hash(state),
+ Value::String(string) => string.hash(state),
+ }
+ }
+}
+
impl Value {
- fn sysmis() -> Self {
+ pub fn sysmis() -> Self {
Self::Number(None)
}
}
cmp::Ordering,
fmt::{Debug, Display, Formatter, Result as FmtResult},
hash::{Hash, Hasher},
- ops::Deref,
+ ops::{Deref, DerefMut},
};
use encoding_rs::{EncoderResult, Encoding, UTF_8};
&self.0
}
}
+
+impl<T> DerefMut for ByIdentifier<T>
+where
+ T: HasIdentifier + Clone,
+{
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.0
+ }
+}
}
let headers = Headers::new(decoded_records, &|e| eprintln!("{e}"))?;
let (dictionary, metadata) = decode(headers, encoding, |e| eprintln!("{e}"))?;
- println!("{dictionary:?}");
- println!("{metadata:?}");
+ println!("{dictionary:#?}");
+ println!("{metadata:#?}");
}
}
let index_offset = r.stream_position()?;
let mut dict_indexes = Vec::with_capacity(n as usize);
let mut invalid_indexes = Vec::new();
+ let valid_range = 1..=var_types.len();
for _ in 0..n {
let index: u32 = endian.parse(read_bytes(r)?);
- if index == 0 || index as usize > var_types.len() {
+ if valid_range.contains(&(index as usize)) {
dict_indexes.push(index);
} else {
invalid_indexes.push(index);