def append(self, ele)
if self.n == self.capacity:
self._resize(2*self.capacity)
self.A[self.n] = ele
self.n += 1
1. The parameter object
ele
will be stored in the array
A
at offset
n
. If the value of
n
is greater than the number of elements of
A-1
then an exception will be thrown.
2. The value of
n
is increased by
1
, in order to point to the next free element in the array
A
.
B = self.make_array(new_cap)
for k in range(self.n):
B[k] = self.A[k]
self.A = B
self.capacity = new_cap
def make_array(self,new_cap)
return (new_cap * ctypes.py_object)()
1. Set the reference
A
to point to the newly created array
B
. So all references will access the data in the new array.
2. Set the variable
capacity
to the value of the parameter
new_cap
. That is just replacing one value in a variable with another (similar to i = 5).
3. The method
make_array
is creating a new raw array that can hold up to
new_cap
ctypes.py_object
objects. The array reference is then passed back to the caller of the method, as referred to in lines 1 and 2.
See also
The Python Tutorial — Python 3.7.2 documentation[
^].