Files
pi-finder/examples/birth-date-finder
Bastian (BaM) 60cc17f66d feat: implement automatic memory management and custom JSON serialization
- Add deinit() method to SearchResult for automatic memory management
- Implement custom jsonStringify() method to exclude allocator from JSON output
- Store allocator internally in SearchResult for automatic cleanup
- Simplify API: result.deinit() no longer requires allocator parameter
- Update all examples to use the new simplified API
- Remove dependency on external JSON formatting functions
- Update README.md with new usage patterns and Key Features section
- Fix JSON serialization errors in Zig 0.14.1
- All examples and tests now build and run successfully

Breaking changes:
- SearchResult.deinit() signature changed from deinit(allocator) to deinit()
- Removed formatSearchResultAsJson() and formatSearchResultAsPlainText() functions
- Users should now use std.json.stringify() directly with SearchResult
2025-05-26 13:58:06 +02:00
..
2025-05-26 11:58:29 +02:00
2025-05-26 11:58:29 +02:00

Birth Date Finder Example

This example demonstrates how the Pi Finder Library is used to search for a birth date (01.01.02) in the decimal places of Pi.

Execution

cd birth-date-finder
zig build run

Additional Examples

This project includes two additional examples:

1. Multiple Test Example

zig build test-multiple

This example tests multiple different sequences and measures the performance.

2. Plain Text Format Example

zig build plain-text

This example demonstrates using the formatSearchResultAsPlainText function instead of the default JSON format.

Features

  • Searches for the sequence "010102" in Pi
  • Uses '-' as delimiter every 2 digits (01-01-02 format)
  • Outputs the result as JSON
  • Shows performance metrics

Example Output

JSON Output (Default)

{
  "success": true,
  "sequence": "010102",
  "position": 12345,
  "context": "...92[01-01-02]94...",
  "performance": {
    "file_load_time_ms": 1250.45,
    "search_time_ms": 23.67,
    "file_size_mb": 95.37,
    "load_speed_mbs": 76.28
  },
  "context_config": {
    "size": 50,
    "position": 25,
    "delimiter": "-",
    "delimiter_interval": 2,
    "prefix": "[",
    "suffix": "]"
  }
}

Plain Text Output (Using formatSearchResultAsPlainText)

Search Result:
Success: true
Sequence: 010102
Position: 12345
Context: ...92[01-01-02]94...