algokit-py 0.1.0__tar.gz → 0.3.0__tar.gz
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.
- {algokit_py-0.1.0 → algokit_py-0.3.0}/PKG-INFO +25 -23
- algokit_py-0.3.0/README.md +42 -0
- algokit_py-0.3.0/algokit_py/__init__.py +8 -0
- {algokit_py-0.1.0 → algokit_py-0.3.0}/algokit_py/search/binary.py +3 -2
- algokit_py-0.3.0/algokit_py/sort/__init__.py +4 -0
- algokit_py-0.3.0/algokit_py/sort/insertion.py +26 -0
- algokit_py-0.3.0/algokit_py/sort/merge.py +43 -0
- {algokit_py-0.1.0 → algokit_py-0.3.0}/algokit_py.egg-info/PKG-INFO +25 -23
- {algokit_py-0.1.0 → algokit_py-0.3.0}/algokit_py.egg-info/SOURCES.txt +6 -1
- {algokit_py-0.1.0 → algokit_py-0.3.0}/pyproject.toml +2 -2
- algokit_py-0.3.0/tests/test_insertion.py +32 -0
- algokit_py-0.3.0/tests/test_merge.py +25 -0
- algokit_py-0.1.0/README.md +0 -40
- algokit_py-0.1.0/algokit_py/__init__.py +0 -8
- {algokit_py-0.1.0 → algokit_py-0.3.0}/algokit_py/search/__init__.py +0 -0
- {algokit_py-0.1.0 → algokit_py-0.3.0}/algokit_py/search/linear.py +0 -0
- {algokit_py-0.1.0 → algokit_py-0.3.0}/algokit_py.egg-info/dependency_links.txt +0 -0
- {algokit_py-0.1.0 → algokit_py-0.3.0}/algokit_py.egg-info/top_level.txt +0 -0
- {algokit_py-0.1.0 → algokit_py-0.3.0}/setup.cfg +0 -0
- {algokit_py-0.1.0 → algokit_py-0.3.0}/tests/test_binary.py +0 -0
- {algokit_py-0.1.0 → algokit_py-0.3.0}/tests/test_linear.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: algokit-py
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: A minimal Python algorithms library with clean implementations of search algorithms
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: A minimal Python algorithms library with clean implementations of search algorithms and sort algorithms
|
|
5
5
|
Author: Chanaka Prasanna
|
|
6
6
|
License: MIT
|
|
7
7
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -12,14 +12,28 @@ Description-Content-Type: text/markdown
|
|
|
12
12
|
|
|
13
13
|
# algokit-py
|
|
14
14
|
|
|
15
|
-
A lightweight Python algorithms library with clean, well-documented implementations.
|
|
15
|
+
A lightweight Python algorithms library with clean, well-documented, and tested implementations.
|
|
16
|
+
Designed for learning, interviews, and real-world algorithm reasoning.
|
|
16
17
|
|
|
17
18
|
## Features
|
|
19
|
+
|
|
20
|
+
### Search Algorithms
|
|
18
21
|
- Linear Search
|
|
19
|
-
- Binary Search
|
|
22
|
+
- Binary Search (iterative, invariant-based)
|
|
23
|
+
|
|
24
|
+
### Sorting Algorithms
|
|
25
|
+
- Insertion Sort (in-place, stable)
|
|
26
|
+
- Merge Sort (divide-and-conquer, O(n log n))
|
|
20
27
|
|
|
21
28
|
## Usage
|
|
22
29
|
|
|
30
|
+
### Install
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
pip install algokit-py
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Search
|
|
23
37
|
```python
|
|
24
38
|
from algokit_py.search import linear_search, binary_search
|
|
25
39
|
|
|
@@ -27,26 +41,14 @@ print(linear_search([1, 2, 3], 2))
|
|
|
27
41
|
print(binary_search([1, 2, 3], 2))
|
|
28
42
|
```
|
|
29
43
|
|
|
44
|
+
### Sorting
|
|
45
|
+
```python
|
|
46
|
+
from algokit_py.sort import insertion_sort, merge_sort
|
|
30
47
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## STEP 6: Local Install Test (Very Important)
|
|
36
|
-
|
|
37
|
-
From **project root**:
|
|
38
|
-
|
|
39
|
-
```powershell
|
|
40
|
-
pip install -e .
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Then test:
|
|
48
|
+
data = [3, 1, 2]
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
```
|
|
50
|
+
insertion_sort(data)
|
|
51
|
+
print(data) # [1, 2, 3]
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
```python
|
|
51
|
-
1
|
|
53
|
+
print(merge_sort([3, 1, 2])) # [1, 2, 3]
|
|
52
54
|
```
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# algokit-py
|
|
2
|
+
|
|
3
|
+
A lightweight Python algorithms library with clean, well-documented, and tested implementations.
|
|
4
|
+
Designed for learning, interviews, and real-world algorithm reasoning.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
### Search Algorithms
|
|
9
|
+
- Linear Search
|
|
10
|
+
- Binary Search (iterative, invariant-based)
|
|
11
|
+
|
|
12
|
+
### Sorting Algorithms
|
|
13
|
+
- Insertion Sort (in-place, stable)
|
|
14
|
+
- Merge Sort (divide-and-conquer, O(n log n))
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Install
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
pip install algokit-py
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Search
|
|
25
|
+
```python
|
|
26
|
+
from algokit_py.search import linear_search, binary_search
|
|
27
|
+
|
|
28
|
+
print(linear_search([1, 2, 3], 2))
|
|
29
|
+
print(binary_search([1, 2, 3], 2))
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Sorting
|
|
33
|
+
```python
|
|
34
|
+
from algokit_py.sort import insertion_sort, merge_sort
|
|
35
|
+
|
|
36
|
+
data = [3, 1, 2]
|
|
37
|
+
|
|
38
|
+
insertion_sort(data)
|
|
39
|
+
print(data) # [1, 2, 3]
|
|
40
|
+
|
|
41
|
+
print(merge_sort([3, 1, 2])) # [1, 2, 3]
|
|
42
|
+
```
|
|
@@ -16,10 +16,11 @@ At every step, the algorithm maintains a range that is guaranteed to contain the
|
|
|
16
16
|
from typing import Sequence, TypeVar
|
|
17
17
|
|
|
18
18
|
T = TypeVar('T')
|
|
19
|
-
# here we use Sequence because binary
|
|
19
|
+
# here we use Sequence because binary search does not support for not indexed iterables.
|
|
20
|
+
# Binary search requires a sorted sequence.
|
|
20
21
|
def binary_search(sequence: Sequence[T], target: T)-> int:
|
|
21
22
|
"""
|
|
22
|
-
This function will perform the binary search
|
|
23
|
+
This function will perform the binary search. Sequence must be a sorted sequence
|
|
23
24
|
|
|
24
25
|
:param sequence: sorted and indexed sequence
|
|
25
26
|
:param target: value that you want to find
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from typing import MutableSequence, TypeVar
|
|
2
|
+
|
|
3
|
+
T = TypeVar('T')
|
|
4
|
+
def insertion_sort(sequence: MutableSequence[T])-> None:
|
|
5
|
+
"""
|
|
6
|
+
At the start of iteration i, the subarray sequence[0:i] is sorted.
|
|
7
|
+
|
|
8
|
+
:param Mutable sequence
|
|
9
|
+
:return None
|
|
10
|
+
|
|
11
|
+
Worst Case Time Complexity: O(n²)
|
|
12
|
+
Space Complexity: O(1)
|
|
13
|
+
"""
|
|
14
|
+
length = len(sequence)
|
|
15
|
+
for i in range(1, length):
|
|
16
|
+
key = sequence[i]
|
|
17
|
+
j = i-1
|
|
18
|
+
while sequence[j] > key and j >= 0:
|
|
19
|
+
sequence[j+1]= sequence[j]
|
|
20
|
+
j -= 1
|
|
21
|
+
sequence[j + 1] = key
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from typing import Sequence, TypeVar
|
|
2
|
+
|
|
3
|
+
T = TypeVar('T')
|
|
4
|
+
|
|
5
|
+
def merge_sort(sequence: Sequence[T]) -> list[T]:
|
|
6
|
+
"""
|
|
7
|
+
Merge sort implementation.
|
|
8
|
+
|
|
9
|
+
Base case:
|
|
10
|
+
- Sequences of length 0 or 1 are already sorted.
|
|
11
|
+
|
|
12
|
+
Worst Case Time Complexity: O(n log n)
|
|
13
|
+
Space Complexity: O(n)
|
|
14
|
+
"""
|
|
15
|
+
if len(sequence) <= 1:
|
|
16
|
+
return list(sequence)
|
|
17
|
+
|
|
18
|
+
middle = len(sequence) // 2
|
|
19
|
+
left = sequence[:middle]
|
|
20
|
+
right = sequence[middle:]
|
|
21
|
+
|
|
22
|
+
sorted_left = merge_sort(left)
|
|
23
|
+
sorted_right = merge_sort(right)
|
|
24
|
+
|
|
25
|
+
merged = []
|
|
26
|
+
i = j = 0
|
|
27
|
+
|
|
28
|
+
while i < len(sorted_left) and j < len(sorted_right):
|
|
29
|
+
if sorted_left[i] <= sorted_right[j]:
|
|
30
|
+
merged.append(sorted_left[i])
|
|
31
|
+
i += 1
|
|
32
|
+
else:
|
|
33
|
+
merged.append(sorted_right[j])
|
|
34
|
+
j += 1
|
|
35
|
+
|
|
36
|
+
merged.extend(sorted_left[i:])
|
|
37
|
+
merged.extend(sorted_right[j:])
|
|
38
|
+
|
|
39
|
+
return merged
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: algokit-py
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: A minimal Python algorithms library with clean implementations of search algorithms
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: A minimal Python algorithms library with clean implementations of search algorithms and sort algorithms
|
|
5
5
|
Author: Chanaka Prasanna
|
|
6
6
|
License: MIT
|
|
7
7
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -12,14 +12,28 @@ Description-Content-Type: text/markdown
|
|
|
12
12
|
|
|
13
13
|
# algokit-py
|
|
14
14
|
|
|
15
|
-
A lightweight Python algorithms library with clean, well-documented implementations.
|
|
15
|
+
A lightweight Python algorithms library with clean, well-documented, and tested implementations.
|
|
16
|
+
Designed for learning, interviews, and real-world algorithm reasoning.
|
|
16
17
|
|
|
17
18
|
## Features
|
|
19
|
+
|
|
20
|
+
### Search Algorithms
|
|
18
21
|
- Linear Search
|
|
19
|
-
- Binary Search
|
|
22
|
+
- Binary Search (iterative, invariant-based)
|
|
23
|
+
|
|
24
|
+
### Sorting Algorithms
|
|
25
|
+
- Insertion Sort (in-place, stable)
|
|
26
|
+
- Merge Sort (divide-and-conquer, O(n log n))
|
|
20
27
|
|
|
21
28
|
## Usage
|
|
22
29
|
|
|
30
|
+
### Install
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
pip install algokit-py
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Search
|
|
23
37
|
```python
|
|
24
38
|
from algokit_py.search import linear_search, binary_search
|
|
25
39
|
|
|
@@ -27,26 +41,14 @@ print(linear_search([1, 2, 3], 2))
|
|
|
27
41
|
print(binary_search([1, 2, 3], 2))
|
|
28
42
|
```
|
|
29
43
|
|
|
44
|
+
### Sorting
|
|
45
|
+
```python
|
|
46
|
+
from algokit_py.sort import insertion_sort, merge_sort
|
|
30
47
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## STEP 6: Local Install Test (Very Important)
|
|
36
|
-
|
|
37
|
-
From **project root**:
|
|
38
|
-
|
|
39
|
-
```powershell
|
|
40
|
-
pip install -e .
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Then test:
|
|
48
|
+
data = [3, 1, 2]
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
```
|
|
50
|
+
insertion_sort(data)
|
|
51
|
+
print(data) # [1, 2, 3]
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
```python
|
|
51
|
-
1
|
|
53
|
+
print(merge_sort([3, 1, 2])) # [1, 2, 3]
|
|
52
54
|
```
|
|
@@ -8,5 +8,10 @@ algokit_py.egg-info/top_level.txt
|
|
|
8
8
|
algokit_py/search/__init__.py
|
|
9
9
|
algokit_py/search/binary.py
|
|
10
10
|
algokit_py/search/linear.py
|
|
11
|
+
algokit_py/sort/__init__.py
|
|
12
|
+
algokit_py/sort/insertion.py
|
|
13
|
+
algokit_py/sort/merge.py
|
|
11
14
|
tests/test_binary.py
|
|
12
|
-
tests/
|
|
15
|
+
tests/test_insertion.py
|
|
16
|
+
tests/test_linear.py
|
|
17
|
+
tests/test_merge.py
|
|
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "algokit-py"
|
|
7
|
-
version = "0.
|
|
8
|
-
description = "A minimal Python algorithms library with clean implementations of search algorithms"
|
|
7
|
+
version = "0.3.0"
|
|
8
|
+
description = "A minimal Python algorithms library with clean implementations of search algorithms and sort algorithms"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
11
11
|
license = {text = "MIT"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
from algokit_py.sort import insertion_sort
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_insertion_sort_basic():
|
|
6
|
+
data = [3, 1, 2]
|
|
7
|
+
insertion_sort(data)
|
|
8
|
+
assert data == [1, 2, 3]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_insertion_sort_already_sorted():
|
|
12
|
+
data = [1, 2, 3, 4]
|
|
13
|
+
insertion_sort(data)
|
|
14
|
+
assert data == [1, 2, 3, 4]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_insertion_sort_reverse():
|
|
18
|
+
data = [4, 3, 2, 1]
|
|
19
|
+
insertion_sort(data)
|
|
20
|
+
assert data == [1, 2, 3, 4]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_insertion_sort_single_element():
|
|
24
|
+
data = [5]
|
|
25
|
+
insertion_sort(data)
|
|
26
|
+
assert data == [5]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_insertion_sort_empty():
|
|
30
|
+
data = []
|
|
31
|
+
insertion_sort(data)
|
|
32
|
+
assert data == []
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from algokit_py.sort import merge_sort
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_merge_sort_basic():
|
|
5
|
+
assert merge_sort([3, 1, 2]) == [1, 2, 3]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_merge_sort_already_sorted():
|
|
9
|
+
assert merge_sort([1, 2, 3, 4]) == [1, 2, 3, 4]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_merge_sort_reverse():
|
|
13
|
+
assert merge_sort([4, 3, 2, 1]) == [1, 2, 3, 4]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_merge_sort_single_element():
|
|
17
|
+
assert merge_sort([5]) == [5]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_merge_sort_empty():
|
|
21
|
+
assert merge_sort([]) == []
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_merge_sort_duplicates():
|
|
25
|
+
assert merge_sort([3, 1, 2, 1]) == [1, 1, 2, 3]
|
algokit_py-0.1.0/README.md
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# algokit-py
|
|
2
|
-
|
|
3
|
-
A lightweight Python algorithms library with clean, well-documented implementations.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
- Linear Search
|
|
7
|
-
- Binary Search
|
|
8
|
-
|
|
9
|
-
## Usage
|
|
10
|
-
|
|
11
|
-
```python
|
|
12
|
-
from algokit_py.search import linear_search, binary_search
|
|
13
|
-
|
|
14
|
-
print(linear_search([1, 2, 3], 2))
|
|
15
|
-
print(binary_search([1, 2, 3], 2))
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
We will improve this later.
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## STEP 6: Local Install Test (Very Important)
|
|
24
|
-
|
|
25
|
-
From **project root**:
|
|
26
|
-
|
|
27
|
-
```powershell
|
|
28
|
-
pip install -e .
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
Then test:
|
|
32
|
-
|
|
33
|
-
```powershell
|
|
34
|
-
python -c "from algokit_py.search import binary_search; print(binary_search([1,2,3], 2))"
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
You must see:
|
|
38
|
-
```python
|
|
39
|
-
1
|
|
40
|
-
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|