@@ -38,6 +38,38 @@ impl TransactionalPartitionHandle {
38
38
self . inner . path ( ) . into ( )
39
39
}
40
40
41
+ /// Approximates the amount of items in the partition.
42
+ ///
43
+ /// For update -or delete-heavy workloads, this value will
44
+ /// diverge from the real value, but is a O(1) operation.
45
+ ///
46
+ /// For insert-only workloads (e.g. logs, time series)
47
+ /// this value is reliable.
48
+ ///
49
+ /// # Examples
50
+ ///
51
+ /// ```
52
+ /// # use fjall::{Config, Keyspace, PartitionCreateOptions};
53
+ /// #
54
+ /// # let folder = tempfile::tempdir()?;
55
+ /// # let keyspace = Config::new(folder).open_transactional()?;
56
+ /// # let partition = keyspace.open_partition("default", PartitionCreateOptions::default())?;
57
+ /// assert_eq!(partition.len()?, 0);
58
+ ///
59
+ /// partition.insert("1", "abc")?;
60
+ /// assert_eq!(partition.approximate_len(), 1);
61
+ ///
62
+ /// partition.remove("1")?;
63
+ /// // Oops! approximate_len will not be reliable here
64
+ /// assert_eq!(partition.approximate_len(), 2);
65
+ /// #
66
+ /// # Ok::<(), fjall::Error>(())
67
+ /// ```
68
+ #[ must_use]
69
+ pub fn approximate_len ( & self ) -> usize {
70
+ self . inner . approximate_len ( )
71
+ }
72
+
41
73
/// Removes an item and returns its value if it existed.
42
74
///
43
75
/// The operation will run wrapped in a transaction.
0 commit comments