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:
parent
5fe51fbfda
commit
5832e57970
8 changed files with 109 additions and 81 deletions
|
|
@ -64,36 +64,33 @@ impl StoreView for Store {
|
|||
None => return,
|
||||
};
|
||||
|
||||
// Build uuid → key map by iterating all nodes once
|
||||
let mut uuid_to_key: std::collections::HashMap<[u8; 16], String> = std::collections::HashMap::new();
|
||||
// Build uuid ↔ key maps in one pass
|
||||
let keys = match index::all_keys(db) {
|
||||
Ok(keys) => keys,
|
||||
Err(_) => return,
|
||||
};
|
||||
let mut uuid_to_key: std::collections::HashMap<[u8; 16], String> = std::collections::HashMap::new();
|
||||
let mut key_to_uuid: std::collections::HashMap<String, [u8; 16]> = std::collections::HashMap::new();
|
||||
for key in &keys {
|
||||
if let Ok(Some(uuid)) = index::get_uuid_for_key(db, key) {
|
||||
uuid_to_key.insert(uuid, key.clone());
|
||||
key_to_uuid.insert(key.clone(), uuid);
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate edges: only process outgoing to avoid duplicates
|
||||
for key in &keys {
|
||||
let uuid = match index::get_uuid_for_key(db, key) {
|
||||
Ok(Some(u)) => u,
|
||||
_ => continue,
|
||||
};
|
||||
let edges = match index::edges_for_node(db, &uuid) {
|
||||
for (key, uuid) in &key_to_uuid {
|
||||
let edges = match index::edges_for_node(db, uuid) {
|
||||
Ok(e) => e,
|
||||
Err(_) => continue,
|
||||
};
|
||||
for (other_uuid, strength, rel_type_byte, is_outgoing) in edges {
|
||||
if !is_outgoing { continue; } // only process outgoing
|
||||
if !is_outgoing { continue; }
|
||||
let target_key = match uuid_to_key.get(&other_uuid) {
|
||||
Some(k) => k,
|
||||
None => continue, // orphan edge
|
||||
None => continue,
|
||||
};
|
||||
let rel_type = RelationType::from_u8(rel_type_byte);
|
||||
f(key, target_key, strength, rel_type);
|
||||
f(key, target_key, strength, RelationType::from_u8(rel_type_byte));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue