work
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 7 Jan 2024 23:33:57 +0000 (15:33 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 7 Jan 2024 23:33:57 +0000 (15:33 -0800)
rust/src/dictionary.rs
rust/src/raw.rs

index e9eca118abe71218f8122e70629eccfcf820500f..4a8e272116a4d667151c8f06f05b8ec1f6986e37 100644 (file)
@@ -26,7 +26,7 @@ pub struct Dictionary {
     pub file_label: Option<String>,
     pub documents: Vec<String>,
     pub vectors: HashSet<ByIdentifier<Vector>>,
-    pub attributes: HashSet<ByIdentifier<Attribute>>,
+    pub attributes: HashMap<Identifier, Vec<String>>,
     pub mrsets: HashSet<ByIdentifier<MultipleResponseSet>>,
     pub variable_sets: HashSet<ByIdentifier<VariableSet>>,
     pub encoding: &'static Encoding,
@@ -43,7 +43,7 @@ impl Dictionary {
             file_label: None,
             documents: Vec::new(),
             vectors: HashSet::new(),
-            attributes: HashSet::new(),
+            attributes: HashMap::new(),
             mrsets: HashSet::new(),
             variable_sets: HashSet::new(),
             encoding,
index 986bb92a52bb389726c8875582130305aa3772d2..65b0f9474cf8326c98af843c7f4b95e894633749 100644 (file)
@@ -11,7 +11,7 @@ use std::{
     borrow::Cow,
     cell::RefCell,
     cmp::Ordering,
-    collections::VecDeque,
+    collections::{VecDeque, HashMap},
     fmt::{Debug, Display, Formatter, Result as FmtResult},
     io::{Error as IoError, Read, Seek, SeekFrom},
     iter::repeat,
@@ -246,6 +246,8 @@ impl Record {
             }),
         }
     }
+
+    
 }
 
 // If `s` is valid UTF-8, returns it decoded as UTF-8, otherwise returns it
@@ -2093,7 +2095,7 @@ impl TextRecord {
             text: extension.data.into(),
         }
     }
-    fn decode<'a>(&self, decoder: &Decoder) -> Result<Option<Record>, Error> {
+    pub fn decode<'a>(&self, decoder: &Decoder) -> Result<Option<Record>, Error> {
         match self.rec_type {
             TextRecordType::VariableSets => Ok(Some(Record::VariableSets(
                 VariableSetRecord::decode(self, decoder),
@@ -2194,7 +2196,7 @@ impl Attribute {
 }
 
 #[derive(Clone, Debug)]
-pub struct AttributeSet(pub Vec<Attribute>);
+pub struct AttributeSet(pub HashMap<Identifier, Vec<String>>);
 
 impl AttributeSet {
     fn parse<'a>(
@@ -2202,14 +2204,15 @@ impl AttributeSet {
         mut input: &'a str,
         sentinel: Option<char>,
     ) -> Result<(AttributeSet, &'a str), Error> {
-        let mut attributes = Vec::new();
+        let mut attributes = HashMap::new();
         let rest = loop {
             match input.chars().next() {
                 None => break input,
                 c if c == sentinel => break &input[1..],
                 _ => {
                     let (attribute, rest) = Attribute::parse(decoder, input)?;
-                    attributes.push(attribute);
+                    // XXX report duplicate name
+                    attributes.insert(attribute.name, attribute.values);
                     input = rest;
                 }
             }