Skip to content

Commit 45b2330

Browse files
committed
add readme
1 parent ac4d6a5 commit 45b2330

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
selectlib
2+
=========
3+
4+
selectlib is a lightweight C extension module for Python that implements the quickselect algorithm. Quickselect is an efficient selection algorithm to find the kth smallest element in an unsorted list without fully sorting the data. The module supports an optional key function, allowing for flexible comparisons and custom ordering.
5+
6+
Features
7+
--------
8+
9+
• Fast in-place selection using a C implementation
10+
• Optional key function for custom comparisons
11+
• Compatibility with Python 3.8 and later
12+
• Easily integratable into your Python projects
13+
14+
Installation
15+
------------
16+
17+
The selectlib module can be installed via pip after building from source. First, ensure you have a C compiler and Python development headers installed for your platform.
18+
19+
1. Clone the repository:
20+
21+
git clone https://github.com/grantjenks/python-selectlib.git
22+
cd python-selectlib
23+
24+
2. Build and install:
25+
26+
python -m pip install -e .
27+
28+
Usage Example
29+
-------------
30+
31+
Below is a simple example using quickselect to find the kth smallest element in a list:
32+
33+
import selectlib
34+
35+
data = [9, 3, 7, 1, 5, 8, 2]
36+
k = 3 # Find the element that would be at index 3 if sorted
37+
selectlib.quickselect(data, k)
38+
39+
print("The kth smallest element is:", data[k])
40+
41+
Using a key function to find the kth largest element:
42+
43+
data = [15, 8, 22, 5, 13]
44+
k = 2 # kth largest element when sorted in descending order
45+
selectlib.quickselect(data, k, key=lambda x: -x)
46+
47+
print("The kth largest element is:", data[k])
48+
49+
Testing
50+
-------
51+
52+
You can run the automated tests using tox. The tests validate both correct partitioning and error cases.
53+
54+
tox
55+
56+
This will run tests on Python versions 3.8 through 3.13, as well as linting and formatting checks.
57+
58+
Development & Continuous Integration
59+
--------------------------------------
60+
61+
This project uses GitHub Actions for CI/CD. The following workflows are available:
62+
63+
• release.yml – Builds wheels for multiple platforms and publishes packages to PyPI
64+
• test.yml – Runs tests and linting on multiple Python versions
65+
66+
Contributing
67+
------------
68+
69+
Contributions are welcome! If you find any bugs, have feature suggestions, or want to contribute improvements, feel free to open an issue or pull request on GitHub.
70+
71+
Building Documentation
72+
----------------------
73+
74+
Documentation is provided within the source code and inline comments. For additional usage examples or API details, please refer to the source and test files.
75+
76+
License
77+
-------
78+
79+
selectlib is licensed under the Apache License, Version 2.0. See the LICENSE file for details.

0 commit comments

Comments
 (0)