@@ -945,24 +945,20 @@ impl<K: Eq + Hash + Clone, V> SieveCache<K, V> {
945945 // Calculate the utilization ratio (visited entries / total entries)
946946 let utilization_ratio = visited_count as f64 / self . nodes . len ( ) as f64 ;
947947
948- // Calculate a fill ratio (how full the cache is)
949- let fill_ratio = self . nodes . len ( ) as f64 / self . capacity as f64 ;
950-
951948 // Determine scaling factor based on utilization
952949 let scaling_factor = if utilization_ratio >= high_threshold {
953950 // High utilization - recommend increasing the capacity
954951 // Scale between 1.0 and max_factor based on utilization above the high threshold
955952 let utilization_above_threshold =
956953 ( utilization_ratio - high_threshold) / ( 1.0 - high_threshold) ;
957954 1.0 + ( max_factor - 1.0 ) * utilization_above_threshold
958- } else if utilization_ratio <= low_threshold && fill_ratio > 0.8 {
959- // Lower the fill ratio threshold for tests
960- // Low utilization and cache is reasonably full - recommend decreasing capacity
955+ } else if utilization_ratio <= low_threshold {
956+ // Low utilization - recommend decreasing capacity regardless of fill ratio
961957 // Scale between min_factor and 1.0 based on how far below the low threshold
962958 let utilization_below_threshold = ( low_threshold - utilization_ratio) / low_threshold;
963959 1.0 - ( 1.0 - min_factor) * utilization_below_threshold
964960 } else {
965- // Normal utilization or cache isn't full enough - keep current capacity
961+ // Normal utilization - keep current capacity
966962 1.0
967963 } ;
968964
@@ -1133,7 +1129,14 @@ fn test_recommended_capacity() {
11331129 cache. get ( & i. to_string ( ) ) ;
11341130 }
11351131 }
1136- // With 50% utilization (between thresholds), should keep capacity the same
1132+ // With 50% utilization (between thresholds), capacity should be fairly stable
11371133 let recommended = cache. recommended_capacity ( 0.5 , 2.0 , 0.3 , 0.7 ) ;
1138- assert_eq ! ( recommended, 100 ) ;
1134+ assert ! (
1135+ recommended >= 95 ,
1136+ "With normal utilization, capacity should be close to original"
1137+ ) ;
1138+ assert ! (
1139+ recommended <= 100 ,
1140+ "With normal utilization, capacity should not exceed original"
1141+ ) ;
11391142}
0 commit comments