store: convert more callers to use RELS index

Convert remaining Vec users to index-based access:
- memory.rs: MemoryNode::from_store uses Store::neighbors()
- graph.rs: orphan detection uses for_each_relation
- local.rs: normalize_strengths uses for_each_relation + set_link_strength

Add Store::neighbors() method and index::get_offsets_for_uuid().

Cleanup:
- for_each_relation: build both uuid↔key maps in one pass
- cap_degree: consolidate key/uuid/degree collection

Remaining Vec uses: admin.rs (fsck, dedup), capnp.rs (load path).

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2026-04-13 21:19:47 -04:00
parent 5fe51fbfda
commit 5832e57970
8 changed files with 109 additions and 81 deletions

View file

@ -34,30 +34,24 @@ impl MemoryNode {
.and_then(|s| s.parse().ok())
.unwrap_or(0);
let mut neighbors: std::collections::HashMap<&str, (f32, bool)> = std::collections::HashMap::new();
for r in &store.relations {
if r.deleted { continue; }
let neighbor_key = if r.source_key == key {
&r.target_key
} else if r.target_key == key {
&r.source_key
} else {
continue;
};
// Get neighbors via index
let mut neighbors: std::collections::HashMap<String, (f32, bool)> = std::collections::HashMap::new();
if let Ok(neighbor_list) = store.neighbors(key) {
for (neighbor_key, strength) in neighbor_list {
let is_new = older_than > 0 && store.get_node(&neighbor_key)
.ok()
.flatten()
.map(|n| n.created_at > older_than)
.unwrap_or(false);
let is_new = older_than > 0 && store.get_node(neighbor_key)
.ok()
.flatten()
.map(|n| n.created_at > older_than)
.unwrap_or(false);
let e = neighbors.entry(neighbor_key.as_str()).or_insert((0.0, false));
e.0 = e.0.max(r.strength);
e.1 = e.1 || is_new;
let e = neighbors.entry(neighbor_key).or_insert((0.0, false));
e.0 = e.0.max(strength);
e.1 = e.1 || is_new;
}
}
let mut links: Vec<(String, f32, bool)> = neighbors.into_iter()
.map(|(k, (s, new))| (k.to_string(), s, new))
.map(|(k, (s, new))| (k, s, new))
.collect();
links.sort_by(|a, b| b.1.total_cmp(&a.1));