From d6209b8c3a432e3f7b433aa456a7f6f6fa07297b Mon Sep 17 00:00:00 2001 From: MeltyPlayer Date: Mon, 27 Nov 2023 23:39:57 -0600 Subject: [PATCH] Fixed missing logic in LazyList. --- .../Fin/Fin/src/data/lazy/LazyArray.cs | 3 +-- .../Fin/Fin/src/data/lazy/LazyList.cs | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/FinModelUtility/Fin/Fin/src/data/lazy/LazyArray.cs b/FinModelUtility/Fin/Fin/src/data/lazy/LazyArray.cs index 147914cf8..2282fb42b 100644 --- a/FinModelUtility/Fin/Fin/src/data/lazy/LazyArray.cs +++ b/FinModelUtility/Fin/Fin/src/data/lazy/LazyArray.cs @@ -49,10 +49,9 @@ public bool TryGetValue(int key, out T value) { return false; } - public T this[int key] { get { - if (this.populated_[key]) { + if (this.ContainsKey(key)) { return this.impl_[key]; } diff --git a/FinModelUtility/Fin/Fin/src/data/lazy/LazyList.cs b/FinModelUtility/Fin/Fin/src/data/lazy/LazyList.cs index e221eb977..cc21323eb 100644 --- a/FinModelUtility/Fin/Fin/src/data/lazy/LazyList.cs +++ b/FinModelUtility/Fin/Fin/src/data/lazy/LazyList.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; @@ -26,8 +27,18 @@ public void Clear() { this.populated_.Clear(); } - public bool ContainsKey(int key) => this.populated_[key]; + public bool ContainsKey(int key) + => this.populated_.Count > key && this.populated_[key]; + public bool TryGetValue(int key, out T value) { + if (this.ContainsKey(key)) { + value = this.impl_[key]; + return true; + } + + value = default; + return false; + } public T this[int key] { get { @@ -59,5 +70,15 @@ public IEnumerable Keys public IEnumerable Values => this.impl_.Where((value, i) => ContainsKey(i)); + + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + + public IEnumerator<(int Key, T Value)> GetEnumerator() { + for (var i = 0; i < this.populated_.Count; ++i) { + if (this.populated_[i]) { + yield return (i, this.impl_[i]); + } + } + } } } \ No newline at end of file