Crate rfgrep

Crate rfgrep 

Source
Expand description

§rfgrep - High-Performance File Search Library

A comprehensive Rust library for fast, memory-efficient file searching with advanced filtering capabilities, parallel processing, and multiple search algorithms.

§Features

  • Multiple Search Algorithms: SIMD-optimized, Boyer-Moore, regex, and simple string matching
  • Parallel Processing: Multi-threaded file processing with adaptive chunking
  • Memory Optimization: Memory-mapped I/O, zero-copy string processing, and intelligent caching
  • Plugin System: Extensible architecture with dynamic plugin loading
  • Interactive TUI: Real-time search interface with live pattern editing
  • Streaming Search: Handles files larger than available memory
  • File Type Classification: Smart handling of 153+ file formats
  • Performance Monitoring: Built-in metrics and benchmarking tools

§Quick Start

use rfgrep::{app_simple::RfgrepApp, Cli, Commands, SearchMode};
use clap::Parser;

#[tokio::main]
async fn main() -> rfgrep::Result<()> {
    // In a real application, you would parse from command line
    let cli = Cli::try_parse_from(&["rfgrep", ".", "search", "pattern"]).unwrap();
    let app = RfgrepApp::new_async().await?;
    app.run(cli).await?;
    Ok(())
}

§Search Algorithms

use rfgrep::search_algorithms::{SearchAlgorithm, SearchAlgorithmFactory};

// Create a search algorithm
let algorithm = SearchAlgorithmFactory::create(SearchAlgorithm::BoyerMoore, "pattern");

// Search in text
let matches = algorithm.search("Hello, world!", "world");

§Performance Features

  • SIMD Acceleration: Hardware-optimized string matching
  • Memory Pooling: Reuses expensive resources (mmap, compiled regex)
  • Adaptive Strategies: Chooses optimal algorithm based on context
  • Zero-Copy Operations: Minimizes memory allocations
  • Intelligent Caching: LRU with TTL and invalidation

§Examples

See the examples/ directory for comprehensive usage examples:

  • real_world_demo.rs - Real-world performance demonstration
  • performance_benchmark_demo.rs - Benchmarking suite

§Thread Safety

All public APIs are designed to be thread-safe and can be used in concurrent environments. The library uses Arc and atomic operations for shared state.

§Performance Characteristics

AlgorithmBest CaseAverage CaseWorst CaseMemory
SIMD SearchO(n)O(n)O(n)O(1)
Boyer-MooreO(n/m)O(n/m)O(n)O(m)
RegexO(n)O(n)O(n²)O(m)
Zero-CopyO(n)O(n)O(n)O(1)

Where: n = text length, m = pattern length

Re-exports§

pub use crate::error::Result;
pub use cli::Cli;
pub use cli::Commands;
pub use cli::SearchMode;
pub use list::FileInfo;
pub use processor::is_binary;
pub use processor::search_file;
pub use search_algorithms::BoyerMoore;
pub use search_algorithms::RegexSearch;
pub use search_algorithms::SearchAlgorithm;
pub use search_algorithms::SearchAlgorithmFactory;
pub use search_algorithms::SearchMatch;
pub use search_algorithms::SimdSearch;
pub use search_algorithms::SimpleSearch;
pub use walker::walk_dir;

Modules§

app_simple
Simplified application architecture with async runtime support Simplified application structure
cli
Command-line interface definitions and argument parsing
error
Error types and result handling
file_types
File type classification system supporting 153+ formats
list
File listing and information utilities File listing engine with advanced filtering and statistics
metrics
Performance metrics and monitoring
performance
High-performance optimization modules
plugin_cli
Plugin command-line interface CLI commands for plugin management
plugin_system
Extensible plugin system with dynamic loading Enhanced plugin system for rfgrep with dynamic loading and better integration
processor
Core file processing and search logic File-level search helpers and match extraction used by the rfgrep core.
search_algorithms
Multiple search algorithms (SIMD, Boyer-Moore, Regex, Simple)
streaming_search
Streaming search pipeline for large files Streaming search pipeline for efficient file processing
test_utils
Test utilities and benchmarking tools (enabled for test/bench/examples features) Test utilities for rfgrep Provides common testing functions, mock data, and test harnesses
tui
Interactive Terminal User Interface Modern TUI interface for rfgrep using ratatui
walker
Directory walking and file discovery

Structs§

AppConfig
Application configuration for rfgrep operations
PathBuf
Path buffer type for file operations An owned, mutable path (akin to String).

Traits§

Parser
Command-line argument parser from clap Parse command-line arguments into Self.

Functions§

load_config
Load application configuration from file or use defaults
run_benchmarks
Run comprehensive performance benchmarks using hyperfine
run_benchmarks_cli
Run benchmarks from CLI arguments with automatic test data setup
run_external_command
Execute an external command with optional environment variables

Derive Macros§

Parser
Command-line argument parser from clap Generates the Parser implementation.