Comapre two arrays of blocks. If the file is open, do not compare
sizes of the blocks.
484334
private boolean blocksEquals(Block[] a1, Block[] a2, boolean closedFile) {
    if (a1 == a2)
      return true;
    if (a1 == null || a2 == null || a2.length != a1.length)
      return false;

    for (int i = 0; i < a1.length; i++) {
      Block b1 = a1[i];
      Block b2 = a2[i];

      if (b1 == b2)
        continue;
      if (b1 == null || b2 == null)
        return false;

      // compare ids and gen stamps
      if (!(b1.getBlockId() == b2.getBlockId() && b1.getGenerationStamp() == b2
          .getGenerationStamp()))
        return false;

      // for open files check len-2 blocks only
      if (!closedFile && i >= a1.length - 2)
        continue;

      // check block size
      if (b1.getNumBytes() != b2.getNumBytes())
        return false;
    }
    return true;
  }
495406
private function isArrayContentsEqual($a, $b)
    {
        foreach ($b as $one) {
            $pos = array_search($one, $a, true);
            if ($pos === false) {
                return false;
            } else {
                unset($a[$pos]);
            }
        }

        return $a ? false : true;
    }
606743
def _compare(info1, info2):
    # type: (Info, Info) -> bool
    
    # Check filesize has changed
    if info1.size != info2.size:
        return True
    # Check modified dates
    date1 = info1.modified
    date2 = info2.modified
    return date1 is None or date2 is None or date1 > date2
1221175
private static int put(byte[] block, int offset, byte[] b, int off, int len) {
    System.arraycopy(b, off, block, offset, len);
    return len;
  }
760332
def differing_blocks(self):
        
        differing_blocks = []
        for (block_a, block_b) in self._block_matches:
            if not self.blocks_probably_identical(block_a, block_b):
                differing_blocks.append((block_a, block_b))
        return differing_blocks
1332222
def merge_blocks(a_blocks, b_blocks):
    
    # Check sentinels for sequence length.
    assert a_blocks[-1][2] == b_blocks[-1][2] == 0 # sentinel size is 0
    assert a_blocks[-1] == b_blocks[-1]
    combined_blocks = sorted(list(set(a_blocks + b_blocks)))
    # Check for overlaps.
    i = j = 0
    for a, b, size in combined_blocks:
        assert i <= a
        assert j <= b
        i = a + size
        j = b + size
    return combined_blocks
531782
static void clear(byte[][] blocks, int off, int len) {
    // this is significantly faster than looping or Arrays.fill (which loops), particularly when
    // the length of the slice to be cleared is <= to ARRAY_LEN (in that case, it's faster by a
    // factor of 2)
    int remaining = len;
    while (remaining > ARRAY_LEN) {
      System.arraycopy(NULL_ARRAY, 0, blocks, off, ARRAY_LEN);
      off += ARRAY_LEN;
      remaining -= ARRAY_LEN;
    }

    System.arraycopy(NULL_ARRAY, 0, blocks, off, remaining);
  }
286736
function(files, next) {
        var fromFile = files[0],
          toFile = files[1];

        differ(id, fromFile, toFile, next);
      }
150100
private void processBlocks(DataInputStream in, ImageVisitor v,
      int numBlocks, boolean skipBlocks) throws IOException {
    v.visitEnclosingElement(ImageElement.BLOCKS,
                            ImageElement.NUM_BLOCKS, numBlocks);
    
    // directory or symlink, no blocks to process    
    if(numBlocks == -1 || numBlocks == -2) { 
      v.leaveEnclosingElement(); // Blocks
      return;
    }
    
    if(skipBlocks) {
      int fieldsBytes = Long.SIZE * 3;
      if (LayoutVersion.supports(Feature.BLOCK_CHECKSUM, imageVersion)) {
        // For block checksum
        fieldsBytes += Integer.SIZE;
      }
      
      int bytesToSkip = ((fieldsBytes /* fields */) / 8 /*bits*/) * numBlocks;
      if(in.skipBytes(bytesToSkip) != bytesToSkip)
        throw new IOException("Error skipping over blocks");
      
    } else {
      for(int j = 0; j < numBlocks; j++) {
        v.visitEnclosingElement(ImageElement.BLOCK);
        v.visit(ImageElement.BLOCK_ID, in.readLong());
        v.visit(ImageElement.NUM_BYTES, in.readLong());
        v.visit(ImageElement.GENERATION_STAMP, in.readLong());
        if (LayoutVersion.supports(Feature.BLOCK_CHECKSUM, imageVersion)) {
          v.visit(ImageElement.BLOCK_CHECKSUM, in.readInt());
        }
        v.leaveEnclosingElement(); // Block
      }
    }
    v.leaveEnclosingElement(); // Blocks
  }
