Skip to content

Commit

Permalink
Merge pull request #37 from burpeesDaily/python311
Browse files Browse the repository at this point in the history
Update Python version to 3.11
  • Loading branch information
burpeesDaily committed Feb 26, 2024
2 parents c12da9c + 2fafdd2 commit 463b525
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
python-version: [3.11]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
python-version: [3.11]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -23,7 +23,7 @@ and informative purposes.

Requirements
------------
``Python 3.9`` or newer is required.
``Python 3.11`` or newer is required.


Installation
Expand Down
1 change: 1 addition & 0 deletions examples/multithreading_not_safe.py
@@ -1,4 +1,5 @@
"""Demonstrate the trees are not thread-safe in write contention situation."""

import threading
import sys

Expand Down
1 change: 1 addition & 0 deletions examples/multithreading_not_safe_read_write.py
@@ -1,4 +1,5 @@
"""Demonstrate the trees are not thread-safe in read-write contention situation."""

import threading
import sys

Expand Down
1 change: 1 addition & 0 deletions examples/multithreading_performance.py
@@ -1,4 +1,5 @@
"""Module to measure the performance using multithreading."""

import threading
import time

Expand Down
1 change: 1 addition & 0 deletions examples/multithreading_safe.py
@@ -1,4 +1,5 @@
"""Example to show atomic trees are thread-safe in write contention situation."""

import threading
import sys

Expand Down
1 change: 1 addition & 0 deletions examples/multithreading_safe_read_write.py
@@ -1,4 +1,5 @@
"""Example to show atomic trees are thread-safe in read-write contention situation."""

import threading
import sys

Expand Down
29 changes: 17 additions & 12 deletions forest/binary_trees/red_black_tree.py
Expand Up @@ -5,8 +5,7 @@
"""Red-Black Tree."""

import enum

from dataclasses import dataclass
import dataclasses

from typing import Any, Optional, Union

Expand All @@ -22,14 +21,14 @@ class Color(enum.Enum):
BLACK = enum.auto()


@dataclass
@dataclasses.dataclass(frozen=True)
class Leaf:
"""Definition Red-Black Tree Leaf node whose color is always black."""

color = Color.BLACK


@dataclass
@dataclasses.dataclass
class Node:
"""Red-Black Tree non-leaf node definition."""

Expand Down Expand Up @@ -518,14 +517,17 @@ def _delete_fixup(self, fixing_node: Union[Leaf, Node]) -> None:
else:
# Case 3: the sibling is black and its left child is red.
if sibling.right.color == Color.BLACK: # type: ignore
sibling.left.color = Color.BLACK # type: ignore
if sibling.left.color is not Color.BLACK:
sibling.left.color = Color.BLACK # type: ignore
sibling.color = Color.RED # type: ignore
self._right_rotate(node_x=sibling) # type: ignore

# Case 4: the sibling is black and its right child is red.
sibling.color = fixing_node.parent.color # type: ignore
fixing_node.parent.color = Color.BLACK # type: ignore
sibling.right.color = Color.BLACK # type: ignore
if fixing_node.parent.color is not Color.BLACK: # type: ignore
fixing_node.parent.color = Color.BLACK # type: ignore
if sibling.right.color is not Color.BLACK:
sibling.right.color = Color.BLACK # type: ignore
self._left_rotate(node_x=fixing_node.parent) # type: ignore
# Once we are here, all the violation has been fixed, so
# move to the root to terminate the loop.
Expand All @@ -552,19 +554,22 @@ def _delete_fixup(self, fixing_node: Union[Leaf, Node]) -> None:
else:
# Case 7: the sibling is black and its right child is red.
if sibling.left.color == Color.BLACK: # type: ignore
sibling.right.color = Color.BLACK # type: ignore
if sibling.right.color is not Color.BLACK:
sibling.right.color = Color.BLACK # type: ignore
sibling.color = Color.RED
self._left_rotate(node_x=sibling) # type: ignore
# Case 8: the sibling is black and its left child is red.
sibling.color = fixing_node.parent.color # type: ignore
fixing_node.parent.color = Color.BLACK # type: ignore
sibling.left.color = Color.BLACK # type: ignore
if fixing_node.parent.color is not Color.BLACK: # type: ignore
fixing_node.parent.color = Color.BLACK # type: ignore
if sibling.left.color is not Color.BLACK:
sibling.left.color = Color.BLACK # type: ignore
self._right_rotate(node_x=fixing_node.parent) # type: ignore
# Once we are here, all the violation has been fixed, so
# move to the root to terminate the loop.
fixing_node = self.root

fixing_node.color = Color.BLACK
if fixing_node.color is not Color.BLACK:
fixing_node.color = Color.BLACK

def _transplant(
self, deleting_node: Node, replacing_node: Union[Node, Leaf]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -6,7 +6,7 @@ authors = [
]
description = "The Forest Project in Python"
readme = {file = "README.rst", content-type = "text/x-rst"}
requires-python = ">=3.9"
requires-python = ">=3.11"
license = {text = "MIT License"}
classifiers = [
"License :: OSI Approved :: MIT License",
Expand Down
1 change: 1 addition & 0 deletions tests/test_atomic_trees.py
@@ -1,4 +1,5 @@
"""Unit tests for atomic trees."""

import sys
import threading

Expand Down

0 comments on commit 463b525

Please sign in to comment.