1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-12 21:34:11 +02:00

Merge pull request #186 from HydrogenC/patch-1

Various fixes and changes
This commit is contained in:
Brian Fiete 2020-05-01 09:02:28 -07:00 committed by GitHub
commit fbe2407ffb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 101 deletions

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections;
using System.Text; using System.Text;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;

View file

@ -13,8 +13,10 @@ namespace System.Collections
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
public class Dictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>> where TKey : IHashable //: IDictionary<TKey, TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue>, ISerializable, IDeserializationCallback public class Dictionary<TKey, TValue> : ICollection<(TKey key, TValue* value)>, IEnumerable<(TKey key, TValue* value)> where TKey : IHashable //: IDictionary<TKey, TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue>, ISerializable, IDeserializationCallback
{ {
typealias KeyValuePair=(TKey key, TValue* value);
private struct Entry private struct Entry
{ {
public TKey mKey; // Key of entry public TKey mKey; // Key of entry
@ -107,10 +109,10 @@ namespace System.Collections
{ {
Insert(key, value, true); Insert(key, value, true);
} }
public void Add(KeyValuePair<TKey, TValue> kvPair) public void Add(KeyValuePair kvPair)
{ {
Insert(kvPair.Key, kvPair.Value, true); Insert(kvPair.key, *kvPair.value, true);
} }
public bool TryAdd(TKey key, TValue value) public bool TryAdd(TKey key, TValue value)
@ -221,18 +223,18 @@ namespace System.Collections
return false; return false;
} }
public bool Contains(KeyValuePair<TKey, TValue> kvPair) public bool Contains(KeyValuePair kvPair)
{ {
TValue value; TValue value;
if(TryGetValue(kvPair.Key, out value)) if(TryGetValue(kvPair.key, out value))
{ {
return value == kvPair.Value; return value == *kvPair.value;
}else{ }else{
return false; return false;
} }
} }
public void CopyTo(KeyValuePair<TKey, TValue>[] kvPair, int index) public void CopyTo(KeyValuePair[] kvPair, int index)
{ {
Keys.Reset(); Keys.Reset();
Values.Reset(); Values.Reset();
@ -242,7 +244,7 @@ namespace System.Collections
{ {
if(i >= index) if(i >= index)
{ {
kvPair[i] = KeyValuePair<TKey,TValue>(Keys.Current, Values.CurrentRef); kvPair[i]=(Keys.Current, &Values.CurrentRef);
} }
} }
while(Keys.MoveNext() && Values.MoveNext()); while(Keys.MoveNext() && Values.MoveNext());
@ -496,9 +498,9 @@ namespace System.Collections
} }
[Inline] [Inline]
public bool Remove(KeyValuePair<TKey, TValue> kvPair) public bool Remove(KeyValuePair kvPair)
{ {
return Remove(kvPair.Key); return Remove(kvPair.key);
} }
public Result<(TKey key, TValue value)> GetAndRemove(TKey key) public Result<(TKey key, TValue value)> GetAndRemove(TKey key)
@ -602,7 +604,7 @@ namespace System.Collections
return (key is TKey); return (key is TKey);
} }
public struct Enumerator : IEnumerator<(TKey key, TValue value)>//, IDictionaryEnumerator public struct Enumerator : IEnumerator<KeyValuePair>//, IDictionaryEnumerator
{ {
private Dictionary<TKey, TValue> mDictionary; private Dictionary<TKey, TValue> mDictionary;
#if VERSION_DICTIONARY #if VERSION_DICTIONARY
@ -678,13 +680,14 @@ namespace System.Collections
} }
} }
public (TKey key, TValue value) Current public KeyValuePair Current
{ {
get { return (mDictionary.mEntries[mCurrentIndex].mKey, mDictionary.mEntries[mCurrentIndex].mValue); } get { return (mDictionary.mEntries[mCurrentIndex].mKey, &mDictionary.mEntries[mCurrentIndex].mValue); }
} }
public void Dispose() public void Dispose()
{ {
} }
public void SetValue(TValue value) public void SetValue(TValue value)
@ -742,7 +745,7 @@ namespace System.Collections
} }
}*/ }*/
public Result<(TKey key, TValue value)> GetNext() mut public Result<KeyValuePair> GetNext() mut
{ {
if (!MoveNext()) if (!MoveNext())
return .Err; return .Err;

View file

@ -5,6 +5,7 @@ namespace System.Collections
interface IEnumerator<T> interface IEnumerator<T>
{ {
Result<T> GetNext() mut; Result<T> GetNext() mut;
T Current { get; };
} }
interface IResettable interface IResettable

View file

@ -1,45 +0,0 @@
namespace System.Collections
{
public struct KeyValuePair<TKey, TValue>
{
private TKey mKey;
private TValue mValue;
public this(TKey key, TValue value)
{
this.mKey = key;
this.mValue = value;
}
public TKey Key
{
get { return mKey; }
}
public TValue Value
{
get { return mValue; }
}
public override void ToString(String strOut)
{
strOut.Append('[');
if (Key != null)
{
Key.ToString(strOut);
}
strOut.Append(", ");
if (Value != null)
{
Value.ToString(strOut);
}
strOut.Append(']');
}
}
}
namespace System.Collections.Generic
{
[Obsolete("The System.Collections.Generic types have been moved into System.Collections", false)]
typealias KeyValuePair<TKey, TValue> = System.Collections.KeyValuePair<TKey, TValue>;
}

View file

@ -120,7 +120,7 @@ namespace System
for (let kv in envVars) for (let kv in envVars)
{ {
keys[idx] = kv.key; keys[idx] = kv.key;
values[idx] = kv.value; values[idx] = *kv.value;
++idx; ++idx;
} }
@ -158,7 +158,7 @@ namespace System
for (let kv in envVars) for (let kv in envVars)
{ {
keys[idx] = kv.key; keys[idx] = kv.key;
values[idx] = kv.value; values[idx] = *kv.value;
++idx; ++idx;
} }
@ -182,4 +182,4 @@ namespace System
data.Add(0); data.Add(0);
} }
} }
} }

