<div class="gmail_extra"><div class="gmail_quote">On Fri, Jul 6, 2012 at 3:51 PM, Jakob Stoklund Olesen <span dir="ltr"><<a href="mailto:stoklund@2pi.dk" target="_blank" class="cremed">stoklund@2pi.dk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div class="im"><div>On Jul 6, 2012, at 3:40 PM, Chandler Carruth <<a href="mailto:chandlerc@gmail.com" target="_blank" class="cremed">chandlerc@gmail.com</a>> wrote:</div>
<br><blockquote type="cite"><div style="font-family:Optima;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
I still think we should likely make join() use this code because we should make it handle that input pattern efficiently, but fall back on something that isn't super-linear when it hits edge cases.</div></blockquote><div>
<br></div></div><div>How about sticking the merge state in a (local) class:</div><div><br></div><div>class LIMerger {</div><div> NewRanges, …</div><div>public:</div><div> LIMerger(LiveInterval &LHS, SlotIndex StartPos);</div>
<div> void add(SlotIndex From, SlotIndex To, VNInfo *VNI);</div><div> void finish();</div><div>};</div><div><br></div><div>That interface could readily be used by all three clients, and you don't clutter up the code with value mapping stuff.</div>
</div></div></blockquote><div><br></div><div>I'd love an interface that doesn't involve the value mapping stuff...</div><div><br></div><div>The annoying thing is that exposing an interface like this makes the looping logic extremely hard to read (for me at least). In the end, I had an easier time with a few special cases in the inside of the loop with comments.</div>
<div><br></div><div>That said, it could work. However:</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>The add method can require disjoint, increasing segments:<br>
</div></div></blockquote><div><br></div><div>One of the useful things to consolidate *is* the merging logic though.</div><div><br></div><div>The other thing that's tricky is that the merging logic can do very surprising things because it has to remove elements from the LHS that are subsumed by the merged entry. That was actually what led to the original bad behavior.</div>
<div><br></div><div>I'm still looking at how best to write the code to make the cases where size doesn't change, or only ever decreases, fast.</div></div></div>