Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -24,15 +24,21 @@ jobs:
- name: Install dependencies
run: poetry install --no-root

- name: Analysing the code with flake8
run: poetry run flake8 --count basic_data_structure/
- name: Run isort
run: poetry run isort . --check-only

- name: Run ruff check
run: poetry run ruff check

- name: Run ruff format
run: poetry run ruff format --check


test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -65,7 +71,7 @@ jobs:
- name: Set up Python & Poetry
uses: mishaga/action-poetry@1
with:
python-version: '3.12'
python-version: '3.13'

- name: Install dependencies
run: poetry install --no-root
Expand Down
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pycqa/isort
rev: 6.0.1
hooks:
- id: isort
name: isort

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.9
hooks:
- id: ruff
args: [ --fix ]
name: ruff check
- id: ruff-format
name: ruff format
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2024 Mikhail Shagov
Copyright (c) 2024-2025 Mikhail Shagov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Expected data structures in future versions:
3. Actual binary tree class (now package contains `TreeNode` class only)
4. Red-black tree

Supported python versions: `3.9` → `3.12`
Supported python versions: `3.9` → `3.13`

Links:

* [GitHub](https://github.com/mishaga/basic_data_structure)
* [GitHub](https://github.com/mishaga/basic-data-structure)
* [PyPi](https://pypi.org/project/basic-data-structure/)
* [Documentation](https://mishaga.github.io/basic_data_structure/)
* [Documentation](https://mishaga.github.io/basic-data-structure/)

Install:

Expand Down
15 changes: 7 additions & 8 deletions basic_data_structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
3. Actual binary tree class (now package contains `TreeNode` class only)
4. Red-black tree

Supported python versions: `3.9` → `3.12`
Supported python versions: `3.9` → `3.13`

Links:

* [GitHub](https://github.com/mishaga/basic_data_structure)
* [GitHub](https://github.com/mishaga/basic-data-structure)
* [PyPi](https://pypi.org/project/basic-data-structure/)
* [Documentation](https://mishaga.github.io/basic_data_structure/)
* [Documentation](https://mishaga.github.io/basic-data-structure/)

Installation:

Expand Down Expand Up @@ -182,8 +182,7 @@ def main():
```
"""


from basic_data_structure.linked_list import LinkedList
from basic_data_structure.nodes.list_node import ListNode
from basic_data_structure.nodes.tree_node import TreeNode
from basic_data_structure.stack import Stack
from basic_data_structure.linked_list import LinkedList as LinkedList
from basic_data_structure.nodes.list_node import ListNode as ListNode
from basic_data_structure.nodes.tree_node import TreeNode as TreeNode
from basic_data_structure.stack import Stack as Stack
20 changes: 9 additions & 11 deletions basic_data_structure/linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,11 @@ def main():
NotListNodeError,
)
from basic_data_structure.iterators.list_node_iterator import ListNodeIterator
from basic_data_structure.iterators.list_value_iterator import (
ListValueIterator,
)
from basic_data_structure.iterators.list_value_iterator import ListValueIterator
from basic_data_structure.nodes.list_node import ListNode


class LinkedList: # noqa: WPS214 Found too many methods
class LinkedList:
"""Linked list data structure."""

def __init__(self, *args) -> None:
Expand Down Expand Up @@ -224,7 +222,7 @@ def __getitem__(self, index: int) -> ListNode:

raise ListIndexOfRangeError

def __delitem__(self, index: int) -> None: # noqa: WPS603 Found using restricted magic method
def __delitem__(self, index: int) -> None:
"""Delete a node at a specific index.

Time complexity: `O(n)`
Expand Down Expand Up @@ -321,7 +319,7 @@ def head(self, new_head: Optional[ListNode]) -> None:
raise NotListNodeError
self.__head = new_head

def values(self) -> ListValueIterator: # noqa: WPS110 Found wrong variable name
def values(self) -> ListValueIterator:
"""Return values iterator.

On each call `next` function on the iterator, you'll be given actual value of a `ListNode`,
Expand Down Expand Up @@ -349,7 +347,7 @@ def values(self) -> ListValueIterator: # noqa: WPS110 Found wrong variable name

def append(
self,
value: Any, # noqa: WPS110 Found wrong variable name
value: Any,
) -> None:
"""Append value to the end of list.

Expand Down Expand Up @@ -389,7 +387,7 @@ def append(

def prepend(
self,
value: Any, # noqa: WPS110 Found wrong variable name
value: Any,
) -> None:
"""Prepend a value to the list (add to the beginning).

Expand All @@ -409,7 +407,7 @@ def prepend(
def insert(
self,
index: int,
value: Any, # noqa: WPS110 Found wrong variable name
value: Any,
) -> None:
"""Insert value into given index.

Expand Down Expand Up @@ -493,7 +491,7 @@ def reverse(self) -> None:

self.__head = previous

def rotate(self, count: int) -> None: # noqa: WPS210 Found too many local variables
def rotate(self, count: int) -> None:
"""Rotate (shift) list.

To rotate right, pass a positive value. To rotate left, pass a negative value.
Expand Down Expand Up @@ -523,7 +521,7 @@ def rotate(self, count: int) -> None: # noqa: WPS210 Found too many local varia
if length < 2:
return

count = count % length # noqa: WPS350 Found usable augmented assign pattern
count = count % length
if count == 0:
return

Expand Down
4 changes: 2 additions & 2 deletions basic_data_structure/nodes/list_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ListNode:

def __init__(
self,
value: Any, # noqa: WPS110 Found wrong variable name
value: Any,
nxt: Optional['ListNode'] = None,
):
"""Init a list node.
Expand All @@ -43,5 +43,5 @@ def __init__(
value: a value of the node
nxt: (optional) link to next node
"""
self.value = value # noqa: WPS110 Found wrong variable name
self.value = value
self.next = nxt
4 changes: 2 additions & 2 deletions basic_data_structure/nodes/tree_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class TreeNode:

def __init__(
self,
value: Any, # noqa: WPS110 Found wrong variable name
value: Any,
left: Optional['TreeNode'] = None,
right: Optional['TreeNode'] = None,
) -> None:
Expand All @@ -109,6 +109,6 @@ def __init__(
left: (optional) left child of the node
right: (optional) right child of the node
"""
self.value = value # noqa: WPS110 Found wrong variable name
self.value = value
self.left = left
self.right = right
2 changes: 1 addition & 1 deletion basic_data_structure/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __len__(self) -> int:

def push(
self,
value: Any, # noqa: WPS110 Found wrong variable name
value: Any,
) -> None:
"""Add a new element to the stack.

Expand Down
Loading