| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Defined the abstract methods in `Queue` and implemented them in `ProrityQueue` and `FIFOQueue`.
|
I don't understand what the __getitems__ method is doing? I have opened an issue (#829) regarding the same. |
Sorry, something went wrong.
|
@MrDupin @norvig |
Sorry, something went wrong.
|
I have previously tried to make changes to the Queues, but each time I realized that it's not a big issue. Students don't come here for this, so we should just have something simple that works. I am not sure what to do with this, sorry. It can go any way. For now focus on the Queues and if Mr. Norvig likes the changes, work on the Stack. |
Sorry, something went wrong.
| @@ -662,41 +663,39 @@ def __missing__(self, key): | |||
|
|
|||
|
|
|||
| class hashabledict(dict): | |||
There was a problem hiding this comment.
I understand the motivation for a hashable dict. It is too bad Python doesn't have frozendict like frozenset.
But the implementation here is O(n) to compare or hash. Given that, a simpler representation is:
class hdict(dict):
def __hash__(self): return 1
Sorry, something went wrong.
| @@ -724,73 +739,94 @@ def Stack(): | |||
|
|
|||
|
|
|||
| class FIFOQueue(Queue): | |||
There was a problem hiding this comment.
The code here is fine, but I think we can just use collections.deque.
Sorry, something went wrong.
There was a problem hiding this comment.
But then we have to change every uses of FIFOQueue and replace its pop with popleft. I thought the idea behind these classes here was to be able to use PriorityQueue and FIFOQueue (and maybe Stack) with a the same code and just change in the constructor.
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, @goswami-rahul you are correct that the motivation of a single interface was to make the various queues the same, so that they could be interchangeable, and we could highlight the similarities. This was a priority in the 1st and 2nd edition of the book (and the code goes all the way back to then). But in the 3rd (and soon 4th) edition, we accept that each search function is somewhat different, and so it is ok, and maybe even preferably, to have popleft instead of pop.
Sorry, something went wrong.
| return item in self.q | ||
|
|
||
|
|
||
| class PriorityQueue(Queue): |
There was a problem hiding this comment.
Probably easier to use heapq.
Sorry, something went wrong.
|
So should I remove all these classes and refactor all their instances with collections.deque.? |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
The __init__ method of the PriorityQueue is changed.
Old:
New:
This change is because it can be seen that the argument passed before i.e. min is a built-in function,
There is no specific use of min function in any method. It is just used as a flag to indicate that make a min PriorityQueue.
This functionality is achieved better when the order argument is str rather than a function.
There are 2 uses of this class, both of which are also updated in this PR.
Also now the PriorityQueue attribute self.order is not required.
Any suggestions or feedbacks are appreciated.