|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Commands |
| 6 | + |
| 7 | +This project uses `uv` for dependency management and `just` as the command runner. |
| 8 | + |
| 9 | +```bash |
| 10 | +just sync # install/sync dependencies (uv sync --all-groups) |
| 11 | +just lint # uv run ruff check . --fix && uv run ruff format . |
| 12 | +just test # uv run pytest |
| 13 | +uv run pytest tests/algorithm_theory/test_binary_search.py # run one test file |
| 14 | +uv run pytest tests/algorithm_theory/test_binary_search.py::test_binary_search_iterative # run one test |
| 15 | +uv add {package} # add a dependency |
| 16 | +``` |
| 17 | + |
| 18 | +There is no separate build step; this is a pure Python (3.14+) library of algorithms with no runtime dependencies. |
| 19 | + |
| 20 | +## Architecture |
| 21 | + |
| 22 | +The repo is organized by topic into top-level directories, each containing implementation modules directly at the |
| 23 | +top level (no `src/` layout). `pyproject.toml` sets `pythonpath = ["."]`, so both implementation and test code |
| 24 | +import via the top-level package name, e.g. `from algorithm_theory.binary_search import binary_search_iterative`. |
| 25 | + |
| 26 | +Three categories of top-level directories, per the root `README.md`: |
| 27 | + |
| 28 | +- **`algorithm_theory/`** — canonical/fundamental algorithm approaches (e.g. binary/jump/linear search, bubble |
| 29 | + sort). |
| 30 | +- **`data_structures/`** — custom implementations of core data structures (binary tree, linked lists, queue, |
| 31 | + stack, trie) that other topic directories' problems build on top of. |
| 32 | +- **Topic/problem directories** (`arrays/`, `binary_search/`, `binary_tree/`, `circularly_linked_list/`, |
| 33 | + `doubly_linked_list/`, `integers/`, `math_problems/`, `multi_dimensional_arrays/`, `n_ary_tree/`, `queues/`, |
| 34 | + `singly_linked_lists/`, `stacks/`, `strings/`, `trie/`) |
| 35 | + |
| 36 | +The problem description, constraints, and examples live as a |
| 37 | +**doc comment directly on the function/class that solves it** (see any existing file, e.g. |
| 38 | +`arrays/two_sum.py`, as the template when adding a new problem). Only when a file genuinely has multiple |
| 39 | +top-level functions/classes for one problem (e.g. a brute-force and an optimized approach, like |
| 40 | +`stacks/daily_temperatures.py`) does it use a module-level docstring for the shared problem statement plus a |
| 41 | +short docstring per function for the approach-specific detail — a single-function file should never have both a module docstring and a redundant function docstring. |
| 42 | + |
| 43 | +Tests live under `tests/<same-directory-name>/test_<module>.py`, mirroring the source layout 1:1 (e.g. |
| 44 | +`algorithm_theory/binary_search.py` → `tests/algorithm_theory/test_binary_search.py`). `test_helpers/test_helpers.py` |
| 45 | +holds shared builders/fixtures (e.g. `get_binary_search_tree`, `get_singly_linked_list`) used across multiple test |
| 46 | +directories for constructing trees and linked lists — check there before writing new setup code for tree/list-based |
| 47 | +tests. |
| 48 | + |
| 49 | +Node/structure classes used across multiple directories (e.g. `binary_tree.tree_node.TreeNode`, |
| 50 | +`data_structures.singly_linked_list_node.SinglyLinkedListNode`, `n_ary_tree.nary_tree_node.NaryTreeNode`) are |
| 51 | +imported directly from their defining module rather than redefined per problem. |
| 52 | + |
| 53 | +## Style |
| 54 | + |
| 55 | +Ruff is configured in `pyproject.toml` (line length 100, target `py314`, rule sets `E, F, W, I, N, D`). Docstring |
| 56 | +presence itself is not enforced (`D100-D107` ignored), but when docstrings are present their formatting is linted. |
| 57 | +`tests/*` is exempt from docstring rules entirely. Solutions favor explicit, readable Python over terse one-liners |
| 58 | +(stated explicitly in the root `README.md`). |
0 commit comments