mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-27 08:38:58 +00:00
4559baaeeb
- Remove reed-solomon-erasure dependency and all related code - Simplify ReedSolomonEncoder from enum to struct with SIMD-only implementation - Eliminate all conditional compilation (#[cfg(feature = ...)]) - Add instance caching with RwLock-based encoder/decoder reuse - Implement reset mechanism to avoid unnecessary allocations - Ensure thread safety with proper cache management - Update documentation and benchmark scripts for SIMD-only approach - Apply code formatting across all files Breaking Changes: - Removes support for reed-solomon-erasure feature flag - API remains compatible but implementation is now SIMD-only Performance Impact: - Improved encoding/decoding performance through SIMD optimization - Reduced memory allocations via instance caching - Enhanced thread safety and concurrency support
76 lines
2.7 KiB
Rust
76 lines
2.7 KiB
Rust
use super::pattern;
|
|
use super::target_id_set::TargetIdSet;
|
|
use crate::arn::TargetID;
|
|
use std::collections::HashMap;
|
|
|
|
/// PatternRules - Event rule that maps object name patterns to TargetID collections.
|
|
/// `event.Rules` (map[string]TargetIDSet) in the Go code
|
|
#[derive(Debug, Clone, Default)]
|
|
pub struct PatternRules {
|
|
pub(crate) rules: HashMap<String, TargetIdSet>,
|
|
}
|
|
|
|
impl PatternRules {
|
|
pub fn new() -> Self {
|
|
Default::default()
|
|
}
|
|
|
|
/// Add rules: Pattern and Target ID.
|
|
/// If the schema already exists, add target_id to the existing TargetIdSet.
|
|
pub fn add(&mut self, pattern: String, target_id: TargetID) {
|
|
self.rules.entry(pattern).or_default().insert(target_id);
|
|
}
|
|
|
|
/// Checks if there are any rules that match the given object name.
|
|
pub fn match_simple(&self, object_name: &str) -> bool {
|
|
self.rules.keys().any(|p| pattern::match_simple(p, object_name))
|
|
}
|
|
|
|
/// Returns all TargetIDs that match the object name.
|
|
pub fn match_targets(&self, object_name: &str) -> TargetIdSet {
|
|
let mut matched_targets = TargetIdSet::new();
|
|
for (pattern_str, target_set) in &self.rules {
|
|
if pattern::match_simple(pattern_str, object_name) {
|
|
matched_targets.extend(target_set.iter().cloned());
|
|
}
|
|
}
|
|
matched_targets
|
|
}
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
self.rules.is_empty()
|
|
}
|
|
|
|
/// Merge another PatternRules.
|
|
/// Corresponding to Go's `Rules.Union`.
|
|
pub fn union(&self, other: &Self) -> Self {
|
|
let mut new_rules = self.clone();
|
|
for (pattern, their_targets) in &other.rules {
|
|
let our_targets = new_rules.rules.entry(pattern.clone()).or_default();
|
|
our_targets.extend(their_targets.iter().cloned());
|
|
}
|
|
new_rules
|
|
}
|
|
|
|
/// Calculate the difference from another PatternRules.
|
|
/// Corresponding to Go's `Rules.Difference`.
|
|
pub fn difference(&self, other: &Self) -> Self {
|
|
let mut result_rules = HashMap::new();
|
|
for (pattern, self_targets) in &self.rules {
|
|
match other.rules.get(pattern) {
|
|
Some(other_targets) => {
|
|
let diff_targets: TargetIdSet = self_targets.difference(other_targets).cloned().collect();
|
|
if !diff_targets.is_empty() {
|
|
result_rules.insert(pattern.clone(), diff_targets);
|
|
}
|
|
}
|
|
None => {
|
|
// If there is no pattern in other, self_targets are all retained
|
|
result_rules.insert(pattern.clone(), self_targets.clone());
|
|
}
|
|
}
|
|
}
|
|
PatternRules { rules: result_rules }
|
|
}
|
|
}
|