Skip to content

Commit

Permalink
Use comparison by reference for bool type objects (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saptashrungi authored and czgdp1807 committed Dec 26, 2019
1 parent 27d3ed8 commit 15ab8ba
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 100 deletions.
16 changes: 8 additions & 8 deletions pydatastructs/linear_data_structures/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class OneDimensionalArray(Array):
__slots__ = ['_size', '_data', '_dtype']

def __new__(cls, dtype=NoneType, *args, **kwargs):
if dtype == NoneType or len(args) not in (1, 2):
if dtype is NoneType or len(args) not in (1, 2):
raise ValueError("1D array cannot be created due to incorrect"
" information.")
obj = object.__new__(cls)
Expand Down Expand Up @@ -206,7 +206,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
def __new__(cls, dtype=NoneType, *args, **kwargs):
obj = super().__new__(cls, dtype, *args, **kwargs)
obj._load_factor = float(kwargs.get('load_factor', 0.25))
obj._num = 0 if obj._size == 0 or obj[0] == None else obj._size
obj._num = 0 if obj._size == 0 or obj[0] is None else obj._size
obj._last_pos_filled = obj._num - 1
return obj

Expand All @@ -219,7 +219,7 @@ def _modify(self):
arr_new = ODA(self._dtype, 2*self._num + 1)
j = 0
for i in range(self._last_pos_filled + 1):
if self[i] != None:
if self[i] is not None:
arr_new[j] = self[i]
j += 1
self._last_pos_filled = j - 1
Expand All @@ -244,7 +244,7 @@ def append(self, el):

def delete(self, idx):
if idx <= self._last_pos_filled and idx >= 0 and \
self[idx] != None:
self[idx] is not None:
self[idx] = None
self._num -= 1
if self._last_pos_filled == idx:
Expand All @@ -270,16 +270,16 @@ def _modify(self):
arr_new = OneDimensionalArray(self._dtype, 2*self._num + 1)
j = 0
for i in range(self._last_pos_filled + 1):
if self[i] != None:
if self[i] is not None:
arr_new[j] = self[i]
new_indices[self[i].key] = j
j += 1
for i in range(j):
if arr_new[i].left != None:
if arr_new[i].left is not None:
arr_new[i].left = new_indices[self[arr_new[i].left].key]
if arr_new[i].right != None:
if arr_new[i].right is not None:
arr_new[i].right = new_indices[self[arr_new[i].right].key]
if arr_new[i].parent != None:
if arr_new[i].parent is not None:
arr_new[i].parent = new_indices[self[arr_new[i].parent].key]
self._last_pos_filled = j - 1
self._data = arr_new._data
Expand Down
2 changes: 1 addition & 1 deletion pydatastructs/miscellaneous_data_structures/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __new__(cls, maxsize=None, top=0, items=None, dtype=int):
raise ValueError("maxsize is missing.")
if not _check_type(top, int):
raise TypeError("top is not of type int.")
if items == None:
if items is None:
items = OneDimensionalArray(dtype, maxsize)
if not _check_type(items, OneDimensionalArray):
raise ValueError("items is not of type, OneDimensionalArray")
Expand Down
Loading

0 comments on commit 15ab8ba

Please sign in to comment.