<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>We could do it the easy way and just allocate 2 arrays of original size and return them.</div><div><br></div><div>We can also do the optimized way which isn't so user-friendly: make a new structure that contains an array and an index internally. The array will be the original array just "sorted" based on the predicate function. And the index is for where the second half starts. The public API would show 2 arrays <i>somehow</i> and gives the illusion that there are 2 arrays.</div><div><br></div><div><br></div><div>- Arman</div><div><br>On Jan 15, 2016, at 5:37 PM, Dave via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><blockquote type="cite"><span>On Jan 15, 2016, at 11:49, Arman Shan &lt;<a href="mailto:armanshan12@gmail.com">armanshan12@gmail.com</a>&gt; wrote:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>I definitely agree that this function should not replace the current filter function. We can give it a new name like "partition" or something.</span><br></blockquote><span>+1 on “partition”. That makes the semantics much clearer, IMHO.</span><br><span></span><br><blockquote type="cite"><span>Regarding the memory constraint: since both filter and partition methods will be provided, the developer may choose whether they prefer performance over memory fragmentation or not.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Or maybe at the end of the partition method, if one of the result arrays is significantly smaller than the other, we copy the data into a smaller array and then return.</span><br></blockquote><span></span><br><span>Oh, yeah… I was thinking the excess storage would be deallocated at the end anyway. Honestly, this whole bit about super-optimizing the memory allocation assumes that the actual element storage is managed like C arrays (with a pointer to [0], and using pointer math to get the other elements) behind the scenes, and I don’t actually know that it’s done that way.</span><br><span></span><br><span>- Dave Sweeris</span><br><span></span><br><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>