algokit-py 0.1.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.
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.4
2
+ Name: algokit-py
3
+ Version: 0.1.0
4
+ Summary: A minimal Python algorithms library with clean implementations of search algorithms
5
+ Author: Chanaka Prasanna
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+
13
+ # algokit-py
14
+
15
+ A lightweight Python algorithms library with clean, well-documented implementations.
16
+
17
+ ## Features
18
+ - Linear Search
19
+ - Binary Search
20
+
21
+ ## Usage
22
+
23
+ ```python
24
+ from algokit_py.search import linear_search, binary_search
25
+
26
+ print(linear_search([1, 2, 3], 2))
27
+ print(binary_search([1, 2, 3], 2))
28
+ ```
29
+
30
+
31
+ We will improve this later.
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:
44
+
45
+ ```powershell
46
+ python -c "from algokit_py.search import binary_search; print(binary_search([1,2,3], 2))"
47
+ ```
48
+
49
+ You must see:
50
+ ```python
51
+ 1
52
+ ```
@@ -0,0 +1,40 @@
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
+ ```
@@ -0,0 +1,8 @@
1
+ """
2
+ algokit_py - A minimal Python algorithms library
3
+ """
4
+
5
+ from algokit_py.search import binary_search, linear_search
6
+
7
+ __version__ = "0.1.0"
8
+ __all__ = ["binary_search", "linear_search"]
@@ -0,0 +1,4 @@
1
+ from .linear import linear_search
2
+ from .binary import binary_search
3
+
4
+ __all__ = ["linear_search", "binary_search"]
@@ -0,0 +1,46 @@
1
+ """
2
+ The True Minimum Requirements for Binary Search
3
+ Now we can state them precisely:
4
+ - The data must be sorted
5
+ - The data must support random access (you must be able to get the middle element)
6
+ - The elements must be comparable to the target
7
+
8
+ Every step of binary search answers one question only:
9
+ - "Which half can I safely throw away without losing the target?"
10
+
11
+ For binary search, always remember this sentence:
12
+ At every step, the algorithm maintains a range that is guaranteed to contain the target if it exists.
13
+
14
+ """
15
+
16
+ from typing import Sequence, TypeVar
17
+
18
+ T = TypeVar('T')
19
+ # here we use Sequence because binary seach does not support for unindexed iterables
20
+ def binary_search(sequence: Sequence[T], target: T)-> int:
21
+ """
22
+ This function will perform the binary search
23
+
24
+ :param sequence: sorted and indexed sequence
25
+ :param target: value that you want to find
26
+ :return: return index of a occurrence, -1 if target is not found
27
+
28
+
29
+ Time Complexity: O(log(n))
30
+ Space Complexity: O(1)
31
+ """
32
+
33
+ left,right = 0, len(sequence)-1
34
+
35
+ while left <= right:
36
+ mid = (left + right) // 2
37
+
38
+ if sequence[mid] == target:
39
+ return mid
40
+
41
+ if target < sequence[mid]:
42
+ right = mid - 1
43
+ else:
44
+ left = mid +1
45
+
46
+ return -1
@@ -0,0 +1,19 @@
1
+ from typing import TypeVar, Iterable
2
+
3
+ T = TypeVar('T')
4
+ def linear_search(iterable: Iterable[T] , target: T)-> int:
5
+ """
6
+ This function do linear search.
7
+
8
+ :param iterable:
9
+ :param target:
10
+ :return: return index of first occurrence, -1 if target is not found
11
+
12
+ Time complexity: O(n)
13
+ Space complexity: O(1)
14
+ """
15
+ for i,v in enumerate(iterable):
16
+ if v == target:
17
+ return i
18
+
19
+ return -1
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.4
2
+ Name: algokit-py
3
+ Version: 0.1.0
4
+ Summary: A minimal Python algorithms library with clean implementations of search algorithms
5
+ Author: Chanaka Prasanna
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+
13
+ # algokit-py
14
+
15
+ A lightweight Python algorithms library with clean, well-documented implementations.
16
+
17
+ ## Features
18
+ - Linear Search
19
+ - Binary Search
20
+
21
+ ## Usage
22
+
23
+ ```python
24
+ from algokit_py.search import linear_search, binary_search
25
+
26
+ print(linear_search([1, 2, 3], 2))
27
+ print(binary_search([1, 2, 3], 2))
28
+ ```
29
+
30
+
31
+ We will improve this later.
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:
44
+
45
+ ```powershell
46
+ python -c "from algokit_py.search import binary_search; print(binary_search([1,2,3], 2))"
47
+ ```
48
+
49
+ You must see:
50
+ ```python
51
+ 1
52
+ ```
@@ -0,0 +1,12 @@
1
+ README.md
2
+ pyproject.toml
3
+ algokit_py/__init__.py
4
+ algokit_py.egg-info/PKG-INFO
5
+ algokit_py.egg-info/SOURCES.txt
6
+ algokit_py.egg-info/dependency_links.txt
7
+ algokit_py.egg-info/top_level.txt
8
+ algokit_py/search/__init__.py
9
+ algokit_py/search/binary.py
10
+ algokit_py/search/linear.py
11
+ tests/test_binary.py
12
+ tests/test_linear.py
@@ -0,0 +1 @@
1
+ algokit_py
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "algokit-py"
7
+ version = "0.1.0"
8
+ description = "A minimal Python algorithms library with clean implementations of search algorithms"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = {text = "MIT"}
12
+
13
+ authors = [
14
+ {name = "Chanaka Prasanna"}
15
+ ]
16
+
17
+ classifiers = [
18
+ "Programming Language :: Python :: 3",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Operating System :: OS Independent",
21
+ ]
22
+
23
+ [tool.setuptools.packages.find]
24
+ where = ["."]
25
+ include = ["algokit_py*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,17 @@
1
+ from algokit_py.search import binary_search
2
+
3
+
4
+ def test_binary_search_found():
5
+ assert binary_search([1, 2, 3, 4, 5], 4) == 3
6
+
7
+
8
+ def test_binary_search_not_found():
9
+ assert binary_search([1, 2, 3, 4, 5], 10) == -1
10
+
11
+
12
+ def test_binary_search_single_element():
13
+ assert binary_search([7], 7) == 0
14
+
15
+
16
+ def test_binary_search_empty():
17
+ assert binary_search([], 1) == -1
@@ -0,0 +1,18 @@
1
+ from algokit_py.search import linear_search
2
+
3
+
4
+ def test_linear_search_found():
5
+ assert linear_search([1, 2, 3, 4], 3) == 2
6
+
7
+
8
+ def test_linear_search_not_found():
9
+ assert linear_search([1, 2, 3, 4], 5) == -1
10
+
11
+
12
+ def test_linear_search_empty():
13
+ assert linear_search([], 1) == -1
14
+
15
+
16
+ def test_linear_search_generator():
17
+ gen = (x for x in [10, 20, 30])
18
+ assert linear_search(gen, 20) == 1