mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-15 06:44:10 +02:00
commit
86a97a12e5
3 changed files with 59 additions and 2 deletions
|
@ -13,7 +13,7 @@ namespace System.Collections.Generic
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics.Contracts;
|
using System.Diagnostics.Contracts;
|
||||||
|
|
||||||
public class Dictionary<TKey, TValue> where TKey : IHashable //: IDictionary<TKey, TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue>, ISerializable, IDeserializationCallback
|
public class Dictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>> where TKey : IHashable //: IDictionary<TKey, TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue>, ISerializable, IDeserializationCallback
|
||||||
{
|
{
|
||||||
private struct Entry
|
private struct Entry
|
||||||
{
|
{
|
||||||
|
@ -108,6 +108,11 @@ namespace System.Collections.Generic
|
||||||
Insert(key, value, true);
|
Insert(key, value, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Add(KeyValuePair<TKey, TValue> kvPair)
|
||||||
|
{
|
||||||
|
Insert(kvPair.Key, kvPair.Value, true);
|
||||||
|
}
|
||||||
|
|
||||||
public bool TryAdd(TKey key, TValue value)
|
public bool TryAdd(TKey key, TValue value)
|
||||||
{
|
{
|
||||||
TKey* keyPtr;
|
TKey* keyPtr;
|
||||||
|
@ -216,6 +221,36 @@ namespace System.Collections.Generic
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Contains(KeyValuePair<TKey, TValue> kvPair)
|
||||||
|
{
|
||||||
|
TValue value;
|
||||||
|
if(TryGetValue(kvPair.Key, out value))
|
||||||
|
{
|
||||||
|
return value == kvPair.Value;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CopyTo(KeyValuePair<TKey, TValue>[] kvPair, int index)
|
||||||
|
{
|
||||||
|
Keys.Reset();
|
||||||
|
Values.Reset();
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
repeat
|
||||||
|
{
|
||||||
|
if(i >= index)
|
||||||
|
{
|
||||||
|
kvPair[i] = KeyValuePair<TKey,TValue>(Keys.Current, Values.CurrentRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(Keys.MoveNext() && Values.MoveNext());
|
||||||
|
|
||||||
|
Keys.Reset();
|
||||||
|
Values.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
public Enumerator GetEnumerator()
|
public Enumerator GetEnumerator()
|
||||||
{
|
{
|
||||||
return Enumerator(this, Enumerator.[Friend]KeyValuePair);
|
return Enumerator(this, Enumerator.[Friend]KeyValuePair);
|
||||||
|
@ -460,6 +495,12 @@ namespace System.Collections.Generic
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Inline]
|
||||||
|
public bool Remove(KeyValuePair<TKey, TValue> kvPair)
|
||||||
|
{
|
||||||
|
return Remove(kvPair.Key);
|
||||||
|
}
|
||||||
|
|
||||||
public Result<(TKey key, TValue value)> GetAndRemove(TKey key)
|
public Result<(TKey key, TValue value)> GetAndRemove(TKey key)
|
||||||
{
|
{
|
||||||
if (mBuckets != null)
|
if (mBuckets != null)
|
||||||
|
|
16
BeefLibs/corlib/src/Collections/Generic/ICollection.bf
Normal file
16
BeefLibs/corlib/src/Collections/Generic/ICollection.bf
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
namespace System.Collections.Generic
|
||||||
|
{
|
||||||
|
interface ICollection<T>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,7 +23,7 @@ namespace System.Collections.Generic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class List<T> : IEnumerable<T>, IList
|
public class List<T> : IEnumerable<T>, IList, ICollection<T>
|
||||||
{
|
{
|
||||||
private const int_cosize cDefaultCapacity = 4;
|
private const int_cosize cDefaultCapacity = 4;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue