Replies: 2 comments 1 reply
-
By the way, I think it would be better to separate different classes into different files, especially when these classes are large. When trying to read the file |
Beta Was this translation helpful? Give feedback.
-
@ttzytt I totally agree with your point of view. Overloading the operators for |
Beta Was this translation helpful? Give feedback.
-
Found some places to improve when using the package to implement the animation of a simple binary search algorithm:
For every comparison between
MArrayPointer
, you have to callfetch_index()
to get the position where the array is pointing. I think it will be better to overload comparators in MArrayPointer so that the implementation will be easier.The same works for other operators like add and subtract: the addition or subtraction between
MArrayPointer
an integer or anotherMArrayPointer
should give the addition and subtraction between the integer and the index that the pointer is pointing to in aMArray
. That way, the operation of pointers will be much easier, and code like the following will be simplified:r.shift_to_elem(mid.fetch_index() - 1, play_anim=False
mid.shift_to_elem((l.fetch_index() + r.fetch_index()) // 2
Another possible improvement from overloading operators is to overload
__getitem__
and__setitem__
forMArray
. Using these two methods, we could directly access theMArrayElement
inside theMArray
through the bracket operator, thus making animations onMArrayElement
in an easier way.I'm not sure about your ideas for these modifications, but if you think they are helpful, I can make a PR on that.
Beta Was this translation helpful? Give feedback.
All reactions