-
Notifications
You must be signed in to change notification settings - Fork 420
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
Window, WindowLeft and WindowRight are not optimal in memory #627
Comments
@atifaziz is there any equivalent to WindowLeftAndRight available ? |
No, never needed it and no one ever asked for it. Do you have a use case? |
I was looking for it to improve it ;) The behavior will be
The usages pretty straightforward. |
For dynamic behaviour? I think if someone needs that, they can achieve it like this: var xs = Enumerable.Range(1, 5);
var windows =
from f in new Func<IEnumerable<int>, int, IEnumerable<IList<int>>>[]
{
MoreEnumerable.Window,
MoreEnumerable.WindowLeft,
MoreEnumerable.WindowRight,
}
select f(xs, 3).Select(w => $"[{w.ToDelimitedString(", ")}]")
.ToDelimitedString(", ");
foreach (var ws in windows)
Console.WriteLine(ws);
// output:
// [1, 2, 3], [2, 3, 4], [3, 4, 5]
// [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5], [5]
// [1], [1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5] |
My proposal is It facilitate the cases where the choice is made at runtime: We have to discuss the name of the optional |
|
Window return a sequence of R/W enable fresh new array and there is no easy way to maintain a Read only version with memory optimisation (keep track of disposed window to free memory in the back end buffer give segmentation management problems). We might need BigO information in the documentation. |
Window
,WindowLeft
andWindowRight
takeO(sourceSize*windowSize)
in memory.If we accept that the method returns
IEnumerable<IReadOnlyList<TSource>>
instead ofIEnumerable<IList<TSource>>
, we can go down toO(consumedElement) < O(sourceSize)
.The text was updated successfully, but these errors were encountered: