1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-24 18:48:01 +02:00

Fixes for large strings, multiple 'opposite' operators

This commit is contained in:
Brian Fiete 2019-10-01 12:48:08 -07:00
parent 1346e241db
commit f266fe69d1
8 changed files with 110 additions and 34 deletions

View file

@ -286,7 +286,7 @@ namespace System.Collections.Generic
private void Insert(TKey key, TValue value, bool add)
{
if (mBuckets == null) Initialize(0);
int_cosize hashCode = (int_cosize)key.GetHashCode() & 0x7FFFFFFF;
int32 hashCode = (int32)key.GetHashCode() & 0x7FFFFFFF;
int_cosize targetBucket = hashCode % (int_cosize)mBuckets.Count;
for (int_cosize i = mBuckets[targetBucket]; i >= 0; i = mEntries[i].mNext)
@ -335,7 +335,7 @@ namespace System.Collections.Generic
private bool Insert(TKey key, bool add, out TKey* keyPtr, out TValue* valuePtr)
{
if (mBuckets == null) Initialize(0);
int_cosize hashCode = (int_cosize)key.GetHashCode() & 0x7FFFFFFF;
int32 hashCode = (int32)key.GetHashCode() & 0x7FFFFFFF;
int_cosize targetBucket = hashCode % (int_cosize)mBuckets.Count;
for (int_cosize i = mBuckets[targetBucket]; i >= 0; i = mEntries[i].mNext)
@ -413,7 +413,7 @@ namespace System.Collections.Generic
{
if (newEntries[i].mHashCode != -1)
{
newEntries[i].mHashCode = (int_cosize)newEntries[i].mKey.GetHashCode() & 0x7FFFFFFF;
newEntries[i].mHashCode = (int32)newEntries[i].mKey.GetHashCode() & 0x7FFFFFFF;
}
}
}
@ -445,7 +445,7 @@ namespace System.Collections.Generic
if (mBuckets != null)
{
int_cosize hashCode = (int_cosize)key.GetHashCode() & 0x7FFFFFFF;
int32 hashCode = (int32)key.GetHashCode() & 0x7FFFFFFF;
int_cosize bucket = hashCode % (int_cosize)mBuckets.Count;
int_cosize last = -1;
for (int_cosize i = mBuckets[bucket]; i >= 0; last = i,i = mEntries[i].mNext)

View file

@ -196,6 +196,24 @@ namespace System.Collections.Generic
return false;
}
public bool ContainsWith<TAltKey>(TAltKey item) where TAltKey : IOpEquals<T>, IHashable
{
if (mBuckets != null)
{
int32 hashCode = (int32)item.GetHashCode() & Lower31BitMask;
// see note at "HashSet" level describing why "- 1" appears in for loop
for (int32 i = mBuckets[hashCode % mBuckets.Count] - 1; i >= 0; i = mSlots[i].mNext)
{
if (mSlots[i].mHashCode == hashCode && /*m_comparer.Equals*/(mSlots[i].mValue == item))
{
return true;
}
}
}
// either m_buckets is null or wasn't found
return false;
}
/// Copy items in this hashset to array, starting at arrayIndex
/// @param array array to add items to
/// @param arrayIndex index to start at

View file

@ -4,7 +4,11 @@ using System.Collections.Generic;
namespace System
{
// Collection size type
#if BF_LARGE_COLLECTIONS
typealias int_cosize = int64;
#else
typealias int_cosize = int32;
#endif
[AlwaysInclude]
static class CompilerSettings
@ -17,6 +21,18 @@ namespace System
public const bool cHasVDataExtender = true;
public const int32 cVDataIntefaceSlotCount = 16;
#if BF_LARGE_STRINGS
public const bool cHasLargeStrings = true;
#else
public const bool cHasLargeStrings = false;
#endif
#if BF_LARGE_COLLECTIONS
public const bool cHasLargeCollections = true;
#else
public const bool cHasLargeCollections = false;
#endif
static this()
{
// This ensures this gets included in vdata