Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added '__slots__' in classes #29 #30

Merged
merged 2 commits into from
Oct 24, 2019

Conversation

udhayacommits
Copy link
Contributor

@udhayacommits udhayacommits commented Oct 23, 2019

References to other Issues or PRs or Relevant literature

Fixes #29

Brief description of what is fixed or changed

Added slots to all the classes
http://book.pythontips.com/en/latest/__slots__magic.html

Other comments

@codecov
Copy link

codecov bot commented Oct 23, 2019

Codecov Report

Merging #30 into master will increase coverage by 0.004%.
The diff coverage is 100%.

@@              Coverage Diff              @@
##            master       #30       +/-   ##
=============================================
+ Coverage   98.203%   98.207%   +0.004%     
=============================================
  Files           15        15               
  Lines          835       837        +2     
=============================================
+ Hits           820       822        +2     
  Misses          15        15
Impacted Files Coverage Δ
pydatastructs/trees/binary_trees.py 97.553% <ø> (ø) ⬆️
pydatastructs/linear_data_structures/arrays.py 100% <100%> (ø) ⬆️
...datastructs/miscellaneous_data_structures/stack.py 92.452% <100%> (+0.145%) ⬆️

Impacted file tree graph

@czgdp1807
Copy link
Member

Thanks for the PR. LGTM. Will merge it after some review.

@czgdp1807 czgdp1807 added the enhancement New feature or request label Oct 23, 2019
@@ -84,6 +84,8 @@ def peek(self):

class ArrayStack(Stack):

__slots__ = ['maxsize', 'top', 'items']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add dtype to the list as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't make this change.
I will give you a diff by tonight, which you can apply on top of your changes and push them here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I will wait for your changes.

@czgdp1807
Copy link
Member

In future PRs, make sure that you do not use master for making changes to the code. It can become quite complex to manage if your PR is closed or not accepted. For now this is fine and you can keep working on it. Thanks.

@czgdp1807
Copy link
Member

czgdp1807 commented Oct 23, 2019

@udhayacommits Please apply the following diff on your master,

diff --git a/pydatastructs/linear_data_structures/arrays.py b/pydatastructs/linear_data_structures/arrays.py
index bf96ee5..cc92c93 100644
--- a/pydatastructs/linear_data_structures/arrays.py
+++ b/pydatastructs/linear_data_structures/arrays.py
@@ -63,9 +63,9 @@ class OneDimensionalArray(Array):
 
     .. [1] https://en.wikipedia.org/wiki/Array_data_structure#One-dimensional_arrays
     '''
-    
-    __slots__ = ['_size', '_data']
-    
+
+    __slots__ = ['_size', '_data', '_dtype']
+
     def __new__(cls, dtype=NoneType, *args, **kwargs):
         if dtype == NoneType or len(args) not in (1, 2):
             raise ValueError("1D array cannot be created due to incorrect"
diff --git a/pydatastructs/miscellaneous_data_structures/stack.py b/pydatastructs/miscellaneous_data_structures/stack.py
index e7f75a8..9b82ca4 100644
--- a/pydatastructs/miscellaneous_data_structures/stack.py
+++ b/pydatastructs/miscellaneous_data_structures/stack.py
@@ -84,8 +84,8 @@ class Stack(object):
 
 class ArrayStack(Stack):
 
-    __slots__ = ['maxsize', 'top', 'items']
-    
+    __slots__ = ['maxsize', 'top', 'items', 'dtype']
+
     def __new__(cls, maxsize=None, top=0, items=None, dtype=int):
         if not _check_type(maxsize, int):
             raise ValueError("maxsize is missing.")
diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py
index a1d2aec..e8fb820 100644
--- a/pydatastructs/trees/binary_trees.py
+++ b/pydatastructs/trees/binary_trees.py
@@ -182,9 +182,7 @@ class BinarySearchTree(BinaryTree):
 
     pydatastructs.trees.binary_tree.BinaryTree
     """
-    
-    __slots__ = ['root_idx', 'comparator', 'tree', 'size']
-    
+
     def insert(self, key, data):
         walk = self.root_idx
         if self.tree[walk].key == None:
@@ -305,9 +303,6 @@ class AVLTree(BinarySearchTree):
     balance_factor = lambda self, node: self.right_height(node) - \
                                         self.left_height(node)
 
-    
-    __slots__ = ['root_idx', 'comparator', 'tree', 'size']
-    
     def _right_rotate(self, j, k):
         y = self.tree[k].right
         if y != None:

Use pds_diff.txt if the above doesn't work.

@udhayacommits
Copy link
Contributor Author

@czgdp1807 Please let me know how to apply the diff. I am only getting errors when trying using the text file.

@czgdp1807
Copy link
Member

Are you using git apply? Can you please share the error message?

@udhayacommits
Copy link
Contributor Author

@czgdp1807 , I was using TortoiseGit that did not work. But the command worked. thanks.

@czgdp1807 czgdp1807 merged commit fbc4a25 into codezonediitj:master Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add __slots__ in classes
2 participants