ruvector_dag/qudag/
sync.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct SyncedPattern {
7 pub id: String,
8 pub pattern_vector: Vec<f32>,
9 pub quality_score: f64,
10 pub source_node: String,
11 pub round_accepted: u64,
12 pub signature: Vec<u8>,
13}
14
15pub struct PatternSync {
16 last_synced_round: u64,
17 pending_patterns: Vec<SyncedPattern>,
18}
19
20impl PatternSync {
21 pub fn new() -> Self {
22 Self {
23 last_synced_round: 0,
24 pending_patterns: Vec::new(),
25 }
26 }
27
28 pub fn last_round(&self) -> u64 {
29 self.last_synced_round
30 }
31
32 pub fn add_pattern(&mut self, pattern: SyncedPattern) {
33 if pattern.round_accepted > self.last_synced_round {
34 self.last_synced_round = pattern.round_accepted;
35 }
36 self.pending_patterns.push(pattern);
37 }
38
39 pub fn drain_pending(&mut self) -> Vec<SyncedPattern> {
40 std::mem::take(&mut self.pending_patterns)
41 }
42
43 pub fn pending_count(&self) -> usize {
44 self.pending_patterns.len()
45 }
46}
47
48impl Default for PatternSync {
49 fn default() -> Self {
50 Self::new()
51 }
52}