View file

@ -76,7 +76,7 @@ namespace System
for (let kv in lhs.mProperties) for (let kv in lhs.mProperties)
{ {
Object lhsVal = kv.value; Object lhsVal = *kv.value;
Object rhsVal; Object rhsVal;
if (!rhs.Get(kv.key, out rhsVal)) if (!rhs.Get(kv.key, out rhsVal))
return false; return false;

View file

@ -214,7 +214,7 @@ Size = "mLength"
ValuePointer = "mPtr" ValuePointer = "mPtr"
[[Type]] [[Type]]
Name = "System.Collections.Generic.List<*>" Name = "System.Collections.List<*>"
DisplayString = "{{ count={mSize} }}" DisplayString = "{{ count={mSize} }}"
[[Type.Expand.Item]] [[Type.Expand.Item]]
Name = "[Count]" Name = "[Count]"
@ -232,7 +232,7 @@ Size = "mSize"
ValuePointer = "mItems" ValuePointer = "mItems"
[[Type]] [[Type]]
Name = "System.Collections.Generic.Queue<*>" Name = "System.Collections.Queue<*>"
DisplayString = "{{ count={mSize} }}" DisplayString = "{{ count={mSize} }}"
[[Type.Expand.Item]] [[Type.Expand.Item]]
Name = "[Count]" Name = "[Count]"
@ -250,7 +250,7 @@ Size = "mSize"
ValueNode = "mItems[($i + mHead) % __clearHighBits(mAllocSizeAndFlags, 2)]" ValueNode = "mItems[($i + mHead) % __clearHighBits(mAllocSizeAndFlags, 2)]"
[[Type]] [[Type]]
Name = "System.Collections.Generic.BinaryHeap<*>" Name = "System.Collections.BinaryHeap<*>"
DisplayString = "{{ count={mSize} }}" DisplayString = "{{ count={mSize} }}"
[[Type.Expand.Item]] [[Type.Expand.Item]]
Name = "[Count]" Name = "[Count]"
@ -260,7 +260,7 @@ Size = "mSize"
ValuePointer = "&this.mData.mFirstElement" ValuePointer = "&this.mData.mFirstElement"
[[Type]] [[Type]]
Name = "System.Collections.Generic.Dictionary<*, *>" Name = "System.Collections.Dictionary<*, *>"
DisplayString = "{{ count={mCount - mFreeCount} }}" DisplayString = "{{ count={mCount - mFreeCount} }}"
[[Type.Expand.Item]] [[Type.Expand.Item]]
Name = "[Count]" Name = "[Count]"
@ -274,7 +274,7 @@ Value = "mValue"
Next = "mNext" Next = "mNext"
[[Type]] [[Type]]
Name = "System.Collections.Generic.Dictionary<*, *>.Entry" Name = "System.Collections.Dictionary<*, *>.Entry"
DisplayString = "{{[{mKey}, {mValue}]}}" DisplayString = "{{[{mKey}, {mValue}]}}"
[[Type.Expand.Item]] [[Type.Expand.Item]]
Name = "[Key]" Name = "[Key]"
@ -284,7 +284,7 @@ Name = "[Value]"
Value = "mValue" Value = "mValue"
[[Type]] [[Type]]
Name = "System.Collections.Generic.HashSet<*>" Name = "System.Collections.HashSet<*>"
DisplayString = "{{ count={mCount} }}" DisplayString = "{{ count={mCount} }}"
[[Type.Expand.Item]] [[Type.Expand.Item]]
Name = "[Count]" Name = "[Count]"
@ -294,16 +294,6 @@ Size = "mCount"
ValuePointer = "&mSlots.mFirstElement" ValuePointer = "&mSlots.mFirstElement"
Condition = "mHashCode >= 0" Condition = "mHashCode >= 0"
[[Type]]
Name = "System.Collections.Generic.KeyValuePair<*, *>"
DisplayString = "{{{mKey}, {mValue}}}"
[[Type.Expand.Item]]
Name = "[Key]"
Value = "mKey"
[[Type.Expand.Item]]
Name = "[Value]"
Value = "mValue"
#################### C++ Standard Types #################### #################### C++ Standard Types ####################
[[Type]] [[Type]]

View file

@ -620,7 +620,7 @@
}, },
"Type": { "Type": {
"Name": "System.Collections.Generic.List<*>", "Name": "System.Collections.List<*>",
"DisplayString": "{{ count={mSize} }}", "DisplayString": "{{ count={mSize} }}",
"Expand": { "Expand": {
"Item": { "Item": {
@ -635,7 +635,7 @@
}, },
"Type": { "Type": {
"Name": "System.Collections.Generic.Dictionary<*, *>", "Name": "System.Collections.Dictionary<*, *>",
"DisplayString": "{{ count={mCount - mFreeCount} }}", "DisplayString": "{{ count={mCount - mFreeCount} }}",
"Expand": { "Expand": {
"Item": { "Item": {
@ -654,7 +654,7 @@
}, },
"Type": { "Type": {
"Name": "System.Collections.Generic.Dictionary<*, *>.Entry", "Name": "System.Collections.Dictionary<*, *>.Entry",
"DisplayString": "{{[{mKey}, {mValue}]}}", "DisplayString": "{{[{mKey}, {mValue}]}}",
"Expand": { "Expand": {
"Item": { "Item": {
@ -669,7 +669,7 @@
}, },
"Type": { "Type": {
"Name": "System.Collections.Generic.HashSet<*>", "Name": "System.Collections.HashSet<*>",
"DisplayString": "{{ count={mCount} }}", "DisplayString": "{{ count={mCount} }}",
"Expand": { "Expand": {
"Item": { "Item": {
@ -683,21 +683,6 @@
} }
} }
}, },
"Type": {
"Name": "System.Collections.Generic.KeyValuePair<*, *>",
"DisplayString": "{{{mKey}, {mValue}}}",
"Expand": {
"Item": {
"Name": "[Key]",
"Value": "mKey"
},
"Item": {
"Name": "[Value]",
"Value": "mValue"
}
}
},
"Type": { "Type": {
"Name": "llvm::SmallVectorImpl<*>", "Name": "llvm::SmallVectorImpl<*>",
@ -1183,4 +1168,4 @@
} }
} }
} }