Name | adaptive-hybrid-sort JSON |
Version |
1.0.0
JSON |
| download |
home_page | None |
Summary | An enhanced adaptive sorting algorithm with pattern detection |
upload_time | 2025-02-10 07:01:41 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT License
Copyright (c) 2024 Valentin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. |
keywords |
sorting
algorithm
adaptive
pattern-detection
optimization
|
VCS |
 |
bugtrack_url |
|
requirements |
numpy
pandas
matplotlib
seaborn
tqdm
psutil
memory_profiler
numba
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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:
| Pattern | Performance vs NumPy | Best Use Case |
|---------|---------------------|---------------|
| Reversed | 0.51x | Large reversed sequences |
| Random | 0.09x | General purpose sorting |
| Few Unique | 0.08x | Data with many duplicates |
| Nearly Sorted | 0.02x | Almost sorted data |
| Pipeline | 0.02x | Streaming data patterns |
## Installation
### From PyPI (Recommended)
```bash
pip install adaptive-hybrid-sort
```
### From Source
```bash
# 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:
```bash
sorts setup
```
2. Sort a single array:
```bash
sorts sort --size 1000 --pattern random
```
Available patterns: `random`, `nearly_sorted`, `reversed`, `few_unique`, `sorted`, `pipeline`
3. Run benchmarks:
```bash
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
```python
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
```python
# 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
```python
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](LICENSE) file for details.
## Author
[valEn1Ob0](https://github.com/valEn1Ob0)
## Acknowledgments
- Inspired by TimSort's adaptive approach
- Uses NumPy for efficient array operations
- Parallel processing inspired by parallel merge sort
Raw data
{
"_id": null,
"home_page": null,
"name": "adaptive-hybrid-sort",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "sorting, algorithm, adaptive, pattern-detection, optimization",
"author": null,
"author_email": "valEn1Ob0 <your.email@example.com>",
"download_url": "https://files.pythonhosted.org/packages/96/a0/90b10bc9aeca7e610caca80b65394daa0274f44bcf445e2425417cf03fea/adaptive_hybrid_sort-1.0.0.tar.gz",
"platform": null,
"description": "# Adaptive Hybrid Sort\n\nA 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.\n\n## Features\n\n- **Pattern Detection**: Automatically detects and adapts to different data patterns\n- **Parallel Processing**: Utilizes multiple cores for large datasets\n- **Stable Sorting**: Maintains relative order of equal elements\n- **Memory Efficient**: Optimized memory usage with NumPy operations\n- **Type Preserving**: Maintains input data types\n- **Fallback Mechanism**: Gracefully handles edge cases\n\n## Performance Characteristics\n\nThe algorithm shows different performance characteristics for various input patterns:\n\n| Pattern | Performance vs NumPy | Best Use Case |\n|---------|---------------------|---------------|\n| Reversed | 0.51x | Large reversed sequences |\n| Random | 0.09x | General purpose sorting |\n| Few Unique | 0.08x | Data with many duplicates |\n| Nearly Sorted | 0.02x | Almost sorted data |\n| Pipeline | 0.02x | Streaming data patterns |\n\n## Installation\n\n### From PyPI (Recommended)\n\n```bash\npip install adaptive-hybrid-sort\n```\n\n### From Source\n\n```bash\n# Clone the repository\ngit clone https://github.com/valEn1Ob0/adaptive-hybrid-sort.git\n\n# Navigate to the directory\ncd adaptive-hybrid-sort\n\n# Install the package\npip install -e .\n\n# Setup the environment\nsorts setup\n```\n\n## Usage\n\n### Command Line Interface\n\nThe package provides a convenient command-line interface through the `sorts` command:\n\n1. Setup environment and install requirements:\n```bash\nsorts setup\n```\n\n2. Sort a single array:\n```bash\nsorts sort --size 1000 --pattern random\n```\nAvailable patterns: `random`, `nearly_sorted`, `reversed`, `few_unique`, `sorted`, `pipeline`\n\n3. Run benchmarks:\n```bash\nsorts benchmark --sizes 1000 2000 4000 --patterns random nearly_sorted --runs 3\n```\n\nThe benchmark results will be saved in a timestamped directory under `sorting_results/`.\n\n### Python API\n\n```python\nfrom adaptive_hybrid_sort import EnhancedAdaptiveSort\n\n# Create a sorter instance\nsorter = EnhancedAdaptiveSort()\n\n# Sort an array\narr = [64, 34, 25, 12, 22, 11, 90]\nsorted_arr = sorter.sort(arr)\n```\n\n### Advanced Usage\n\n```python\n# Custom thresholds for different array sizes\nsorter = EnhancedAdaptiveSort(\n threshold_small=32, # Threshold for insertion sort\n threshold_chunk=2048 # Threshold for chunk size\n)\n\n# Sort different types of data\n# Integers\nint_arr = [1000, 1, 100, 10]\nsorted_ints = sorter.sort(int_arr)\n\n# Floats\nfloat_arr = [3.14, 1.41, 2.71, 1.73]\nsorted_floats = sorter.sort(float_arr)\n```\n\n### Benchmarking\n\n```python\nfrom adaptive_hybrid_sort import SortingVisualizer\n\n# Create visualizer\nvisualizer = SortingVisualizer()\n\n# Run benchmarks\nsizes = [1000, 10000, 100000]\npatterns = [\"random\", \"nearly_sorted\", \"reversed\", \"few_unique\", \"sorted\", \"pipeline\"]\nresults = visualizer.benchmark_sorting(sizes, patterns)\n\n# Generate visualizations\nvisualizer.plot_performance_comparison(results)\n```\n\n## Algorithm Details\n\n### 1. Pattern Detection\nThe algorithm uses statistical sampling to detect patterns in the input data:\n- Sorted sequences\n- Reversed sequences\n- Nearly sorted data\n- Data with many duplicates\n\n### 2. Sorting Strategies\nAdapts its strategy based on input characteristics:\n- **Small Arrays**: Optimized insertion sort\n- **Nearly Sorted**: Direct insertion sort\n- **Many Duplicates**: Three-way partitioning\n- **Large Arrays**: Parallel merge sort\n- **Random Data**: Hybrid quicksort\n\n### 3. Optimizations\n- Vectorized operations using NumPy\n- Binary search for insertion points\n- Adaptive chunk sizing for parallel processing\n- Memory-efficient merging\n- Cache-friendly operations\n\n## Performance Tips\n\n1. **Array Size**\n - Small arrays (< 32 elements): Uses insertion sort\n - Medium arrays (32-2048 elements): Uses quicksort\n - Large arrays (> 2048 elements): Uses pattern detection\n\n2. **Data Patterns**\n - Best performance on reversed sequences\n - Efficient with duplicate elements\n - Good for nearly sorted data\n - Stable performance on random data\n\n3. **Memory Usage**\n - Uses about 2x input size for worst case\n - More efficient for nearly sorted data\n - Parallel processing requires additional memory\n\n## Contributing\n\nContributions are welcome! Here are some areas for improvement:\n\n1. SIMD optimization for parallel operations\n2. Additional pattern detection strategies\n3. GPU acceleration for large arrays\n4. Memory optimization for in-place operations\n5. Additional benchmarking scenarios\n\n## License\n\nMIT License - see the [LICENSE](LICENSE) file for details.\n\n## Author\n\n[valEn1Ob0](https://github.com/valEn1Ob0)\n\n## Acknowledgments\n\n- Inspired by TimSort's adaptive approach\n- Uses NumPy for efficient array operations\n- Parallel processing inspired by parallel merge sort \n",
"bugtrack_url": null,
"license": "MIT License\n \n Copyright (c) 2024 Valentin\n \n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE. ",
"summary": "An enhanced adaptive sorting algorithm with pattern detection",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/valEn1Ob0/adaptive-hybrid-sort",
"Issues": "https://github.com/valEn1Ob0/adaptive-hybrid-sort/issues",
"Repository": "https://github.com/valEn1Ob0/adaptive-hybrid-sort.git"
},
"split_keywords": [
"sorting",
" algorithm",
" adaptive",
" pattern-detection",
" optimization"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "c25d353ca061a7c24b60fa97fc9d118f7796b40618c97f6ff6a40aaf8ce6cec2",
"md5": "15f8ac704f7ad567bd4b42cca8030c0f",
"sha256": "ca5738ffbeecce513984df94b3823a2dfe81d138d61a96ec380b1e04bb4e82b1"
},
"downloads": -1,
"filename": "adaptive_hybrid_sort-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "15f8ac704f7ad567bd4b42cca8030c0f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 14974,
"upload_time": "2025-02-10T07:01:39",
"upload_time_iso_8601": "2025-02-10T07:01:39.442220Z",
"url": "https://files.pythonhosted.org/packages/c2/5d/353ca061a7c24b60fa97fc9d118f7796b40618c97f6ff6a40aaf8ce6cec2/adaptive_hybrid_sort-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "96a090b10bc9aeca7e610caca80b65394daa0274f44bcf445e2425417cf03fea",
"md5": "2a4274c3cf3b869b3b15e98edc95eca9",
"sha256": "7d6579f008363b0d832fe99f641edd3594f60ed86e3f6eb5e1847ce11160d4c8"
},
"downloads": -1,
"filename": "adaptive_hybrid_sort-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "2a4274c3cf3b869b3b15e98edc95eca9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 14987,
"upload_time": "2025-02-10T07:01:41",
"upload_time_iso_8601": "2025-02-10T07:01:41.676521Z",
"url": "https://files.pythonhosted.org/packages/96/a0/90b10bc9aeca7e610caca80b65394daa0274f44bcf445e2425417cf03fea/adaptive_hybrid_sort-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-10 07:01:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "valEn1Ob0",
"github_project": "adaptive-hybrid-sort",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "numpy",
"specs": [
[
">=",
"1.19.0"
]
]
},
{
"name": "pandas",
"specs": [
[
">=",
"1.2.0"
]
]
},
{
"name": "matplotlib",
"specs": [
[
">=",
"3.3.0"
]
]
},
{
"name": "seaborn",
"specs": [
[
">=",
"0.11.0"
]
]
},
{
"name": "tqdm",
"specs": [
[
">=",
"4.50.0"
]
]
},
{
"name": "psutil",
"specs": [
[
">=",
"5.7.0"
]
]
},
{
"name": "memory_profiler",
"specs": [
[
">=",
"0.58.0"
]
]
},
{
"name": "numba",
"specs": [
[
">=",
"0.56.0"
]
]
}
],
"lcname": "adaptive-hybrid-sort"
}