MemoizingEnumerable.Count returns only the buffered prefix after partial enumeration

オープン 初心者向け
#10,175 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
backend

調査の方向性

Common/Util/MemoizingEnumerable.csから始め、Count、Empty、部分列挙がバッファをどのように使い、ソースの終端をどのように追跡するかをたどってください。Countをすぐに呼び出す場合、Emptyの後に呼び出す場合、部分列挙の後に呼び出す場合を含むテストを追加し、Take(1).Single()のケースも含めてください。各アクセス順序で、バッファされた要素を失ったりソースを再評価したりせずに、完全な件数が返されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

priority:p2

Problem

MemoizingEnumerable<T>.Count returns the buffered prefix's length after partial enumeration, rather than the total number of elements promised by its documentation.

Reproduction

var items = new MemoizingEnumerable<int>(Enumerable.Range(1, 100));
Console.WriteLine(items.Empty);            // False
Console.WriteLine(items.Count);            // 1 -- expected 100
Console.WriteLine(items.ToArray().Length); // 100
Console.WriteLine(items.Count);            // 100

Likewise, items.Take(1).Single() before Count produces 1 instead of 100. I ran both cases against the current implementation; both reproduced. The same implementation is present on master.

Cause and expected result

In Common/Util/MemoizingEnumerable.cs, Count completes enumeration only when _buffer == null. Empty and partial enumeration allocate and populate that buffer without exhausting the source, so the count silently depends on how the enumerable has previously been accessed.

A fix must make Count return the full source count whether called immediately, after Empty, or after partial enumeration, without losing the buffered elements or repeating source evaluation. Add coverage for these access orders. A suggested approach is to use source-exhaustion state, rather than buffer allocation, to determine whether enumeration remains necessary.

This is limited to callers accessing the count before completing enumeration; fully enumerating first is a workaround.

主要言語
C#
スター
22.5k
フォーク
5.4k
平均マージ
13時間 11分
マージ済み PR(30日)
104

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

QuantConnect/Lean のほかの issue

QuantConnect/Lean の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。