Beispiel #1
0
        private static bool TryGetNextValueAtomic(
            NativeHashSetState *state,
            ref NativeMultiHashSetIterator it)
        {
            int entryIdx = it.NextEntryIndex;

            it.NextEntryIndex = -1;
            if (entryIdx < 0 || entryIdx >= state->ItemCapacity)
            {
                return(false);
            }

            int *nextPtrs = (int *)state->Next;

            while (!UnsafeUtility.ReadArrayElement <T>(
                       state->Items,
                       entryIdx).Equals(it.Item))
            {
                entryIdx = nextPtrs[entryIdx];
                if (entryIdx < 0 || entryIdx >= state->ItemCapacity)
                {
                    return(false);
                }
            }
            it.NextEntryIndex = nextPtrs[entryIdx];

            return(true);
        }
Beispiel #2
0
        private static bool TryGetFirstValueAtomic(
            NativeHashSetState *state,
            T item,
            out NativeMultiHashSetIterator it)
        {
            it.Item = item;
            if (state->AllocatedIndexLength <= 0)
            {
                it.NextEntryIndex = -1;
                return(false);
            }
            // First find the slot based on the hash
            int *buckets = (int *)state->Buckets;
            int  bucket  = item.GetHashCode() & state->BucketCapacityMask;

            it.NextEntryIndex = buckets[bucket];
            return(TryGetNextValueAtomic(state, ref it));
        }