store: remove Vec<Relation>, dedup uses index iteration
The relations Vec is gone from Store. dedup now iterates via edges_for_uuid() instead of mutating in-memory Vec — removes/re-adds edges through the index directly. Removed load_relations_vec() and clear_relations() — no longer needed. Added helper methods: edges_for_uuid, index_relation, remove_relation_from_index. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
c2de14dcab
commit
2548ca059d
5 changed files with 105 additions and 78 deletions
|
|
@ -47,7 +47,6 @@ pub fn strip_md_suffix(key: &str) -> String {
|
|||
|
||||
// The full in-memory store
|
||||
pub struct Store {
|
||||
pub relations: Vec<Relation>, // all active relations
|
||||
/// Log sizes at load time — used for staleness detection.
|
||||
pub(crate) loaded_nodes_size: u64,
|
||||
pub(crate) loaded_rels_size: u64,
|
||||
|
|
@ -58,7 +57,6 @@ pub struct Store {
|
|||
impl Default for Store {
|
||||
fn default() -> Self {
|
||||
Store {
|
||||
relations: Vec::new(),
|
||||
loaded_nodes_size: 0,
|
||||
loaded_rels_size: 0,
|
||||
db: None,
|
||||
|
|
@ -130,14 +128,25 @@ impl Store {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Rebuild relation index from Vec. Call after mutations that modify relations.
|
||||
pub fn reindex_relations(&self) -> Result<()> {
|
||||
/// Get all edges for a node by UUID. Returns (other_uuid, strength, rel_type, is_outgoing).
|
||||
pub fn edges_for_uuid(&self, uuid: &[u8; 16]) -> Result<Vec<([u8; 16], f32, u8, bool)>> {
|
||||
let db = self.db.as_ref()
|
||||
.ok_or_else(|| anyhow::anyhow!("store not loaded"))?;
|
||||
index::edges_for_node(db, uuid)
|
||||
}
|
||||
|
||||
/// Add a relation to the index.
|
||||
pub fn index_relation(&self, source: &[u8; 16], target: &[u8; 16], strength: f32, rel_type: u8) -> Result<()> {
|
||||
if let Some(db) = self.db.as_ref() {
|
||||
index::clear_relations(db)?;
|
||||
for rel in &self.relations {
|
||||
if rel.deleted { continue; }
|
||||
index::index_relation(db, &rel.source, &rel.target, rel.strength, rel.rel_type as u8)?;
|
||||
}
|
||||
index::index_relation(db, source, target, strength, rel_type)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove a relation from the index.
|
||||
pub fn remove_relation_from_index(&self, source: &[u8; 16], target: &[u8; 16], strength: f32, rel_type: u8) -> Result<()> {
|
||||
if let Some(db) = self.db.as_ref() {
|
||||
index::remove_relation(db, source, target, strength, rel_type)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue