mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-18 16:10:26 +02:00
Improve ILIst and add IDictionary
This commit is contained in:
parent
d3ca45d80a
commit
b6e05186b7
4 changed files with 140 additions and 31 deletions
|
@ -6,15 +6,31 @@
|
|||
#define VERSION_DICTIONARY
|
||||
#endif
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Threading;
|
||||
|
||||
namespace System.Collections
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Threading;
|
||||
interface IDictionary
|
||||
{
|
||||
Variant this[Variant key]
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
bool ContainsKey(Variant key);
|
||||
bool ContainsValue(Variant value);
|
||||
void Add(Variant key, Variant value);
|
||||
void Clear();
|
||||
void Remove(Variant key);
|
||||
}
|
||||
|
||||
public class Dictionary<TKey, TValue> :
|
||||
IDictionary,
|
||||
ICollection<(TKey key, TValue value)>,
|
||||
IEnumerable<(TKey key, TValue value)>,
|
||||
IRefEnumerable<(TKey key, TValue* valueRef)> where TKey : IHashable
|
||||
|
@ -130,11 +146,29 @@ namespace System.Collections
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
Variant IDictionary.this[Variant key]
|
||||
{
|
||||
get
|
||||
{
|
||||
return [Unbound]Variant.Create(this[key.Get<TKey>()]);
|
||||
}
|
||||
set
|
||||
{
|
||||
this[key.Get<TKey>()] = value.Get<TValue>();
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(TKey key, TValue value)
|
||||
{
|
||||
Insert(key, value, true);
|
||||
}
|
||||
|
||||
void IDictionary.Add(Variant key, Variant value)
|
||||
{
|
||||
Add(key.Get<TKey>(), value.Get<TValue>());
|
||||
}
|
||||
|
||||
public void Add(KeyValuePair kvPair)
|
||||
{
|
||||
Insert(kvPair.key, kvPair.value, true);
|
||||
|
@ -257,6 +291,11 @@ namespace System.Collections
|
|||
return FindEntry(key) >= 0;
|
||||
}
|
||||
|
||||
bool IDictionary.ContainsKey(Variant key)
|
||||
{
|
||||
return ContainsKey(key.Get<TKey>());
|
||||
}
|
||||
|
||||
public bool ContainsKeyAlt<TAltKey>(TAltKey key) where TAltKey : IHashable where bool : operator TKey == TAltKey
|
||||
{
|
||||
return FindEntryAlt(key) >= 0;
|
||||
|
@ -270,6 +309,11 @@ namespace System.Collections
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IDictionary.ContainsValue(Variant value)
|
||||
{
|
||||
return ContainsValue(value.Get<TValue>());
|
||||
}
|
||||
|
||||
public bool Contains(KeyValuePair kvPair)
|
||||
{
|
||||
|
@ -659,6 +703,11 @@ namespace System.Collections
|
|||
return false;
|
||||
}
|
||||
|
||||
void IDictionary.Remove(Variant key)
|
||||
{
|
||||
Remove(key.Get<TKey>());
|
||||
}
|
||||
|
||||
public bool RemoveAlt<TAltKey>(TAltKey key) where TAltKey : IHashable where bool : operator TKey == TAltKey
|
||||
{
|
||||
if (mBuckets != null)
|
||||
|
|
|
@ -21,6 +21,14 @@ namespace System.Collections
|
|||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
void Add(Variant item);
|
||||
void Clear();
|
||||
bool Contains(Variant item);
|
||||
int IndexOf(Variant item);
|
||||
void Insert(int index, Variant item);
|
||||
bool Remove(Variant item);
|
||||
void RemoveAt(int index);
|
||||
}
|
||||
|
||||
public class List<T> : IEnumerable<T>, IList, ICollection<T>
|
||||
|
@ -217,6 +225,19 @@ namespace System.Collections
|
|||
}
|
||||
}
|
||||
|
||||
Variant IList.this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return [Unbound]Variant.Create(this[index]);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this[index] = value.Get<T>();
|
||||
}
|
||||
}
|
||||
|
||||
public ref T this[Index index]
|
||||
{
|
||||
[Checked]
|
||||
|
@ -297,19 +318,6 @@ namespace System.Collections
|
|||
}
|
||||
}
|
||||
|
||||
Variant IList.this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return [Unbound]Variant.Create(this[index]);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ThrowUnimplemented();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual T* Alloc(int size)
|
||||
{
|
||||
return Internal.AllocRawArrayUnmarked<T>(size);
|
||||
|
@ -368,6 +376,11 @@ namespace System.Collections
|
|||
#endif
|
||||
}
|
||||
|
||||
void IList.Add(Variant item)
|
||||
{
|
||||
Add(item.Get<T>());
|
||||
}
|
||||
|
||||
/// Adds an item to the front of the list.
|
||||
public void AddFront(T item)
|
||||
{
|
||||
|
@ -466,6 +479,11 @@ namespace System.Collections
|
|||
}
|
||||
}
|
||||
|
||||
bool IList.Contains(Variant item)
|
||||
{
|
||||
return Contains(item.Get<T>());
|
||||
}
|
||||
|
||||
public bool ContainsStrict(T item)
|
||||
{
|
||||
if (item == null)
|
||||
|
@ -582,6 +600,11 @@ namespace System.Collections
|
|||
return -1;
|
||||
}
|
||||
|
||||
int IList.IndexOf(Variant item)
|
||||
{
|
||||
return IndexOf(item.Get<T>());
|
||||
}
|
||||
|
||||
public int IndexOf(T item, int index)
|
||||
{
|
||||
Debug.Assert((uint)index < (uint)mSize);
|
||||
|
@ -681,6 +704,11 @@ namespace System.Collections
|
|||
#endif
|
||||
}
|
||||
|
||||
void IList.Insert(int index, Variant item)
|
||||
{
|
||||
Insert(index, item.Get<T>());
|
||||
}
|
||||
|
||||
public void Insert(int index, Span<T> items)
|
||||
{
|
||||
//TODO: Handle case where Span is a reference to ourselves
|
||||
|
@ -840,6 +868,11 @@ namespace System.Collections
|
|||
return false;
|
||||
}
|
||||
|
||||
bool IList.Remove(Variant item)
|
||||
{
|
||||
return Remove(item.Get<T>());
|
||||
}
|
||||
|
||||
public bool RemoveStrict(T item)
|
||||
{
|
||||
int index = IndexOfStrict(item);
|
||||
|
|
|
@ -184,6 +184,19 @@ namespace System.Collections
|
|||
}
|
||||
}
|
||||
|
||||
Variant IList.this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return [Unbound]Variant.Create(this[index]);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ThrowUnimplemented();
|
||||
}
|
||||
}
|
||||
|
||||
public int Count => mSize;
|
||||
|
||||
[Inline] public Data Data => .(this);
|
||||
|
@ -312,6 +325,16 @@ namespace System.Collections
|
|||
#endif
|
||||
}
|
||||
|
||||
public void IList.Add(Variant item)
|
||||
{
|
||||
Add(item.Get<T>());
|
||||
}
|
||||
|
||||
public void IList.Insert(int index, Variant item)
|
||||
{
|
||||
Runtime.NotImplemented();
|
||||
}
|
||||
|
||||
protected override void GCMarkMembers()
|
||||
{
|
||||
[Comptime]
|
||||
|
@ -358,6 +381,11 @@ namespace System.Collections
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool IList.Contains(Variant item)
|
||||
{
|
||||
return Contains(item.Get<T>());
|
||||
}
|
||||
|
||||
public void CopyTo(Span<T> span)
|
||||
{
|
||||
for (int i < span.Length)
|
||||
|
@ -376,6 +404,11 @@ namespace System.Collections
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool IList.Remove(Variant item)
|
||||
{
|
||||
return Remove(item.Get<T>());
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
Debug.Assert((uint)index < (uint)mSize);
|
||||
|
@ -417,19 +450,6 @@ namespace System.Collections
|
|||
#endif
|
||||
}
|
||||
|
||||
Variant IList.this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return [Unbound]Variant.Create(this[index]);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ThrowUnimplemented();
|
||||
}
|
||||
}
|
||||
|
||||
public Enumerator GetEnumerator()
|
||||
{
|
||||
return .(this);
|
||||
|
@ -451,6 +471,11 @@ namespace System.Collections
|
|||
return -1;
|
||||
}
|
||||
|
||||
public int IList.IndexOf(Variant item)
|
||||
{
|
||||
return IndexOf(item.Get<T>());
|
||||
}
|
||||
|
||||
public int IndexOf(T item, int index)
|
||||
{
|
||||
for (int i = index; i < mSize; i++)
|
||||
|
|
|
@ -282,6 +282,8 @@ namespace System
|
|||
}
|
||||
}
|
||||
|
||||
public T Get<T>() => Runtime.NotImplemented();
|
||||
|
||||
public T Get<T>() where T : class
|
||||
{
|
||||
Debug.Assert(IsObject);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue