Skip to main content

dedup/
cluster.rs

1/// A cluster of duplicate documents.
2#[derive(Debug, Clone, PartialEq)]
3pub struct DuplicateCluster {
4    /// Cluster ID (sequential from 0).
5    pub id: usize,
6    /// Document indices in this cluster.
7    pub indices: Vec<usize>,
8    /// Representative index (first in cluster).
9    pub representative: usize,
10}
11
12impl DuplicateCluster {
13    /// Create a new duplicate cluster.
14    pub fn new(id: usize, representative: usize) -> Self {
15        Self {
16            id,
17            indices: vec![representative],
18            representative,
19        }
20    }
21
22    /// Add an index to the cluster.
23    pub fn add(&mut self, index: usize) {
24        self.indices.push(index);
25    }
26
27    /// Get the number of documents.
28    #[must_use]
29    pub fn len(&self) -> usize {
30        self.indices.len()
31    }
32
33    /// Check if cluster has no documents.
34    #[must_use]
35    pub fn is_empty(&self) -> bool {
36        self.indices.is_empty()
37    }
38
39    /// Check if cluster has duplicates.
40    #[must_use]
41    pub fn is_duplicate(&self) -> bool {
42        self.len() > 1
43    }
44
45    /// Check if this cluster contains a document.
46    #[must_use]
47    pub fn contains(&self, index: usize) -> bool {
48        self.indices.contains(&index)
49    }
50}