Beispiel #1
0
  private final int add(long tick) {
    long[] ticks = _ticks;
    Buff[] buffs = _buffs;

    if (ticks == null || ticks.length == 0) {
      ticks = new long[OpenMap.CAPACITY];
      buffs = new Buff[OpenMap.CAPACITY];
    } else if (Debug.THREADS) Tick.checkSet(ticks);

    int hash = Tick.hashTick(tick);
    int index;

    while ((index = Tick.tryToAdd(ticks, tick, hash)) < 0) {
      long[] previousTicks = ticks;
      Buff[] previousBuffs = buffs;

      for (; ; ) {
        ticks = new long[ticks.length << OpenMap.TIMES_TWO_SHIFT];
        buffs = new Buff[buffs.length << OpenMap.TIMES_TWO_SHIFT];

        if (rehash(previousTicks, ticks, previousBuffs, buffs)) break;
      }
    }

    if (Debug.ENABLED) Tick.checkSet(ticks);

    _ticks = ticks;
    _buffs = buffs;
    return index;
  }
Beispiel #2
0
  private final boolean rehash(
      long[] previousTicks, long[] ticks, Buff[] previousBuffs, Buff[] buffs) {
    for (int i = previousTicks.length - 1; i >= 0; i--) {
      if (!Tick.isNull(previousTicks[i])) {
        int index = Tick.tryToAdd(ticks, previousTicks[i], Tick.hashTick(previousTicks[i]));

        if (index < 0) return false;

        buffs[index] = previousBuffs[i];
      }
    }

    return true;
  }