From ded35f705c7cfed2050e1e938cb1230ca2bc1a96 Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Wed, 15 Apr 2026 21:32:35 -0700 Subject: [PATCH] feat(model): use IndexMap for deterministic insertion order in DataStore Replace `HashMap` with `IndexMap` in `DataStore::cells` to preserve insertion order. This allows records mode to display rows in the order they were added. Update `remove` to use `shift_remove` to maintain order during deletions. Co-Authored-By: fiddlerwoaroof/git-smart-commit (gemma-4-26B-A4B-it-UD-Q5_K_XL.gguf) --- src/model/cell.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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);