1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
//! # 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
//!
//! ```rust
//! 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
//!
//! ```rust
//! 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
//!
//! | Algorithm | Best Case | Average Case | Worst Case | Memory |
//! |-----------|-----------|--------------|------------|--------|
//! | SIMD Search | O(n) | O(n) | O(n) | O(1) |
//! | Boyer-Moore | O(n/m) | O(n/m) | O(n) | O(m) |
//! | Regex | O(n) | O(n) | O(n²) | O(m) |
//! | Zero-Copy | O(n) | O(n) | O(n) | O(1) |
//!
//! Where: n = text length, m = pattern length
// Core application modules
/// Simplified application architecture with async runtime support
/// Application submodules (stdin, filters, handlers, etc.)
/// Command-line interface definitions and argument parsing
/// Internal configuration management
/// CLI configuration module
/// Compression support
/// Error types and result handling
/// File type classification system supporting 153+ formats
/// Test utilities and benchmarking tools (enabled for test/bench/examples features)
/// Interactive search mode implementation
/// File listing and information utilities
/// Memory management and optimization
/// Performance metrics and monitoring
/// Output format implementations (JSON, XML, HTML, Markdown)
/// High-performance optimization modules
///
/// Includes:
/// - Memory pooling and caching
/// - Parallel processing with adaptive chunking
/// - Zero-copy string processing
/// - Optimized memory-mapped I/O
/// Plugin command-line interface
/// Extensible plugin system with dynamic loading
/// Core file processing and search logic
/// Progress tracking and reporting
/// Search algorithm implementations
/// Multiple search algorithms (SIMD, Boyer-Moore, Regex, Simple)
/// SIMD-optimized search engine implementation
/// Streaming search pipeline for large files
/// Interactive Terminal User Interface
/// Directory walking and file discovery
use crateConfig;
// Re-export commonly used types for convenience
/// Result type alias for rfgrep operations
pub use crateResult;
/// Command-line argument parser from clap
pub use Parser;
/// CLI definitions and search modes
pub use ;
/// File information structure for listing operations
pub use FileInfo;
/// Core file processing functions
pub use ;
/// Search algorithm implementations and utilities
pub use ;
use Path;
/// Path buffer type for file operations
pub use PathBuf;
/// Directory walking functionality
pub use walk_dir;
/// Application configuration for rfgrep operations
///
/// Contains runtime configuration including chunk sizes, executable paths,
/// and output directories for benchmarking and testing operations.
/// Load application configuration from file or use defaults
///
/// Attempts to load configuration from the default location, falling back
/// to default values if no configuration file is found.
///
/// # Returns
/// * `AppConfig` - Loaded or default configuration
/// Execute an external command with optional environment variables
///
/// # Arguments
/// * `command` - Command to execute
/// * `args` - Command arguments
/// * `env` - Optional environment variable value
///
/// # Returns
/// * `std::io::Result<()>` - Success or I/O error
///
/// # Example
/// ```no_run
/// use rfgrep::run_external_command;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// // Run a simple command
/// run_external_command("echo", &["hello"], None)?;
///
/// // Run with environment variable
/// run_external_command("env", &[], Some("test_value"))?;
/// Ok(())
/// }
/// ```
/// Run comprehensive performance benchmarks using hyperfine
///
/// Executes a series of performance tests including warmup and detailed
/// benchmarking with JSON and Markdown output formats.
///
/// # Arguments
/// * `config` - Application configuration with paths and settings
/// * `test_dir` - Directory containing test files for benchmarking
///
/// # Returns
/// * `Result<()>` - Success or error during benchmark execution
///
/// # Example
/// ```no_run
/// use rfgrep::{AppConfig, run_benchmarks};
/// use std::path::Path;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// // Create config manually for doctest
/// let config = AppConfig {
/// chunk_size: Some(100),
/// rfgrep_exe: std::env::current_exe().unwrap_or_else(|_| std::path::PathBuf::from("rfgrep")),
/// results_dir: std::path::PathBuf::from("results"),
/// };
/// let test_dir = Path::new("/path/to/test/files");
/// run_benchmarks(&config, test_dir)?;
/// Ok(())
/// }
/// ```
/// Run benchmarks from CLI arguments with automatic test data setup
///
/// Convenience function that creates test data directory if needed and
/// runs comprehensive benchmarks using the provided CLI configuration.
///
/// # Arguments
/// * `cli` - Parsed command-line interface arguments
///
/// # Returns
/// * `Result<()>` - Success or error during benchmark execution
///
/// # Example
/// ```no_run
/// use rfgrep::{Cli, run_benchmarks_cli};
/// use clap::Parser;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// // In a real application, you would parse from command line
/// let cli = Cli::try_parse_from(&["rfgrep", ".", "search", "pattern"]).unwrap();
/// run_benchmarks_cli(&cli)?;
/// Ok(())
/// }
/// ```