Skip to content

Commit

Permalink
Update EmptyWeightedSelector.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
mackysoft committed Jan 29, 2021
1 parent fb8d48f commit 98091d3
Showing 1 changed file with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;

namespace MackySoft.Choice {

internal sealed class EmptyWeightedSelector<T> : IWeightedSelector<T> {

public static readonly EmptyWeightedSelector<T> Instance = new EmptyWeightedSelector<T>();
Expand All @@ -13,9 +14,9 @@ internal sealed class EmptyWeightedSelector<T> : IWeightedSelector<T> {

public int Count => 0;

ICollection<T> IDictionary<T,float>.Keys => throw new System.NotImplementedException();
ICollection<T> IDictionary<T,float>.Keys => EmptyCollection<T>.Instance;

ICollection<float> IDictionary<T,float>.Values => throw new System.NotImplementedException();
ICollection<float> IDictionary<T,float>.Values => EmptyCollection<float>.Instance;

bool ICollection<KeyValuePair<T,float>>.IsReadOnly => false;

Expand Down Expand Up @@ -70,5 +71,45 @@ public void CopyTo (KeyValuePair<T,float>[] array,int arrayIndex) {
public bool Remove (KeyValuePair<T,float> item) {
return false;
}


}

internal sealed class EmptyCollection<T> : ICollection<T> {

public static readonly EmptyCollection<T> Instance = new EmptyCollection<T>();

public int Count => 0;

public bool IsReadOnly => false;

public void Add (T item) {

}

public bool Remove (T item) {
return false;
}

public void Clear () {

}

public bool Contains (T item) {
return false;
}

public void CopyTo (T[] array,int arrayIndex) {

}

public IEnumerator<T> GetEnumerator () {
return Enumerable.Empty<T>().GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator () {
return GetEnumerator();
}
}

}

0 comments on commit 98091d3

Please sign in to comment.