public void putAndEnsureCapacity(long index,int value){
  int segment=(int)(index >>> SEGMENT_BITS);
  int position=(int)(index & SEGMENT_MASK);
  if (segment >= segments.length) {
    grow(segment + 1);
    segments[segment][position]=value;
    if (value != 0)     numberOfNonZeroEntries++;
  }
 else {
    final int old=segments[segment][position];
    if (old == 0) {
      if (value != 0) {
        segments[segment][position]=value;
        numberOfNonZeroEntries++;
      }
    }
 else {
      segments[segment][position]=value;
      if (value == 0)       numberOfNonZeroEntries--;
    }
  }
  maxIndex=Math.max(maxIndex,index);
}

public void putAndEnsureCapacity ( long index , int value ) { int segment = ( int ) ( index > > > SEGMENT_BITS ) ; int position = ( int ) ( index & SEGMENT_MASK ) ; if ( segment >= segments . length ) { grow ( segment + 1 ) ; segments [ segment ] [ position ] = value ; if ( value != 0 ) numberOfNonZeroEntries ++ ; } else { final int old = segments [ segment ] [ position ] ; if ( old == 0 ) { if ( value != 0 ) { segments [ segment ] [ position ] = value ; numberOfNonZeroEntries ++ ; } } else { segments [ segment ] [ position ] = value ; if ( value == 0 ) numberOfNonZeroEntries -- ; } } maxIndex = Math . max ( maxIndex , index ) ; }
put a value , if the index is larger than current maxindex ( ) , increases length of array
