// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.common.fastutil;

import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.HashCommon;
import javax.annotation.Nonnull;
import com.hypixel.hytale.function.predicate.LongTriIntBiObjPredicate;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;

public class HLongOpenHashSet extends LongOpenHashSet implements HLongSet
{
    @Override
    public <T, V> void removeIf(@Nonnull final LongTriIntBiObjPredicate<T, V> predicate, final int ia, final int ib, final int ic, final T obj1, final V obj2) {
        int pos = super.n;
        int last = -1;
        int c = super.size;
        boolean mustReturnNull = super.containsNull;
        LongArrayList wrapped = null;
        while (c != 0) {
            long value = 0L;
            --c;
            if (mustReturnNull) {
                mustReturnNull = false;
                last = super.n;
                value = super.key[super.n];
            }
            else {
                final long[] key1 = super.key;
                while (--pos >= 0) {
                    if (key1[pos] != 0L) {
                        value = key1[last = pos];
                        break;
                    }
                }
                if (pos < 0) {
                    last = Integer.MIN_VALUE;
                    value = wrapped.getLong(-pos - 1);
                }
            }
            if (predicate.test(value, ia, ib, ic, obj1, obj2)) {
                if (last == super.n) {
                    super.containsNull = false;
                    super.key[super.n] = 0L;
                    --super.size;
                    last = -1;
                }
                else if (pos >= 0) {
                    int pos2 = last;
                    final long[] key2 = super.key;
                    int last2 = 0;
                Label_0195:
                    while (true) {
                        last2 = pos2;
                        pos2 = (pos2 + 1 & super.mask);
                        long curr;
                        while ((curr = key2[pos2]) != 0L) {
                            final int slot = (int)HashCommon.mix(curr) & super.mask;
                            Label_0300: {
                                if (last2 <= pos2) {
                                    if (last2 >= slot) {
                                        break Label_0300;
                                    }
                                    if (slot > pos2) {
                                        break Label_0300;
                                    }
                                }
                                else if (last2 >= slot && slot > pos2) {
                                    break Label_0300;
                                }
                                pos2 = (pos2 + 1 & super.mask);
                                continue;
                            }
                            if (pos2 < last2) {
                                if (wrapped == null) {
                                    wrapped = new LongArrayList(2);
                                }
                                wrapped.add(key2[pos2]);
                            }
                            key2[last2] = curr;
                            continue Label_0195;
                        }
                        break;
                    }
                    key2[last2] = 0L;
                    --super.size;
                    last = -1;
                }
                else {
                    super.remove(wrapped.getLong(-pos - 1));
                    last = -1;
                }
            }
        }
    }
}
