color-sort-algorithm 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- color_sort_algorithm-0.0.1.dist-info/METADATA +8 -0
- color_sort_algorithm-0.0.1.dist-info/RECORD +6 -0
- color_sort_algorithm-0.0.1.dist-info/WHEEL +5 -0
- color_sort_algorithm-0.0.1.dist-info/licenses/LICENSE.txt +28 -0
- color_sort_algorithm-0.0.1.dist-info/top_level.txt +1 -0
- color_sort_prototype.py +134 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: color_sort_algorithm
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A simple and competitively efficient prototyped unstable sorting algorithm which sorts data according to a predefined color gradient spectrum
|
|
5
|
+
Author-email: S1NGULAR1TY <theo.b.gray@gmail.com>
|
|
6
|
+
Requires-Python: >=3.14.4
|
|
7
|
+
License-File: LICENSE.txt
|
|
8
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
color_sort_prototype.py,sha256=c-ghHb_JC9RH89rpnTmRs-78tHMQLTdWefw-e4hZ29s,5798
|
|
2
|
+
color_sort_algorithm-0.0.1.dist-info/licenses/LICENSE.txt,sha256=pwwmuHPauFd2B60NTKFnYwEDxUxKvsA2C4ZcWGlNAVM,1524
|
|
3
|
+
color_sort_algorithm-0.0.1.dist-info/METADATA,sha256=WV2GhcHNFFA2H0c-MD3LLYOgB08_LEOTwyFRZ4j8iYM,347
|
|
4
|
+
color_sort_algorithm-0.0.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
5
|
+
color_sort_algorithm-0.0.1.dist-info/top_level.txt,sha256=dhHFUseMniacIDSsr4Xno5ujN-wXt6pVTUGjsmKB-LY,21
|
|
6
|
+
color_sort_algorithm-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, S1NGULAR1TY
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
color_sort_prototype
|
color_sort_prototype.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""
|
|
2
|
+
*| COLOR SORT ALGORITHM (PROTOTYPE) |*
|
|
3
|
+
AUTHOR: S1NGULAR1TY (@github/1ts-s1ngular1ty)
|
|
4
|
+
DATE: 7/29/2026
|
|
5
|
+
LICENSE: BSD 3-Clause
|
|
6
|
+
LANGUAGE: Python (v3.14.4)
|
|
7
|
+
DESCRIPTION: A simple and competitively efficient prototyped unstable sorting algorithm which sorts data according to a predefined color gradient spectrum
|
|
8
|
+
ORDER:
|
|
9
|
+
- Ascending (isAscending = True)
|
|
10
|
+
- Descending (isAscending = False)
|
|
11
|
+
MODES:
|
|
12
|
+
- Numerical (isNumerical = True)
|
|
13
|
+
- Alphabetical (isNumerical = False)
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
# ------------------------------
|
|
17
|
+
# -- DEPENDENCIES --
|
|
18
|
+
# ------------------------------
|
|
19
|
+
from typing import List, Dict, Union, Any
|
|
20
|
+
import time
|
|
21
|
+
|
|
22
|
+
# ------------------------------
|
|
23
|
+
# -- CLASSES --
|
|
24
|
+
# ------------------------------
|
|
25
|
+
class Color3: # Abstract Color3 class for representing gradient RGB colors
|
|
26
|
+
def __init__(self, r: float, g: float, b: float):
|
|
27
|
+
self.r = r
|
|
28
|
+
self.g = g
|
|
29
|
+
self.b = b
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
def fromRGB(cls, r: float, g: float, b: float) -> 'Color3':
|
|
33
|
+
return cls(r / 255.0, g / 255.0, b / 255.0)
|
|
34
|
+
|
|
35
|
+
def lerp(self, other: 'Color3', fraction: float) -> 'Color3':
|
|
36
|
+
return Color3(
|
|
37
|
+
self.r + (other.r - self.r) * fraction,
|
|
38
|
+
self.g + (other.g - self.g) * fraction,
|
|
39
|
+
self.b + (other.b - self.b) * fraction
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
def __repr__(self) -> str:
|
|
43
|
+
return f"Color3({self.r:.3f}, {self.g:.3f}, {self.b:.3f})"
|
|
44
|
+
|
|
45
|
+
# ------------------------------
|
|
46
|
+
# -- VARIABLES --
|
|
47
|
+
# ------------------------------
|
|
48
|
+
AlphabetMap: Dict[str, int] = {chr(65 + i): i for i in range(26)} # Iterates Unicode character indexes from A-Z (ex: A = 0, B = 1, etc.) for alphabetical data filtration
|
|
49
|
+
# ------------------------------
|
|
50
|
+
GradientMap: List[Dict[str, Union[float, Color3]]] = [ # Predefined gradient color spectrum with keypoints that contain percent based thresholds and corresponding RGB values (ex: 0% = Red, 100% = Magenta)
|
|
51
|
+
# More colors and higher color contrasts would theoretically increase the data filtration accuracy
|
|
52
|
+
{"Threshold": 0, "Color": Color3.fromRGB(255, 23, 68)}, # Red [1]
|
|
53
|
+
{"Threshold": 10, "Color": Color3.fromRGB(255, 143, 0)}, # Orange [2]
|
|
54
|
+
{"Threshold": 20, "Color": Color3.fromRGB(255, 235, 59)}, # Yellow [3]
|
|
55
|
+
{"Threshold": 30, "Color": Color3.fromRGB(198, 255, 0)}, # Lime [4]
|
|
56
|
+
{"Threshold": 40, "Color": Color3.fromRGB(0, 230, 118)}, # Green [5]
|
|
57
|
+
{"Threshold": 50, "Color": Color3.fromRGB(0, 229, 255)}, # Teal [6]
|
|
58
|
+
{"Threshold": 60, "Color": Color3.fromRGB(0, 176, 255)}, # Cyan [7]
|
|
59
|
+
{"Threshold": 70, "Color": Color3.fromRGB(41, 98, 255)}, # Blue [8]
|
|
60
|
+
{"Threshold": 80, "Color": Color3.fromRGB(61, 90, 254)}, # Indigo [9]
|
|
61
|
+
{"Threshold": 90, "Color": Color3.fromRGB(124, 77, 255)}, # Purple [10]
|
|
62
|
+
{"Threshold": 100, "Color": Color3.fromRGB(213, 0, 249)} # Magenta [11]
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
# ------------------------------
|
|
66
|
+
# -- HELPER FUNCTIONS --
|
|
67
|
+
# ------------------------------
|
|
68
|
+
def _clamp(value: float, minVal: float, maxVal: float) -> float:
|
|
69
|
+
return max(minVal, min(value, maxVal))
|
|
70
|
+
|
|
71
|
+
# ------------------------------
|
|
72
|
+
# -- MAIN FUNCTIONS --
|
|
73
|
+
# ------------------------------
|
|
74
|
+
def mapValueToColorGradient(value: float, gradient: List[Dict[str, Any]]) -> Color3: # Maps each specific value to the gradient color spectrum mapping in a linear direction
|
|
75
|
+
minimumThreshold = gradient[0]["Threshold"]
|
|
76
|
+
maximumThreshold = gradient[-1]["Threshold"]
|
|
77
|
+
clampedValue = _clamp(value, minimumThreshold, maximumThreshold)
|
|
78
|
+
|
|
79
|
+
lowerBound, upperBound = None, None
|
|
80
|
+
for i in range(len(gradient) - 1):
|
|
81
|
+
if gradient[i]["Threshold"] <= clampedValue <= gradient[i + 1]["Threshold"]:
|
|
82
|
+
lowerBound = gradient[i]
|
|
83
|
+
upperBound = gradient[i + 1]
|
|
84
|
+
break
|
|
85
|
+
|
|
86
|
+
if not lowerBound:
|
|
87
|
+
return gradient[-1]["Color"]
|
|
88
|
+
|
|
89
|
+
rangeThreshold = upperBound["Threshold"] - lowerBound["Threshold"]
|
|
90
|
+
fraction = 0.0
|
|
91
|
+
if rangeThreshold > 0:
|
|
92
|
+
fraction = (clampedValue - lowerBound["Threshold"]) / rangeThreshold
|
|
93
|
+
|
|
94
|
+
return lowerBound["Color"].lerp(upperBound["Color"], fraction)
|
|
95
|
+
|
|
96
|
+
# ------------------------------
|
|
97
|
+
# -- PACKAGE CONSTRUCTOR --
|
|
98
|
+
# ------------------------------
|
|
99
|
+
class ColorSort:
|
|
100
|
+
def __init__(self):
|
|
101
|
+
self._dataToFilter = []
|
|
102
|
+
print("Raw Time:", time.time()) # Benchmark timetstamp for raw data before filtration
|
|
103
|
+
|
|
104
|
+
def sortData(self, dataToUnpack: List[float], isAscending: bool = True, isNumerical: bool = True) -> None:
|
|
105
|
+
# Sort the raw data with the above gradient mapping function (according to sort mode)
|
|
106
|
+
self._dataToFilter = list(dataToUnpack)
|
|
107
|
+
print("Raw Data:", self._dataToFilter)
|
|
108
|
+
|
|
109
|
+
if isNumerical: # Sort numerically
|
|
110
|
+
for value in self._dataToFilter:
|
|
111
|
+
mapValueToColorGradient(value, GradientMap)
|
|
112
|
+
else: # Sort alphabetically
|
|
113
|
+
for value in self._dataToFilter:
|
|
114
|
+
firstLetter = value[0].upper()
|
|
115
|
+
secondLetter = value[1].upper()
|
|
116
|
+
|
|
117
|
+
firstIndex = AlphabetMap[firstLetter]
|
|
118
|
+
secondIndex = AlphabetMap[secondLetter]
|
|
119
|
+
|
|
120
|
+
if secondIndex > firstIndex:
|
|
121
|
+
mapValueToColorGradient(secondIndex, GradientMap)
|
|
122
|
+
|
|
123
|
+
mapValueToColorGradient(firstIndex, GradientMap)
|
|
124
|
+
|
|
125
|
+
self._dataToFilter.sort(reverse = not isAscending)
|
|
126
|
+
|
|
127
|
+
print("Sorted Data: ", self._dataToFilter)
|
|
128
|
+
print("Sorted Time:", time.time()) # Benchmark timetstamp for sorted data after filtration
|
|
129
|
+
|
|
130
|
+
return self._dataToFilter
|
|
131
|
+
|
|
132
|
+
def __call__(self, dataToUnpack: List[float], *args) -> None:
|
|
133
|
+
isAscending = args[0] if args else True
|
|
134
|
+
self.sortData(dataToUnpack, isAscending)
|