11use crate :: event:: metric:: TagValueSet ;
22use crate :: transforms:: tag_cardinality_limit:: config:: Mode ;
3- use bloom :: { BloomFilter , ASMS } ;
3+ use bloomy :: BloomFilter ;
44use std:: collections:: HashSet ;
55use std:: fmt;
66
77/// Container for storing the set of accepted values for a given tag key.
88#[ derive( Debug ) ]
99pub struct AcceptedTagValueSet {
1010 storage : TagValueSetStorage ,
11- num_elements : usize ,
1211}
1312
1413enum TagValueSetStorage {
1514 Set ( HashSet < TagValueSet > ) ,
16- Bloom ( BloomFilter ) ,
15+ Bloom ( BloomFilter < TagValueSet > ) ,
1716}
1817
1918impl fmt:: Debug for TagValueSetStorage {
@@ -26,40 +25,37 @@ impl fmt::Debug for TagValueSetStorage {
2625}
2726
2827impl AcceptedTagValueSet {
29- pub fn new ( value_limit : u32 , mode : & Mode ) -> Self {
28+ pub fn new ( value_limit : usize , mode : & Mode ) -> Self {
3029 let storage = match & mode {
31- Mode :: Exact => TagValueSetStorage :: Set ( HashSet :: with_capacity ( value_limit as usize ) ) ,
30+ Mode :: Exact => TagValueSetStorage :: Set ( HashSet :: with_capacity ( value_limit) ) ,
3231 Mode :: Probabilistic ( config) => {
3332 let num_bits = config. cache_size_per_key / 8 ; // Convert bytes to bits
34- let num_hashes = bloom:: optimal_num_hashes ( num_bits, value_limit) ;
35- TagValueSetStorage :: Bloom ( BloomFilter :: with_size ( num_bits, num_hashes) )
33+ TagValueSetStorage :: Bloom ( BloomFilter :: with_size ( num_bits) )
3634 }
3735 } ;
38- Self {
39- storage,
40- num_elements : 0 ,
41- }
36+ Self { storage }
4237 }
4338
4439 pub fn contains ( & self , value : & TagValueSet ) -> bool {
4540 match & self . storage {
4641 TagValueSetStorage :: Set ( set) => set. contains ( value) ,
47- TagValueSetStorage :: Bloom ( bloom) => bloom. contains ( & value) ,
42+ TagValueSetStorage :: Bloom ( bloom) => bloom. contains ( value) ,
4843 }
4944 }
5045
51- pub const fn len ( & self ) -> usize {
52- self . num_elements
46+ pub fn len ( & self ) -> usize {
47+ match & self . storage {
48+ TagValueSetStorage :: Set ( set) => set. len ( ) ,
49+ TagValueSetStorage :: Bloom ( bloom) => bloom. count ( ) ,
50+ }
5351 }
5452
55- pub fn insert ( & mut self , value : TagValueSet ) -> bool {
56- let inserted = match & mut self . storage {
57- TagValueSetStorage :: Set ( set) => set. insert ( value) ,
53+ pub fn insert ( & mut self , value : TagValueSet ) {
54+ match & mut self . storage {
55+ TagValueSetStorage :: Set ( set) => {
56+ set. insert ( value) ;
57+ }
5858 TagValueSetStorage :: Bloom ( bloom) => bloom. insert ( & value) ,
5959 } ;
60- if inserted {
61- self . num_elements += 1
62- }
63- inserted
6460 }
6561}
0 commit comments