-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4a924b
commit e55320f
Showing
25 changed files
with
153 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
datastax/Arrays/priority_queue.py → datastax/Arrays/PriorityQueue.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,35 @@ | ||
# Stack Implementation using Lists (Pseudo Arrays) | ||
import math | ||
from typing import Any | ||
from typing import Any, Optional | ||
|
||
from datastax.errors import UnderFlowError, OverFlowError | ||
from datastax.Arrays.AbstractArrays import Stack as AbstractStack | ||
|
||
|
||
class Stack(AbstractStack): | ||
def __init__(self, *, capacity: int = None): | ||
def __init__(self, *, capacity: Optional[int] = None): | ||
self._array = [] | ||
self.set_capacity(capacity) | ||
|
||
@property | ||
def array(self) -> list[Any]: | ||
return self._array | ||
|
||
def is_full(self) -> bool: | ||
return len(self._array) == self.capacity | ||
return len(self.array) == self.capacity | ||
|
||
def is_empty(self) -> bool: | ||
return not len(self._array) | ||
return not self.array | ||
|
||
def push(self, item: Any) -> int: | ||
if self.is_full(): # Overflow Condition | ||
raise OverFlowError(self) | ||
|
||
self._array.append(item) | ||
self.array.append(item) | ||
return 0 | ||
|
||
def pop(self) -> Any: | ||
if self.is_empty(): # Underflow Condition handled | ||
raise UnderFlowError(self) | ||
return self._array.pop() | ||
return self.array.pop() | ||
|
||
def __len__(self): | ||
return len(self._array) | ||
return len(self.array) | ||
|
||
def peek(self) -> Any: | ||
return 'STACK EMPTY' if self.is_empty() else self._array[-1] | ||
return 'STACK EMPTY' if self.is_empty() else self.array[-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.