-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
heap.toIterator #253
base: master
Are you sure you want to change the base?
heap.toIterator #253
Conversation
Codecov Report
@@ Coverage Diff @@
## master #253 +/- ##
==========================================
+ Coverage 91.23% 91.24% +<.01%
==========================================
Files 24 24
Lines 1621 1622 +1
Branches 227 217 -10
==========================================
+ Hits 1479 1480 +1
Misses 142 142
Continue to review full report at Codecov.
|
@@ -129,6 +129,19 @@ sealed abstract class Heap[A] { | |||
def heapify(a: List[A])(implicit order: Order[A]): Heap[A] = | |||
Heap.heapify(a) | |||
|
|||
def toIterator(implicit order: Order[A]): Iterator[A] = { | |||
@scala.annotation.tailrec | |||
def build(heap: Heap[A], acc: Stream[A]): Stream[A] = heap match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is using a Stream better than just building the List below? Since it is tailrec you are building the whole Stream no? If we do that, isn’t a List cheaper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in list you have to reverse it at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this particular case the following does not apply, but in the other implementations, the stream based removed the need for mutations, and adds stateless build of the iterator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are making a performance argument, can we show a win with benchmarks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh man, you are killing me... I haven't written one of those in a while. Let me see
No description provided.