Skip to content

Commit

Permalink
refactor: added new package Nodes to segregate Nodes from Structures
Browse files Browse the repository at this point in the history
  • Loading branch information
warmachine028 committed Jul 29, 2023
1 parent e55320f commit 1ef8ce2
Show file tree
Hide file tree
Showing 67 changed files with 119 additions and 110 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ venv.bak/

# mypy
.mypy_cache/
out/
.dmypy.json
dmypy.json

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pip install datastax
Usage
> py datastax <data-structure> [data]
Data Structures:
-> trees Hierarchical DS
-> Trees Hierarchical DS
-> linkedlists Linear DS
-> arrays Fixed Size Linear DS
Expand Down
3 changes: 3 additions & 0 deletions datastax/Arrays/AbstractArrays/Queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ def dequeue(self) -> Any:
@abstractmethod
def peek(self) -> Any:
...

def __len__(self):
return len(self.array)
3 changes: 0 additions & 3 deletions datastax/Arrays/Queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ def dequeue(self) -> Any:
self._front += 1
return deleted_item

def __len__(self):
return len(self.array)

def peek(self) -> Any:
if self.is_empty() or self._front >= self._rear:
return "QUEUE EMPTY"
Expand Down
6 changes: 3 additions & 3 deletions datastax/Lists/AbstractLists/CircularLinkedList.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from abc import ABC
from abc import ABC as AbstractClass
from typing import Optional
from datastax.Nodes.AbstractNodes import Node
from datastax.Lists.AbstractLists.LinkedList import LinkedList
from datastax.Utils import Commons
from datastax.Lists.AbstractLists.Node import Node


class CircularLinkedList(LinkedList, ABC):
class CircularLinkedList(LinkedList, AbstractClass):
def _max_width(self, node: Optional[Node]):
max_width = 0
ref = node
Expand Down
5 changes: 2 additions & 3 deletions datastax/Lists/AbstractLists/DoublyCircularList.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from abc import ABC

from abc import ABC as AbstractClass
from datastax.Lists.AbstractLists.CircularLinkedList import CircularLinkedList
from datastax.Lists.AbstractLists.DoublyLinkedList import DoublyLinkedList
from datastax.Utils import Commons


class DoublyCircularList(DoublyLinkedList, CircularLinkedList, ABC):
class DoublyCircularList(DoublyLinkedList, CircularLinkedList, AbstractClass):

def __str__(self):
if not self.head:
Expand Down
6 changes: 3 additions & 3 deletions datastax/Lists/AbstractLists/DoublyLinkedList.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from abc import ABC
from abc import ABC as AbstractClass
from typing import Optional
from datastax.Nodes.AbstractNodes import DoublyNode
from datastax.Lists.AbstractLists.LinkedList import LinkedList
from datastax.Utils import Commons
from datastax.Lists.AbstractLists.DoublyNode import DoublyNode


class DoublyLinkedList(LinkedList, ABC):
class DoublyLinkedList(LinkedList, AbstractClass):
_head: Optional[DoublyNode] = None
_tail: Optional[DoublyNode] = None

Expand Down
2 changes: 1 addition & 1 deletion datastax/Lists/AbstractLists/LinkedList.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Optional, Self, Iterable
from datastax.Lists.AbstractLists.Node import Node
from datastax.Utils import Commons
from abc import abstractmethod, ABC as AbstractClass
from datastax.Nodes.AbstractNodes import Node


class LinkedList(AbstractClass):
Expand Down
6 changes: 3 additions & 3 deletions datastax/Lists/AbstractLists/Queue.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from abc import ABC, abstractmethod
from abc import ABC as AbstractClass, abstractmethod
from typing import Optional, Any
from datastax.Nodes.AbstractNodes import Node
from datastax.Lists.AbstractLists.LinkedList import LinkedList
from datastax.Lists.AbstractLists.Node import Node
from datastax.Utils import Commons


class Queue(LinkedList, ABC):
class Queue(LinkedList, AbstractClass):
_capacity = 0
_rear = 0

