Catalog PyPI
PACKAGE EXPLORERView in registry

adaptive-hybrid-sort

PyPI

An enhanced adaptive sorting algorithm with pattern detection

adaptivealgorithmoptimizationpattern-detectionsorting
Versions collected1
Direct dependencies7From release 1.0.0
Last observed20 Oct, 19:06 UTC

README

Version 1.0.0 documentation

Adaptive Hybrid Sort

A novel sorting algorithm that combines multiple sorting strategies with pattern detection and parallel processing capabilities. This algorithm is particularly efficient for certain types of data patterns and provides stable sorting guarantees.

Features

  • Pattern Detection: Automatically detects and adapts to different data patterns
  • Parallel Processing: Utilizes multiple cores for large datasets
  • Stable Sorting: Maintains relative order of equal elements
  • Memory Efficient: Optimized memory usage with NumPy operations
  • Type Preserving: Maintains input data types
  • Fallback Mechanism: Gracefully handles edge cases

Performance Characteristics

The algorithm shows different performance characteristics for various input patterns:

PatternPerformance vs NumPyBest Use Case
Reversed0.51xLarge reversed sequences
Random0.09xGeneral purpose sorting
Few Unique0.08xData with many duplicates
Nearly Sorted0.02xAlmost sorted data
Pipeline0.02xStreaming data patterns

Installation

pip install adaptive-hybrid-sort

From Source

# Clone the repository
git clone https://github.com/valEn1Ob0/adaptive-hybrid-sort.git

# Navigate to the directory
cd adaptive-hybrid-sort

# Install the package
pip install -e .

# Setup the environment
sorts setup

Usage

Command Line Interface

The package provides a convenient command-line interface through the sorts command:

  1. Setup environment and install requirements:
sorts setup
  1. Sort a single array:
sorts sort --size 1000 --pattern random

Available patterns: random, nearly_sorted, reversed, few_unique, sorted, pipeline

  1. Run benchmarks:
sorts benchmark --sizes 1000 2000 4000 --patterns random nearly_sorted --runs 3

The benchmark results will be saved in a timestamped directory under sorting_results/.

Python API

from adaptive_hybrid_sort import EnhancedAdaptiveSort

# Create a sorter instance
sorter = EnhancedAdaptiveSort()

# Sort an array
arr = [64, 34, 25, 12, 22, 11, 90]
sorted_arr = sorter.sort(arr)

Advanced Usage

# Custom thresholds for different array sizes
sorter = EnhancedAdaptiveSort(
    threshold_small=32,    # Threshold for insertion sort
    threshold_chunk=2048   # Threshold for chunk size
)

# Sort different types of data
# Integers
int_arr = [1000, 1, 100, 10]
sorted_ints = sorter.sort(int_arr)

# Floats
float_arr = [3.14, 1.41, 2.71, 1.73]
sorted_floats = sorter.sort(float_arr)

Benchmarking

from adaptive_hybrid_sort import SortingVisualizer

# Create visualizer
visualizer = SortingVisualizer()

# Run benchmarks
sizes = [1000, 10000, 100000]
patterns = ["random", "nearly_sorted", "reversed", "few_unique", "sorted", "pipeline"]
results = visualizer.benchmark_sorting(sizes, patterns)

# Generate visualizations
visualizer.plot_performance_comparison(results)

Algorithm Details

1. Pattern Detection

The algorithm uses statistical sampling to detect patterns in the input data:

  • Sorted sequences
  • Reversed sequences
  • Nearly sorted data
  • Data with many duplicates

2. Sorting Strategies

Adapts its strategy based on input characteristics:

  • Small Arrays: Optimized insertion sort
  • Nearly Sorted: Direct insertion sort
  • Many Duplicates: Three-way partitioning
  • Large Arrays: Parallel merge sort
  • Random Data: Hybrid quicksort

3. Optimizations

  • Vectorized operations using NumPy
  • Binary search for insertion points
  • Adaptive chunk sizing for parallel processing
  • Memory-efficient merging
  • Cache-friendly operations

Performance Tips

  1. Array Size

    • Small arrays (< 32 elements): Uses insertion sort
    • Medium arrays (32-2048 elements): Uses quicksort
    • Large arrays (> 2048 elements): Uses pattern detection
  2. Data Patterns

    • Best performance on reversed sequences
    • Efficient with duplicate elements
    • Good for nearly sorted data
    • Stable performance on random data
  3. Memory Usage

    • Uses about 2x input size for worst case
    • More efficient for nearly sorted data
    • Parallel processing requires additional memory

Contributing

Contributions are welcome! Here are some areas for improvement:

  1. SIMD optimization for parallel operations
  2. Additional pattern detection strategies
  3. GPU acceleration for large arrays
  4. Memory optimization for in-place operations
  5. Additional benchmarking scenarios

License

MIT License - see the LICENSE file for details.

Author

valEn1Ob0

Acknowledgments

  • Inspired by TimSort's adaptive approach
  • Uses NumPy for efficient array operations
  • Parallel processing inspired by parallel merge sort

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
1.0.010 Feb 20257

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
valen1ob0/adaptive-hybrid-sort

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:06 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:d4302f73a0abc1feccd57c8a7d437b1d39788130bba92266bd5979e4c387c100