Skip to content

Commit

Permalink
refactor: refactored datastax/Arrays for Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
warmachine028 committed Aug 3, 2023
1 parent 48278ad commit 5a525aa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions datastax/Arrays/PriorityQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any, Callable, Optional

from datastax.Arrays.Queue import Queue
from datastax.errors import OverFlowError, UnderFlowError
from datastax.Utils.Exceptions import OverflowException, UnderflowException


class PriorityQueue(Queue):
Expand Down Expand Up @@ -38,7 +38,7 @@ def heapify(self, index: int, length: int) -> None:

def dequeue(self) -> Any:
if self.is_empty():
raise UnderFlowError(self)
raise UnderflowException(self)

deleted_item = self._array[self._front]
self._array[self._front] = self._array[-1]
Expand All @@ -49,7 +49,7 @@ def dequeue(self) -> Any:

def enqueue(self, item: Any) -> int:
if self.is_full():
raise OverFlowError(self)
raise OverflowException(self)

self._array.append(item)
self._rear += 1
Expand Down
6 changes: 3 additions & 3 deletions datastax/Arrays/Queue.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Queue Implementation using Lists (Pseudo Arrays)
from typing import Any, Optional

from datastax.errors import OverFlowError, UnderFlowError
from datastax.Utils.Exceptions import OverflowException, UnderflowException
from datastax.Arrays.AbstractArrays import Queue as AbstractQueue


Expand All @@ -18,15 +18,15 @@ def is_empty(self) -> bool:

def enqueue(self, item: Any) -> int:
if self.is_full():
raise OverFlowError(self)
raise OverflowException(self)

self._array.append(item)
self._rear += 1
return 0

def dequeue(self) -> Any:
if self.is_empty() or self.front >= self.rear:
raise UnderFlowError(self)
raise UnderflowException(self)
deleted_item = self._array[self.front]
self._front += 1
return deleted_item
Expand Down
6 changes: 3 additions & 3 deletions datastax/Arrays/Stack.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Stack Implementation using Lists (Pseudo Arrays)
from typing import Any, Optional

from datastax.errors import UnderFlowError, OverFlowError
from datastax.Utils.Exceptions import UnderflowException, OverflowException
from datastax.Arrays.AbstractArrays import Stack as AbstractStack


Expand All @@ -18,14 +18,14 @@ def is_empty(self) -> bool:

def push(self, item: Any) -> int:
if self.is_full(): # Overflow Condition
raise OverFlowError(self)
raise OverflowException(self)

self.array.append(item)
return 0

def pop(self) -> Any:
if self.is_empty(): # Underflow Condition handled
raise UnderFlowError(self)
raise UnderflowException(self)
return self.array.pop()

def __len__(self):
Expand Down

0 comments on commit 5a525aa

Please sign in to comment.