From: Ben Pfaff Date: Sat, 19 Aug 2023 21:06:50 +0000 (-0700) Subject: work X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6313b8dfb4ecd8257cf552bf58d5c030f7175825;p=pspp work --- diff --git a/rust/src/cooked.rs b/rust/src/cooked.rs index e0a7ef1fea..3c0d2e4ff6 100644 --- a/rust/src/cooked.rs +++ b/rust/src/cooked.rs @@ -1,13 +1,13 @@ -use std::{borrow::Cow, collections::HashSet}; +use std::{borrow::Cow, collections::{HashSet, HashMap}}; use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use encoding_rs::Encoding; - +use num::integer::div_ceil; use crate::{ format::{Spec, UncheckedSpec, Width}, identifier::{Error as IdError, Identifier}, raw::{self, MissingValues}, - {endian::Endian, CategoryLabels, Compression}, + {endian::Endian, Compression}, }; use thiserror::Error as ThisError; @@ -37,6 +37,8 @@ pub struct Decoder { pub endian: Endian, pub encoding: &'static Encoding, pub var_names: HashSet, + pub dict_indexes: HashMap, + n_dict_indexes: usize, n_generated_names: usize, } @@ -55,6 +57,17 @@ impl Decoder { assert!(self.n_generated_names < usize::MAX); } } + fn take_dict_indexes(&mut self, id: &Identifier, width: Width) -> usize { + let n = match width { + 0 => 1, + w => div_ceil(w, 8) as usize, + }; + let dict_index = self.n_dict_indexes; + self.dict_indexes.insert(self.n_dict_indexes, id.clone()); + self.n_dict_indexes += n; + dict_index + + } fn decode_string<'a>(&self, input: &'a [u8], warn: &impl Fn(Error)) -> Cow<'a, str> { let (output, malformed) = self.encoding.decode_without_bom_handling(input); if malformed { @@ -165,6 +178,7 @@ impl Variable { .label .as_ref() .map(|label| decoder.decode_string(&label.0, &warn).into()); + decoder.take_dict_indexes(&name, width); Ok(Some(Variable { width, name, @@ -430,25 +444,6 @@ impl TextRecord for VariableAttributeRecord { } } -#[derive(Clone, Debug)] -pub enum MultipleResponseType { - MultipleDichotomy { - value: String, - labels: CategoryLabels, - }, - MultipleCategory, -} -#[derive(Clone, Debug)] -pub struct MultipleResponseSet { - pub name: String, - pub label: String, - pub mr_type: MultipleResponseType, - pub vars: Vec, -} - -#[derive(Clone, Debug)] -pub struct MultipleResponseRecord(Vec); - pub enum Measure { Nominal, Ordinal,