3 ms·
Programming nit: The posted code should use collections.deque() rather than Queue.Queue(). The former is a high-speed C-coded datatype that is ideal for a sea
by raymondh 12y ago
Programming nit: The posted code should use collections.deque() rather than Queue.Queue(). The former is a high-speed C-coded datatype that is ideal for a search queue. The latter is a pure Python wrapper that adds thread synchronization around an underlying collections.deque() object. The wrapper overhead is only worth it if you're actually using multiple threads that share the same queue.
- deleted 12y ago[deleted]
- raymondh 12y agoIn the author's separate page of implementation notes, a Queue class is created that doesn't have threading overhead. That would be great, but it uses list.pop(0) which is an O(n) operation. For O(1) performance, it should use collections.deque.popleft() instead. Otherwise, the article is first-rate :-)
- amitp 12y agoAh, thanks! I've been focusing on simplicity rather than performance, but deque is just as simple here, so I should use it. :-)