public void testRemoveNonExistant() throws Exception {
   TIntSet set = new TIntHashSet();
   set.add(1);
   set.add(2);
   assertTrue("One was not added", set.contains(1));
   assertTrue("One was not removed", set.remove(1));
   assertFalse("One was not removed", set.contains(1));
   assertTrue("Two was also removed", set.contains(2));
   assertFalse("Three was removed (non-existant)", set.remove(3));
 }
  @Override
  protected void freeChunk(Point p) {
    int x = (int) p.getX() >> Chunk.BLOCKS.BITS;
    int y = (int) p.getY() >> Chunk.BLOCKS.BITS; // + SEALEVEL_CHUNK;
    int z = (int) p.getZ() >> Chunk.BLOCKS.BITS;

    if (y < 0 || y >= p.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return;
    }

    TIntSet column = initializedChunks.get(x, z);
    CompressedChunkMessage CCMsg;
    if (column != null) {
      column.remove(y);
      if (column.isEmpty()) {
        if (initializedChunks.remove(x, z) != null) {
          activeChunks.remove(x, z);
        }
        CCMsg = new CompressedChunkMessage(x, z, true, null, null, null, true);
      } else {
        CCMsg = new CompressedChunkMessage(x, z, false, null, null, null, true);
      }

      session.send(false, CCMsg);
    }
  }
  @Override
  public void keyReleased(final KeyEvent e) {
    //		System.out.println( "MouseAndKeyHandler.keyReleased()" );
    update();

    if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
      shiftPressed = false;
    } else if (e.getKeyCode() == KeyEvent.VK_META) {
      metaPressed = false;
    } else if (e.getKeyCode() != KeyEvent.VK_ALT
        && e.getKeyCode() != KeyEvent.VK_CONTROL
        && e.getKeyCode() != KeyEvent.VK_ALT_GRAPH) {
      pressedKeys.remove(e.getKeyCode());

      for (final BehaviourEntry<DragBehaviour> drag : activeKeyDrags)
        drag.behaviour.end(mouseX, mouseY);
      activeKeyDrags.clear();
    }
  }
  @Override
  protected void freeChunk(Point p) {
    int x = (int) p.getX() >> Chunk.BLOCKS.BITS;
    int y = (int) p.getY() >> Chunk.BLOCKS.BITS; // + SEALEVEL_CHUNK;
    int z = (int) p.getZ() >> Chunk.BLOCKS.BITS;

    if (y < 0 || y >= p.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return;
    }

    TIntSet column = initializedChunks.get(x, z);
    if (column != null) {
      column.remove(y);
      if (column.isEmpty()) {
        emptyColumns.add(IntPairHashed.key(x, z));
      } // TODO - is this required?
      /*
      else {
      	CCMsg = new ChunkDataMessage(x, z, false, null, null, null, true);
      }*/
    }
  }
  @Override
  protected void freeChunk(Point p) {
    int x = (int) p.getX() >> Chunk.BLOCKS.BITS;
    int y = (int) p.getY() >> Chunk.BLOCKS.BITS; // + SEALEVEL_CHUNK;
    int z = (int) p.getZ() >> Chunk.BLOCKS.BITS;

    RepositionManager rm = getRepositionManager();

    int cY = rm.convertChunkY(y);

    if (cY < 0 || cY >= p.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return;
    }

    TIntSet column = initializedChunks.get(x, z);
    if (column != null) {
      column.remove(y);
      if (column.isEmpty()) {
        emptyColumns.add(IntPairHashed.key(x, z));
      }
    }
  }
Пример #6
0
  @Override
  public SRResultList predictMostSimilar(
      List<SRResultList> scores, int maxResults, TIntSet validIds) {
    if (2 * scores.size() + 1 != mostSimilarCoefficients.size()) {
      throw new IllegalStateException();
    }
    TIntSet allIds = new TIntHashSet(); // ids returned by at least one metric
    for (SRResultList resultList : scores) {
      if (resultList != null) {
        for (SRResult result : resultList) {
          allIds.add(result.getId());
        }
      }
    }

    TIntDoubleHashMap scoreMap = new TIntDoubleHashMap();
    for (int id : allIds.toArray()) {
      scoreMap.put(id, mostSimilarCoefficients.get(0));
    }
    int i = 1;
    for (SRResultList resultList : scores) {
      TIntSet unknownIds = new TIntHashSet(allIds);
      double c1 = mostSimilarCoefficients.get(i); // score coeff
      double c2 = mostSimilarCoefficients.get(i + 1); // rank coefficient
      if (resultList != null) {
        for (int j = 0; j < resultList.numDocs(); j++) {
          int rank = j + 1;
          // expand or contract ranks proportionately
          if (validIds != null) {
            double k = 1.0 * numTrainingCandidateArticles / validIds.size();
            rank = (int) (rank * k);
          }
          SRResult result = resultList.get(j);
          unknownIds.remove(result.getId());
          double value = c1 * result.getScore() + c2 * Math.log(rank);
          if (debug) {
            System.err.format(
                "%s %d. %.3f (id=%d), computing %.3f * %.3f + %.3f * (log(%d) = %.3f)\n",
                "m" + i, j, value, result.getId(), c1, result.getScore(), c2, rank, Math.log(rank));
          }
          scoreMap.adjustValue(result.getId(), value);
        }
      }

      // interpolate scores for unknown ids
      double value =
          c1 * mostSimilarInterpolator.getInterpolatedScore(i / 2)
              + c2 * Math.log(mostSimilarInterpolator.getInterpolatedRank(i / 2));
      for (int id : unknownIds.toArray()) {
        scoreMap.adjustValue(id, value);
      }
      i += 2;
    }
    List<SRResult> resultList = new ArrayList<SRResult>();
    for (int id : scoreMap.keys()) {
      resultList.add(new SRResult(id, scoreMap.get(id)));
    }
    Collections.sort(resultList);
    Collections.reverse(resultList);
    int size = maxResults > resultList.size() ? resultList.size() : maxResults;
    SRResultList result = new SRResultList(size);
    for (i = 0; i < size; i++) {
      result.set(i, resultList.get(i));
    }
    return result;
  }