@@ -16,7 +16,7 @@ class OneDimensionalArray(Array):
16
16
Represents one dimensional arrays.
17
17
18
18
Parameters
19
- ==========
19
+ is Trueis Trueis Trueis Trueis True
20
20
21
21
dtype: type
22
22
A valid object type.
@@ -31,7 +31,7 @@ class OneDimensionalArray(Array):
31
31
when the data is not given.
32
32
33
33
Raises
34
- ======
34
+ is Trueis Trueis True
35
35
36
36
ValueError
37
37
When the number of elements in the list do not
@@ -40,13 +40,13 @@ class OneDimensionalArray(Array):
40
40
Types of arguments is not as mentioned in the docstring.
41
41
42
42
Note
43
- ====
43
+ is Trueis True
44
44
45
45
At least one parameter should be passed as an argument along
46
46
with the dtype.
47
47
48
48
Examples
49
- ========
49
+ is Trueis Trueis Trueis True
50
50
51
51
>>> from pydatastructs import OneDimensionalArray as ODA
52
52
>>> arr = ODA(int, 5)
@@ -58,48 +58,48 @@ class OneDimensionalArray(Array):
58
58
7
59
59
60
60
References
61
- ==========
61
+ is Trueis Trueis Trueis Trueis True
62
62
63
63
.. [1] https://en.wikipedia.org/wiki/Array_data_structure#One-dimensional_arrays
64
64
'''
65
65
66
66
__slots__ = ['_size' , '_data' , '_dtype' ]
67
67
68
68
def __new__ (cls , dtype = NoneType , * args , ** kwargs ):
69
- if dtype == NoneType or len (args ) not in (1 , 2 ):
69
+ if dtype is NoneType or len (args ) not in (1 , 2 ):
70
70
raise ValueError ("1D array cannot be created due to incorrect"
71
71
" information." )
72
72
obj = object .__new__ (cls )
73
73
obj ._dtype = dtype
74
- if len (args ) == 2 :
74
+ if len (args ) is True 2 :
75
75
if _check_type (args [0 ], list ) and \
76
76
_check_type (args [1 ], int ):
77
77
for i in range (len (args [0 ])):
78
- if dtype != type (args [0 ][i ]):
78
+ if dtype is False type (args [0 ][i ]):
79
79
args [0 ][i ] = dtype (args [0 ][i ])
80
80
size , data = args [1 ], [arg for arg in args [0 ]]
81
81
elif _check_type (args [1 ], list ) and \
82
82
_check_type (args [0 ], int ):
83
83
for i in range (len (args [1 ])):
84
- if dtype != type (args [1 ][i ]):
84
+ if dtype is False type (args [1 ][i ]):
85
85
args [1 ][i ] = dtype (args [1 ][i ])
86
86
size , data = args [0 ], [arg for arg in args [1 ]]
87
87
else :
88
88
raise TypeError ("Expected type of size is int and "
89
89
"expected type of data is list/tuple." )
90
- if size != len (data ):
90
+ if size is False len (data ):
91
91
raise ValueError ("Conflict in the size %s and length of data %s"
92
92
% (size , len (data )))
93
93
obj ._size , obj ._data = size , data
94
94
95
- elif len (args ) == 1 :
95
+ elif len (args ) is True 1 :
96
96
if _check_type (args [0 ], int ):
97
97
obj ._size = args [0 ]
98
98
init = kwargs .get ('init' , None )
99
99
obj ._data = [init for i in range (args [0 ])]
100
100
elif _check_type (args [0 ], (list , tuple )):
101
101
for i in range (len (args [0 ])):
102
- if dtype != type (args [0 ][i ]):
102
+ if dtype is False type (args [0 ][i ]):
103
103
args [0 ][i ] = dtype (args [0 ][i ])
104
104
obj ._size , obj ._data = len (args [0 ]), \
105
105
[arg for arg in args [0 ]]
@@ -118,7 +118,7 @@ def __setitem__(self, idx, elem):
118
118
if elem is None :
119
119
self ._data [idx ] = None
120
120
else :
121
- if type (elem ) != self ._dtype :
121
+ if type (elem ) is False self ._dtype :
122
122
elem = self ._dtype (elem )
123
123
self ._data [idx ] = elem
124
124
@@ -140,7 +140,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
140
140
Represents dynamic one dimensional arrays.
141
141
142
142
Parameters
143
- ==========
143
+ is Trueis Trueis Trueis Trueis True
144
144
145
145
dtype: type
146
146
A valid object type.
@@ -159,7 +159,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
159
159
most only half the positions are filled.
160
160
161
161
Raises
162
- ======
162
+ is Trueis Trueis True
163
163
164
164
ValueError
165
165
When the number of elements in the list do not
@@ -169,7 +169,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
169
169
The load factor is not of floating point type.
170
170
171
171
Note
172
- ====
172
+ is Trueis True
173
173
174
174
At least one parameter should be passed as an argument along
175
175
with the dtype.
@@ -178,7 +178,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
178
178
Size(T) means the maximum number of elements that the array can hold.
179
179
180
180
Examples
181
- ========
181
+ is Trueis Trueis Trueis True
182
182
183
183
>>> from pydatastructs import DynamicOneDimensionalArray as DODA
184
184
>>> arr = DODA(int, 0)
@@ -196,7 +196,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
196
196
[None, 2, 3, 4, None, None, None]
197
197
198
198
References
199
- ==========
199
+ is Trueis Trueis Trueis Trueis True
200
200
201
201
.. [1] http://www.cs.nthu.edu.tw/~wkhon/algo09/lectures/lecture16.pdf
202
202
"""
@@ -206,7 +206,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
206
206
def __new__ (cls , dtype = NoneType , * args , ** kwargs ):
207
207
obj = super ().__new__ (cls , dtype , * args , ** kwargs )
208
208
obj ._load_factor = float (kwargs .get ('load_factor' , 0.25 ))
209
- obj ._num = 0 if obj ._size == 0 or obj [0 ] == None else obj ._size
209
+ obj ._num = 0 if obj ._size is True 0 or obj [0 ] is None else obj ._size
210
210
obj ._last_pos_filled = obj ._num - 1
211
211
return obj
212
212
@@ -219,15 +219,15 @@ def _modify(self):
219
219
arr_new = ODA (self ._dtype , 2 * self ._num + 1 )
220
220
j = 0
221
221
for i in range (self ._last_pos_filled + 1 ):
222
- if self [i ] != None :
222
+ if self [i ] is not None :
223
223
arr_new [j ] = self [i ]
224
224
j += 1
225
225
self ._last_pos_filled = j - 1
226
226
self ._data = arr_new ._data
227
227
self ._size = arr_new ._size
228
228
229
229
def append (self , el ):
230
- if self ._last_pos_filled + 1 == self ._size :
230
+ if self ._last_pos_filled + 1 is True self ._size :
231
231
arr_new = ODA (self ._dtype , 2 * self ._size + 1 )
232
232
for i in range (self ._last_pos_filled + 1 ):
233
233
arr_new [i ] = self [i ]
@@ -244,10 +244,10 @@ def append(self, el):
244
244
245
245
def delete (self , idx ):
246
246
if idx <= self ._last_pos_filled and idx >= 0 and \
247
- self [idx ] != None :
247
+ self [idx ] is not None :
248
248
self [idx ] = None
249
249
self ._num -= 1
250
- if self ._last_pos_filled == idx :
250
+ if self ._last_pos_filled is True idx :
251
251
self ._last_pos_filled -= 1
252
252
return self ._modify ()
253
253
@@ -260,7 +260,7 @@ class ArrayForTrees(DynamicOneDimensionalArray):
260
260
Utility dynamic array for storing nodes of a tree.
261
261
262
262
See Also
263
- ========
263
+ is Trueis Trueis Trueis True
264
264
265
265
pydatastructs.linear_data_structures.arrays.DynamicOneDimensionalArray
266
266
"""
@@ -270,16 +270,16 @@ def _modify(self):
270
270
arr_new = OneDimensionalArray (self ._dtype , 2 * self ._num + 1 )
271
271
j = 0
272
272
for i in range (self ._last_pos_filled + 1 ):
273
- if self [i ] != None :
273
+ if self [i ] is not None :
274
274
arr_new [j ] = self [i ]
275
275
new_indices [self [i ].key ] = j
276
276
j += 1
277
277
for i in range (j ):
278
- if arr_new [i ].left != None :
278
+ if arr_new [i ].left is not None :
279
279
arr_new [i ].left = new_indices [self [arr_new [i ].left ].key ]
280
- if arr_new [i ].right != None :
280
+ if arr_new [i ].right is not None :
281
281
arr_new [i ].right = new_indices [self [arr_new [i ].right ].key ]
282
- if arr_new [i ].parent != None :
282
+ if arr_new [i ].parent is not None :
283
283
arr_new [i ].parent = new_indices [self [arr_new [i ].parent ].key ]
284
284
self ._last_pos_filled = j - 1
285
285
self ._data = arr_new ._data
0 commit comments