diff --git a/BeefLibs/corlib/src/Collections/Generic/Dictionary.bf b/BeefLibs/corlib/src/Collections/Generic/Dictionary.bf index adddac93..07a08589 100644 --- a/BeefLibs/corlib/src/Collections/Generic/Dictionary.bf +++ b/BeefLibs/corlib/src/Collections/Generic/Dictionary.bf @@ -13,7 +13,7 @@ namespace System.Collections.Generic using System.Diagnostics; using System.Diagnostics.Contracts; - public class Dictionary where TKey : IHashable //: IDictionary, IDictionary, IReadOnlyDictionary, ISerializable, IDeserializationCallback + public class Dictionary : ICollection> where TKey : IHashable //: IDictionary, IDictionary, IReadOnlyDictionary, ISerializable, IDeserializationCallback { private struct Entry { @@ -107,6 +107,11 @@ namespace System.Collections.Generic { Insert(key, value, true); } + + public void Add(KeyValuePair kvPair) + { + Insert(kvPair.Key, kvPair.Value, true); + } public bool TryAdd(TKey key, TValue value) { @@ -215,6 +220,36 @@ namespace System.Collections.Generic } return false; } + + public bool Contains(KeyValuePair kvPair) + { + TValue value; + if(TryGetValue(kvPair.Key, out value)) + { + return value == kvPair.Value; + }else{ + return false; + } + } + + public void CopyTo(KeyValuePair[] kvPair, int index) + { + Keys.Reset(); + Values.Reset(); + int i = 0; + + repeat + { + if(i >= index) + { + kvPair[i] = KeyValuePair(Keys.Current, Values.CurrentRef); + } + } + while(Keys.MoveNext() && Values.MoveNext()); + + Keys.Reset(); + Values.Reset(); + } public Enumerator GetEnumerator() { @@ -459,6 +494,12 @@ namespace System.Collections.Generic } return false; } + + [Inline] + public bool Remove(KeyValuePair kvPair) + { + return Remove(kvPair.Key); + } public Result<(TKey key, TValue value)> GetAndRemove(TKey key) { diff --git a/BeefLibs/corlib/src/Collections/Generic/ICollection.bf b/BeefLibs/corlib/src/Collections/Generic/ICollection.bf new file mode 100644 index 00000000..52d683b4 --- /dev/null +++ b/BeefLibs/corlib/src/Collections/Generic/ICollection.bf @@ -0,0 +1,16 @@ +namespace System.Collections.Generic +{ + interface ICollection + { + public abstract int Count + { + get; + } + + public void Add(T item); + public void Clear(); + public bool Contains(T item); + public void CopyTo(T[] arr, int index); + public bool Remove(T item); + } +} diff --git a/BeefLibs/corlib/src/Collections/Generic/List.bf b/BeefLibs/corlib/src/Collections/Generic/List.bf index 1ce7c14e..5b012c33 100644 --- a/BeefLibs/corlib/src/Collections/Generic/List.bf +++ b/BeefLibs/corlib/src/Collections/Generic/List.bf @@ -23,7 +23,7 @@ namespace System.Collections.Generic } } - public class List : IEnumerable, IList + public class List : IEnumerable, IList, ICollection { private const int_cosize cDefaultCapacity = 4;