Skip to content

Commit

Permalink
commenting #57
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Aug 3, 2023
1 parent fd94677 commit 24538e3
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions playground/Experiments/FHashMap91.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,21 @@ public interface IEntries<K, V, TEq> where TEq : IEq<K>

internal const int MinEntriesCapacity = 2;

public struct SingleArrayEntries<K, V, TEq> : IEntries<K, V, TEq> where TEq : struct, IEq<K>
/// <summary>Stores the entries in a single dynamically reallocated array</summary>
public struct SingleArrayEntries<K, V, TEq> : IEntries<K, V, TEq> where TEq : struct, IEq<K>
{
int _entryCount;
internal Entry<K, V>[] _entries;

/// <inheritdoc/>
public void Init(byte capacityBitShift) =>
_entries = new Entry<K, V>[1 << capacityBitShift];

/// <inheritdoc/>
[MethodImpl((MethodImplOptions)256)]
public int GetCount() => _entryCount;

/// <inheritdoc/>
[MethodImpl((MethodImplOptions)256)]
public ref Entry<K, V> GetSurePresentEntryRef(int index)
{
Expand All @@ -302,6 +307,7 @@ public ref Entry<K, V> GetSurePresentEntryRef(int index)
#endif
}

/// <inheritdoc/>
[MethodImpl((MethodImplOptions)256)]
public ref V AddKeyAndGetValueRef(K key)
{
Expand All @@ -325,6 +331,7 @@ public ref V AddKeyAndGetValueRef(K key)
return ref e.Value;
}

/// <summary>Tombstones the entry key</summary>
[MethodImpl((MethodImplOptions)256)]
public void TombstoneOrRemoveSurePresentEntry(int index)
{
Expand All @@ -334,25 +341,29 @@ public void TombstoneOrRemoveSurePresentEntry(int index)
}

// todo: @improve make it configurable
const byte ChunkCapacityBitShift = 8; // 8 bits == 256
const int ChunkCapacity = 1 << ChunkCapacityBitShift;
const int ChunkCapacityMask = ChunkCapacity - 1;
/// <summary>The capacity of chunk in bits for <see cref="ChunkedArrayEntries{K, V, TEq}"/></summary>
public const byte ChunkCapacityBitShift = 8; // 8 bits == 256
internal const int ChunkCapacity = 1 << ChunkCapacityBitShift;
internal const int ChunkCapacityMask = ChunkCapacity - 1;

// todo: @perf research on the similar growable indexed collection with append-to-end semantics
/// <summary>The array of array buckets, where bucket is the fixed size.
/// <summary>The array of array buckets, where bucket is the fixed size.
/// It enables adding the new bucket without for the new entries without reallocating the existing data.
/// It may allow to drop the empty bucket as well, reclaiming the memory after remove.
/// The structure is similar to Hashed Array Tree (HAT)</summary>
public struct ChunkedArrayEntries<K, V, TEq> : IEntries<K, V, TEq> where TEq : struct, IEq<K>
{
int _entryCount;
Entry<K, V>[][] _entries;
/// <inheritdoc/>
public void Init(byte capacityBitShift) =>
_entries = new[] { new Entry<K, V>[(1 << capacityBitShift) & ChunkCapacityMask] };

/// <inheritdoc/>
[MethodImpl((MethodImplOptions)256)]
public int GetCount() => _entryCount;

/// <inheritdoc/>
[MethodImpl((MethodImplOptions)256)]
public ref Entry<K, V> GetSurePresentEntryRef(int index)
{
Expand All @@ -364,6 +375,7 @@ public ref Entry<K, V> GetSurePresentEntryRef(int index)
#endif
}

/// <inheritdoc/>
public ref V AddKeyAndGetValueRef(K key)
{
var index = _entryCount++;
Expand Down Expand Up @@ -426,6 +438,7 @@ public ref V AddKeyAndGetValueRef(K key)
}
}

/// <summary>Tombstones the entry key</summary>
[MethodImpl((MethodImplOptions)256)]
public void TombstoneOrRemoveSurePresentEntry(int index)
{
Expand Down

0 comments on commit 24538e3

Please sign in to comment.