732841
protected static final int findSameIndexBlock(int index[], int indexLength,
                                                  int otherBlock) 
    {
        for (int block = BMP_INDEX_LENGTH_; block < indexLength; 
             block += SURROGATE_BLOCK_COUNT_) {
            if(equal_int(index, block, otherBlock, SURROGATE_BLOCK_COUNT_)) {
                return block;
            }
        }
        return indexLength;
    }
429828
private void validateBlockSize(byte[] descriptor) throws IOException {
        int blockSize = Util.getUInt16Both(descriptor, 129);
        if (blockSize != Constants.DEFAULT_BLOCK_SIZE) {
            throw new LoopFileSystemException("Invalid block size: " + blockSize);
        }
    }
1089118
private static boolean arrayCompare(byte[] a, int offset1, byte[] a2, int offset2, int length) {
        for (int i = 0; i < length; i++) {
            if (a[offset1++] != a2[offset2++]) return false;
        }
        return true;
    }
1007306
function (array1, array2) {
                return array1.every(function (element) {
                    return array2.includes(element);
                }) && array1.length === array2.length;
            }
584623
private void sortBlocksBySize(Map<String, List<OneBlockInfo>> nodeToBlocks) {
    OneBlockInfoSizeComparator comparator = new OneBlockInfoSizeComparator();
    for (Entry<String, List<OneBlockInfo>> entry : nodeToBlocks.entrySet()) {
      Collections.sort(entry.getValue(), comparator);
    }
  }
391951
public boolean isValidBlock(int namespaceId, Block b, boolean checkSize)
      throws IOException {
    File f = null;
    ;
    try {
      f = getValidateBlockFile(namespaceId, b, checkSize);
    } catch (IOException e) {
      DataNode.LOG.warn("Block " + b + " is not valid:", e);
    }

    return ((f != null) ? isBlockFinalizedWithLock(namespaceId, b) : false);
  }
446122
function( array, nBlocks, blockSize ) {

			var firstElem = array[ 0 ];

			if ( firstElem <= 0 || firstElem > 0 ) return array;
			// unoptimized: ! isNaN( firstElem )
			// see http://jacksondunstan.com/articles/983

			var n = nBlocks * blockSize,
				r = arrayCacheF32[ n ];

			if ( r === undefined ) {

				r = new Float32Array( n );
				arrayCacheF32[ n ] = r;

			}

			if ( nBlocks !== 0 ) {

				firstElem.toArray( r, 0 );

				for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {

					offset += blockSize;
					array[ i ].toArray( r, offset );

				}

			}

			return r;

		}
557462
private boolean skipToInitialBlock()
    {
        int offsetInBlock = (int) (initialOffset % BLOCK_SIZE);
        long blockStartLocation = initialOffset - offsetInBlock;

        // Don't search a block if we'd be in the trailer
        if (offsetInBlock > BLOCK_SIZE - 6) {
            blockStartLocation += BLOCK_SIZE;
        }

        endOfBufferOffset = blockStartLocation;

        // Skip to start of first block that can contain the initial record
        if (blockStartLocation > 0) {
            try {
                fileChannel.position(blockStartLocation);
            }
            catch (IOException e) {
                reportDrop(blockStartLocation, e);
                return false;
            }
        }

        return true;
    }