diff --git a/src/model/cell.rs b/src/model/cell.rs index c74cd39..e1cca01 100644 --- a/src/model/cell.rs +++ b/src/model/cell.rs @@ -1,3 +1,4 @@ +use indexmap::IndexMap; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; @@ -104,8 +105,9 @@ pub struct InternedKey(pub Vec<(Symbol, Symbol)>); /// to implement the `Serialize`-as-string requirement for JSON object keys. #[derive(Debug, Clone, Default)] pub struct DataStore { - /// Primary storage — interned keys for O(1) hash/compare. - cells: HashMap, + /// Primary storage — interned keys, insertion-ordered so records mode + /// can display rows in the order they were entered. + cells: IndexMap, /// String interner — all category/item names are interned here. pub symbols: SymbolTable, /// Secondary index: interned (category, item) → set of interned keys. @@ -193,7 +195,7 @@ impl DataStore { let Some(ikey) = self.lookup_key(key) else { return; }; - if self.cells.remove(&ikey).is_some() { + if self.cells.shift_remove(&ikey).is_some() { for pair in &ikey.0 { if let Some(set) = self.index.get_mut(pair) { set.remove(&ikey);