A Python library for utilities and wrappers for frequently used functionality.
Project description
skyshapython
A Python library for utilities and wrappers for frequently used functionality.
skyshapython is a lightweight and intuitive Python library designed to simplify common programming tasks. It currently includes easy-to-use wrappers for working with MaxHeap and MinHeap, extending Python's built-in functionality in a clean and efficient way. The library is licensed under the MIT license, ensuring it is free for anyone to use, modify, and distribute.
Note - As long as the library is in version 0.x.x I am not actively looking after this. When I do intend to start managing and supporting this more seriously, I will upgrade to versions 1.0 and above. Thank you.
Installation
You can install skyshapython directly from PyPI:
pip install skyshapython
Features
MaxHeap
A simple wrapper for Python's heapq module, providing an easy-to-use MaxHeap implementation.
Supports pushing single values or lists, and popping single or multiple values.
Usage:
from skyshapython import MaxHeap
# Initialize the MaxHeap as default, with a value, or list
max_heap = MaxHeap() # default
max_heap_value = MaxHeap(5) # with a value
max_heap_list = MaxHeap([5, 2, 7, 4, 1, 9]) # with a list
# Add items to the heap
max_heap.push(10)
max_heap.push(20)
max_heap.push(5)
# Add multiple items at once
max_heap.push([50, 30, 40])
# Get the largest item
largest = max_heap.pop()
print(largest) # Output: 50 (the largest value)
# Peek at the largest item without removing it
print(max_heap.peek()) # Output: 40 (the next largest)
# Add and pop in one operation (adding a single item)
max_heap.pushpop(15) # Adds 15 and removes the largest element
# Add and pop multiple items in one operation
max_heap.pushpop([100, 200]) # Adds [100, 200], pops and returns the 2 largest values
# It can pop multiple items at once
max_heap.pop(2) # Outputs 2 largest values in order
# pop all remaining values in descending order
max_heap.popall()
# Check if the heap is empty
if max_heap:
print("Heap is not empty")
# check length of the heap, number of values in it
print(len(max_heap))
MinHeap
A clean wrapper for Python's heapq module, providing an intuitive MinHeap implementation.
Supports pushing single values or lists, and popping single or multiple values.
Usage:
from skyshapython import MinHeap
# Initialize the MinHeap as default, with a value, or list
min_heap = MinHeap() # default
min_heap_value = MinHeap(5) # with a value
min_heap_list = MinHeap([5, 2, 7, 4, 1, 9]) # with a list
# Add items to the heap
min_heap.push(10)
min_heap.push(20)
min_heap.push(5)
# Add multiple items at once
min_heap.push([50, 30, 40])
# Get the smallest item
smallest = min_heap.pop()
print(smallest) # Output: 5 (the smallest value)
# Peek at the smallest item without removing it
print(min_heap.peek()) # Output: 10 (the next smallest)
# Add and pop in one operation (adding a single item)
min_heap.pushpop(15) # Adds 15 and removes the smallest element
# Add and pop multiple items in one operation
min_heap.pushpop([100, 200]) # Adds [100, 200], pops and returns the 2 smallest values
# It can pop multiple items at once
min_heap.pop(2) # Outputs 2 smallest values in order
# pop all remaining values in ascending order
min_heap.popall()
# Check if the heap is empty
if not min_heap:
print("Heap is empty")
# Check length of the heap, number of values in it
print(len(min_heap))
SortMaster
A versatile class that provides a variety of sorting algorithms, including basic sorting techniques as well as multi-threaded and optimized approaches.
Supports sorting using algorithms like QuickSort, MergeSort, Timsort, IntroSort, and even a custom multi-threaded sorting implementation.
Sorting Methods:
- BubbleSort
- SelectionSort
- QuickSort
- MergeSort
- InsertionSort
- HeapSort
- Timsort
- IntroSoft
- ThreadSort (custom sorting solution)
Usage:
from skyshapython import SortMaster
# Initialize the SortMaster instance
sort_master = SortMaster()
# Sorting with BubbleSort (ascending and descending order)
arr = [5, 2, 9, 1, 5, 6]
sorted_asc = sort_master.bubble_sort(arr.copy(), reverse=False)
sorted_desc = sort_master.bubble_sort(arr.copy(), reverse=True)
print(sorted_asc) # Output: [1, 2, 5, 5, 6, 9]
print(sorted_desc) # Output: [9, 6, 5, 5, 2, 1]
# Sorting with SelectionSort (ascending and descending order)
sorted_asc = sort_master.selection_sort(arr.copy(), reverse=False)
sorted_desc = sort_master.selection_sort(arr.copy(), reverse=True)
print(sorted_asc) # Output: [1, 2, 5, 5, 6, 9]
print(sorted_desc) # Output: [9, 6, 5, 5, 2, 1]
# Sorting with QuickSort
sorted_asc = sort_master.quick_sort(arr.copy(), reverse=False)
sorted_desc = sort_master.quick_sort(arr.copy(), reverse=True)
print(sorted_asc) # Output: [1, 2, 5, 5, 6, 9]
print(sorted_desc) # Output: [9, 6, 5, 5, 2, 1]
# Sorting with MergeSort
sorted_asc = sort_master.merge_sort(arr.copy(), reverse=False)
sorted_desc = sort_master.merge_sort(arr.copy(), reverse=True)
print(sorted_asc) # Output: [1, 2, 5, 5, 6, 9]
print(sorted_desc) # Output: [9, 6, 5, 5, 2, 1]
# Sorting with InsertionSort
sorted_asc = sort_master.insertion_sort(arr.copy(), reverse=False)
sorted_desc = sort_master.insertion_sort(arr.copy(), reverse=True)
print(sorted_asc) # Output: [1, 2, 5, 5, 6, 9]
print(sorted_desc) # Output: [9, 6, 5, 5, 2, 1]
# Sorting with HeapSort
sorted_asc = sort_master.heap_sort(arr.copy(), reverse=False)
sorted_desc = sort_master.heap_sort(arr.copy(), reverse=True)
print(sorted_asc) # Output: [1, 2, 5, 5, 6, 9]
print(sorted_desc) # Output: [9, 6, 5, 5, 2, 1]
# Sorting with Timsort
sorted_asc = sort_master.timsort(arr.copy(), reverse=False)
sorted_desc = sort_master.timsort(arr.copy(), reverse=True)
print(sorted_asc) # Output: [1, 2, 5, 5, 6, 9]
print(sorted_desc) # Output: [9, 6, 5, 5, 2, 1]
# Sorting with IntroSort
sorted_asc = sort_master.introsort(arr.copy(), reverse=False)
sorted_desc = sort_master.introsort(arr.copy(), reverse=True)
print(sorted_asc) # Output: [1, 2, 5, 5, 6, 9]
print(sorted_desc) # Output: [9, 6, 5, 5, 2, 1]
# Sorting with ThreadSort (multi-threaded sorting)
sorted_asc = sort_master.thread_sort(arr.copy(), reverse=False)
sorted_desc = sort_master.thread_sort(arr.copy(), reverse=True)
print(sorted_asc) # Output: [1, 2, 5, 5, 6, 9]
print(sorted_desc) # Output: [9, 6, 5, 5, 2, 1]
# Finding the fastest sorting algorithm
fastest_algo = sort_master.fastest(arr.copy(), reverse=False)
print(fastest_algo) # Output: 'QuickSort', 'MergeSort', 'Timsort', or 'IntroSort'
Links
- PyPI: skyshapython on PyPI
- GitHub: skyshapython Repository
License
skyshapython is licensed under the MIT License, which means you are free to use, modify, and distribute the library in both personal and commercial projects. Contributions are always welcome, so feel free to fork the repository and create pull requests for improvements or new features.
MIT License
Copyright (c) 2024 skywalker94
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:
...
Contributing
Contributions are welcome! Feel free to submit issues or pull requests on the GitHub repository.
Author
skywalker94
Note - To be fair I do not know how often I will check back with this library and look through suggested pull requests as so on.. At the time of writing this up I just wanted to make heaps easier for myself (I detest the heapq syntax. It feels like such a chore & I often forget it). In the future, I may add mode functionality to this and change my approach toward this tiny library. But until then.. godspeed!
Happy coding with skyshapython! 🎉
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file skyshapython-0.3.1.tar.gz.
File metadata
- Download URL: skyshapython-0.3.1.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e01267faead1b74f8f16154b0bc07b0772969c508bf2d856fbef827663a400a2
|
|
| MD5 |
76b39097632826f338b81fbf4eefd528
|
|
| BLAKE2b-256 |
848e0e236344e11efff1f1ccd9c108c791b1016edb75c942714d72d02da8b673
|
File details
Details for the file skyshapython-0.3.1-py3-none-any.whl.
File metadata
- Download URL: skyshapython-0.3.1-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f4a42b06c395a1d8205d3a0a48b1490ab66370762e24e7e8b0fcf4f5f38394f
|
|
| MD5 |
4ecba0a82dd9bb97cfe8d4ed5fde94f8
|
|
| BLAKE2b-256 |
55c9f6e2ff0de05e1ad46d0b50316737abe16c62b386b8494c07a26494571278
|