Skip to content

Commit

Permalink
Fixed missing logic in LazyList.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Nov 28, 2023
1 parent 401a06b commit d6209b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
3 changes: 1 addition & 2 deletions FinModelUtility/Fin/Fin/src/data/lazy/LazyArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
23 changes: 22 additions & 1 deletion FinModelUtility/Fin/Fin/src/data/lazy/LazyList.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -59,5 +70,15 @@ public IEnumerable<int> Keys

public IEnumerable<T> 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]);
}
}
}
}
}

0 comments on commit d6209b8

Please sign in to comment.