public int[] getNearestNeighboursElementIds(long[] key, int beamRadius) {
    ReferenceBlock containingBlock = getBlockFor(key);
    ReferenceBlock lowerBlock = null;
    ReferenceBlock higherBlock = null;
    
    IntList neighbours = new IntArrayList(3 * blockSize);
    
    if (containingBlock == null) {
      higherBlock = firstBlock;
    } else {
      neighbours.addElements(neighbours.size(), containingBlock.getElements());
      
      lowerBlock = containingBlock.getPreviousBlock();
      higherBlock = containingBlock.getNextBlock();
    }
    
    int fetchSmallerElements = beamRadius, fetchGreaterElements = beamRadius;
    
    while (lowerBlock != null && fetchSmallerElements > 0) {
      neighbours.addElements(neighbours.size(), lowerBlock.getElements());

      fetchSmallerElements -= lowerBlock.getSize();
      lowerBlock = lowerBlock.getPreviousBlock();
    }
    
    while (higherBlock != null && fetchGreaterElements > 0) {
      neighbours.addElements(neighbours.size(), higherBlock.getElements());
      
      fetchGreaterElements -= higherBlock.getSize();
      higherBlock = higherBlock.getNextBlock();
    }
    
    return neighbours.toArray(new int[neighbours.size()]);
  }