public unsafe Chunk *GetChunkWithEmptySlots(int *sharedComponentDataIndices, int numSharedComponents) { uint hashCode = this.GetHashCode(sharedComponentDataIndices, numSharedComponents); Node *buckets = this.buckets + ((hashCode & this.hashMask) * sizeof(Node)); Node *nodePtr2 = this.buckets + (this.hashMask * sizeof(Node)); while (true) { Chunk *chunkFromEmptySlotNode; if (buckets.IsFree()) { chunkFromEmptySlotNode = null; } else { if (!(!buckets.IsDeleted() && buckets.CheckEqual(hashCode, sharedComponentDataIndices, numSharedComponents))) { buckets++; if (buckets <= nodePtr2) { continue; } buckets = this.buckets; continue; } chunkFromEmptySlotNode = ArchetypeManager.GetChunkFromEmptySlotNode(buckets->list.Begin); } return(chunkFromEmptySlotNode); } }
private unsafe void Grow() { uint unoccupiedNodes = 0; int num4 = 0; while (true) { if (num4 > this.hashMask) { int count = (int)((this.hashMask + 1) * (this.ShouldGrow(unoccupiedNodes) ? 2 : 1)); Node *buckets = this.buckets; int num3 = ((int)this.hashMask) + 1; this.Init(count); Node *nodePtr2 = this.buckets + (this.hashMask * sizeof(Node)); int num5 = 0; while (true) { if (num5 >= num3) { UnsafeUtility.Free((void *)buckets, Allocator.Persistent); return; } Node *nodePtr3 = buckets + num5; if (!nodePtr3.IsDeleted() && !nodePtr3.IsFree()) { uint hash = nodePtr3->hash; Node *nodePtr4 = this.buckets + ((hash & this.hashMask) * sizeof(Node)); while (true) { if (nodePtr4.IsFree()) { nodePtr4[0] = nodePtr3[0]; nodePtr4->list.Next.Prev = &nodePtr4->list; nodePtr4->list.Prev.Next = &nodePtr4->list; this.emptyNodes--; break; } nodePtr4++; if (nodePtr4 > nodePtr2) { nodePtr4 = this.buckets; } } } num5++; } } if (((this.buckets + num4)).IsFree() || ((this.buckets + num4)).IsDeleted()) { unoccupiedNodes++; } num4++; } }
private unsafe void AddMultiple(UnsafeLinkedListNode *list) { Chunk *chunkPtr = ref ArchetypeManager.GetChunkFromEmptySlotNode(list.Begin); uint hashCode = this.GetHashCode(chunkPtr->SharedComponentValueArray, chunkPtr->Archetype.NumSharedComponents); int * sharedComponentValueArray = chunkPtr->SharedComponentValueArray; int numSharedComponents = chunkPtr->Archetype.NumSharedComponents; Node * buckets = this.buckets + ((hashCode & this.hashMask) * sizeof(Node)); Node * nodePtr2 = this.buckets + (this.hashMask * sizeof(Node)); Node * nodePtr3 = null; while (true) { if (buckets.IsFree()) { if (nodePtr3 == null) { nodePtr3 = buckets; this.emptyNodes--; } nodePtr3->hash = hashCode; UnsafeLinkedListNode.InitializeList(&nodePtr3->list); UnsafeLinkedListNode.InsertListBefore(nodePtr3->list.End, list); if (this.ShouldGrow(this.emptyNodes)) { this.Grow(); } break; } if (!buckets.IsDeleted()) { if (buckets.CheckEqual(hashCode, sharedComponentValueArray, numSharedComponents)) { UnsafeLinkedListNode.InsertListBefore(buckets->list.End, list); break; } } else if (nodePtr3 == null) { nodePtr3 = buckets; } buckets++; if (buckets > nodePtr2) { buckets = this.buckets; } } }
public unsafe void Add(Chunk *chunk) { int * sharedComponentValueArray = chunk.SharedComponentValueArray; int numSharedComponents = chunk.Archetype.NumSharedComponents; uint hashCode = this.GetHashCode(sharedComponentValueArray, numSharedComponents); Node *buckets = this.buckets + ((hashCode & this.hashMask) * sizeof(Node)); Node *nodePtr2 = this.buckets + (this.hashMask * sizeof(Node)); Node *nodePtr3 = null; while (true) { if (buckets.IsFree()) { if (nodePtr3 == null) { nodePtr3 = buckets; this.emptyNodes--; } nodePtr3->hash = hashCode; UnsafeLinkedListNode.InitializeList(&nodePtr3->list); nodePtr3->list.Add(&chunk.ChunkListWithEmptySlotsNode); if (this.ShouldGrow(this.emptyNodes)) { this.Grow(); } break; } if (!buckets.IsDeleted()) { if (buckets.CheckEqual(hashCode, sharedComponentValueArray, numSharedComponents)) { buckets->list.Add(&chunk.ChunkListWithEmptySlotsNode); break; } } else if (nodePtr3 == null) { nodePtr3 = buckets; } buckets++; if (buckets > nodePtr2) { buckets = this.buckets; } } }
public unsafe void AppendFrom(ChunkListMap *src) { if (src.buckets != null) { Node *buckets = src.buckets; int num = ((int)src.hashMask) + 1; int num2 = 0; while (true) { if (num2 >= num) { break; } Node *nodePtr2 = buckets + num2; if (!nodePtr2.IsDeleted() && !nodePtr2.IsFree()) { this.AddMultiple(&nodePtr2->list); } num2++; } } }