/** * Performs sorting, if necessary. */ private void ensureSorted() { if (sorted) { return; } ensureCapacity(); DataUtils.sort(byBlockHash); for (int i = 0; i < size; i++) { resourceIdsIndex[i] = i; } DataUtils.sort(byResourceId); sorted = true; }
/** * {@inheritDoc} * <p> * <strong>Note that this implementation allows insertion of two blocks with same index for one resource.</strong> * </p> */ @Override public void insert(Block block) { sorted = false; ensureCapacity(); resourceIds[size] = block.getResourceId(); int[] hash = block.getBlockHash().toIntArray(); if (hash.length != hashInts) { throw new IllegalArgumentException("Expected " + hashInts + " ints in hash, but got " + hash.length); } int offset = size * blockInts; for (int i = 0; i < hashInts; i++) { blockData[offset++] = hash[i]; } blockData[offset++] = block.getIndexInFile(); blockData[offset++] = block.getStartLine(); blockData[offset++] = block.getEndLine(); blockData[offset++] = block.getStartUnit(); blockData[offset] = block.getEndUnit(); size++; }
/** * Performs sorting, if necessary. */ private void ensureSorted() { if (sorted) { return; } ensureCapacity(); DataUtils.sort(byBlockHash); for (int i = 0; i < size; i++) { resourceIdsIndex[i] = i; } DataUtils.sort(byResourceId); sorted = true; }
/** * {@inheritDoc} * <p> * <strong>Note that this implementation allows insertion of two blocks with same index for one resource.</strong> * </p> */ @Override public void insert(Block block) { sorted = false; ensureCapacity(); resourceIds[size] = block.getResourceId(); int[] hash = block.getBlockHash().toIntArray(); if (hash.length != hashInts) { throw new IllegalArgumentException("Expected " + hashInts + " ints in hash, but got " + hash.length); } int offset = size * blockInts; for (int i = 0; i < hashInts; i++) { blockData[offset++] = hash[i]; } blockData[offset++] = block.getIndexInFile(); blockData[offset++] = block.getStartLine(); blockData[offset++] = block.getEndLine(); blockData[offset++] = block.getStartUnit(); blockData[offset] = block.getEndUnit(); size++; }