Expand Down
14 changes: 5 additions & 9 deletions datastax/Lists/AbstractLists/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,16 @@
Author: Pritam Kundu
Date: 2023-07-10
"""
from .Node import Node
from .DoublyNode import DoublyNode
from .LinkedList import LinkedList
from .DoublyLinkedList import DoublyLinkedList
from .CircularLinkedList import CircularLinkedList
from .DoublyCircularList import DoublyCircularList
from .Queue import Queue

__all__ = [
'Node',
'DoublyNode',
'LinkedList',
'DoublyLinkedList',
'CircularLinkedList',
'DoublyCircularList',
'Queue'
LinkedList,
DoublyLinkedList,
CircularLinkedList,
DoublyCircularList,
Queue
]
2 changes: 1 addition & 1 deletion datastax/Lists/DoublyLinkedList.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Optional, Iterable, Self

from datastax.Lists.DoublyNode import DoublyNode
from datastax.Nodes import DoublyNode
from datastax.Lists.LinkedList import LinkedList
from datastax.Lists.AbstractLists import DoublyLinkedList as AbstractList

Expand Down
2 changes: 1 addition & 1 deletion datastax/Lists/LRUCache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from typing import Any

from datastax.Lists.DoublyLinkedList import DoublyLinkedList
from datastax.Lists.DoublyNode import DoublyNode
from datastax.Nodes import DoublyNode


class LRUCache(DoublyLinkedList):
Expand Down
2 changes: 1 addition & 1 deletion datastax/Lists/LinkedList.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Optional, Iterable, Self

from datastax.Lists.Node import Node
from datastax.Nodes import Node
from datastax.Lists.AbstractLists import LinkedList as AbstractLinkedList


Expand Down
2 changes: 1 addition & 1 deletion datastax/Lists/Queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from sys import maxsize
from typing import Any, Optional, Sequence, Self
from datastax.Lists.Node import Node
from datastax.Nodes import Node
from datastax.errors import OverFlowError, UnderFlowError
from datastax.Lists.LinkedList import LinkedList
from datastax.Lists.AbstractLists import Queue as AbstractQueue
Expand Down
16 changes: 6 additions & 10 deletions datastax/Lists/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from .Node import Node
from .DoublyNode import DoublyNode
from .LinkedList import LinkedList
from .DoublyLinkedList import DoublyLinkedList
from .CircularLinkedList import CircularLinkedList
Expand All @@ -8,12 +6,10 @@
from .Queue import Queue

__all__ = [
'Node',
'DoublyNode',
'LinkedList',
'DoublyLinkedList',
'CircularLinkedList',
'DoublyCircularList',
'Queue',
'LRUCache'
LinkedList,
DoublyLinkedList,
CircularLinkedList,
DoublyCircularList,
Queue,
LRUCache
]
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from abc import ABC
from abc import ABC as AbstractClass
from typing import Optional, Self

from datastax.Lists.AbstractLists.Node import Node
from datastax.Nodes.AbstractNodes.Node import Node
from datastax.Utils import Commons


class DoublyNode(Node, ABC):
class DoublyNode(Node, AbstractClass):
_next: Optional[Self]
_prev: Optional[Self]

Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions datastax/Nodes/AbstractNodes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .Node import Node
from .DoublyNode import DoublyNode

__all__ = [
Node,
DoublyNode
]
4 changes: 2 additions & 2 deletions datastax/Lists/DoublyNode.py → datastax/Nodes/DoublyNode.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Self, Optional

from datastax.Lists.Node import Node
from datastax.Lists.AbstractLists import DoublyNode as AbstractNode
from datastax.Nodes.Node import Node
from datastax.Nodes.AbstractNodes import DoublyNode as AbstractNode


class DoublyNode(AbstractNode, Node):
Expand Down
2 changes: 1 addition & 1 deletion datastax/Lists/Node.py → datastax/Nodes/Node.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Self, Optional

from datastax.Lists.AbstractLists import Node as AbstractNode
from datastax.Nodes.AbstractNodes import Node as AbstractNode


class Node(AbstractNode):
Expand Down
7 changes: 7 additions & 0 deletions datastax/Nodes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .Node import Node
from .DoublyNode import DoublyNode

__all__ = [
Node,
DoublyNode
]
File renamed without changes.
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import math
from typing import Any, Optional, Union

from datastax.trees.private_trees.binary_tree import (
from datastax.Trees.AbstractTrees.binary_tree import (
BinaryTree, TreeNode,
_node_builder, _mangled
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from itertools import chain
from typing import Any, Optional

from datastax.trees.private_trees.binary_tree import (
from datastax.Trees.AbstractTrees.binary_tree import (
TreeNode,
BinaryTree,
_mangled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import math
from typing import Any, Optional

from datastax.trees.private_trees.binary_tree import (
from datastax.Trees.AbstractTrees.binary_tree import (
BinaryTree, TreeNode, _node_builder, _mangled
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from typing import Optional, Any

from datastax.Lists import Queue
from datastax.trees import (
from datastax.Trees import (
BinaryTree,
AVLTree,
HeapTree,
MinHeapTree
)
from datastax.trees.private_trees import binary_tree
from datastax.trees.private_trees.binary_tree import TreeNode, _mangled
from datastax.Trees.AbstractTrees import binary_tree
from datastax.Trees.AbstractTrees.binary_tree import TreeNode, _mangled


class ThreadedNode(TreeNode):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion datastax/trees/avl_tree.py → datastax/Trees/avl_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any, Optional

from datastax.errors import DuplicateNodeWarning
from datastax.trees.binary_search_tree import BinarySearchTree, TreeNode
from datastax.Trees.binary_search_tree import BinarySearchTree, TreeNode


class AVLNode(TreeNode):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
DeletionFromEmptyTreeWarning,
NodeNotFoundWarning
)
from datastax.trees.private_trees.binary_tree import BinaryTree, TreeNode
from datastax.Trees.AbstractTrees.binary_tree import BinaryTree, TreeNode


class BinarySearchTree(BinaryTree):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
DeletionFromEmptyTreeWarning,
)
from datastax.Lists import Queue
from datastax.trees.private_trees import binary_tree
from datastax.trees.private_trees.binary_tree import TreeNode
from datastax.Trees.AbstractTrees import binary_tree
from datastax.Trees.AbstractTrees.binary_tree import TreeNode


class BinaryTree(binary_tree.BinaryTree):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
UnmatchedBracketPairError, InvalidExpressionError,
UnderFlowError, OverFlowError
)
from datastax.trees.private_trees.binary_tree import TreeNode, BinaryTree
from datastax.Trees.AbstractTrees.binary_tree import TreeNode, BinaryTree


class ExpressionTree(BinaryTree):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import Optional, Any

from datastax.trees.private_trees.binary_tree import BinaryTree, TreeNode
from datastax.Trees.AbstractTrees.binary_tree import BinaryTree, TreeNode


class FibonacciTree(BinaryTree):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Optional, Any

from datastax.errors import DeletionFromEmptyTreeWarning
from datastax.trees.private_trees.binary_tree import BinaryTree, TreeNode
from datastax.Trees.AbstractTrees.binary_tree import BinaryTree, TreeNode


class HeapNode(TreeNode):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from typing import Any, Optional, Union

from datastax.Arrays import PriorityQueue
from datastax.trees.private_trees import huffman_tree
from datastax.trees.private_trees.huffman_tree import HuffmanNode
from datastax.Trees.AbstractTrees import huffman_tree
from datastax.Trees.AbstractTrees.huffman_tree import HuffmanNode


class HuffmanTable(huffman_tree.HuffmanTable):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Min Heap Tree Implementation
from __future__ import annotations

from datastax.trees.heap_tree import HeapTree, HeapNode
from datastax.Trees.heap_tree import HeapTree, HeapNode


class MinHeapTree(HeapTree):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sys import maxsize
from typing import Any, Optional

from datastax.trees.private_trees.segment_tree import SegmentTree, SegmentNode
from datastax.Trees.AbstractTrees.segment_tree import SegmentTree, SegmentNode


class MinSegmentTree(SegmentTree):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from datastax.errors import (
DuplicateNodeWarning
)
from datastax.trees.binary_search_tree import BinarySearchTree
from datastax.trees.private_trees import red_black_tree
from datastax.trees.private_trees.red_black_tree import (
from datastax.Trees.binary_search_tree import BinarySearchTree
from datastax.Trees.AbstractTrees import red_black_tree
from datastax.Trees.AbstractTrees.red_black_tree import (
RedBlackNode,
BLACK, RED
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
DeletionFromEmptyTreeWarning,
NodeNotFoundWarning
)
from datastax.trees.binary_search_tree import BinarySearchTree, TreeNode
from datastax.Trees.binary_search_tree import BinarySearchTree, TreeNode


class SplayNode(TreeNode):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import Any, Optional

from datastax.trees.private_trees.segment_tree import SegmentTree, SegmentNode
from datastax.Trees.AbstractTrees.segment_tree import SegmentTree, SegmentNode


class SumSegmentTree(SegmentTree):
Expand Down
Loading

0 comments on commit 1ef8ce2

Please sign in to comment.