code: public void setPrimitive(int index, int value) {
          int pos = Arrays.binarySearch(indices, index);
  
          if (value != 0) {
              // need to make room in the indices array
              if (pos < 0) {
                  int newPos = 0 - (pos + 1);
                  int[] newIndices = new int[indices.length + 1];
                  int[] newValues = new int[values.length + 1];
              
                  // copy the existing array contents that are valid in their
                  // current positions
                  for (int i = 0; i < newPos; ++i) {
                      newValues[i] = values[i];
                      newIndices[i] = indices[i];
                  }
  
                  // shift the elements down by one to make room
                  for (int i = newPos; i < values.length; ++i) {
                      newValues[i+1] = values[i];
                      newIndices[i+1] = indices[i];
                  }
                      
                  // swap the arrays
                  indices = newIndices;
                  values = newValues;
                  pos = newPos;
                      
                   // update the position of the pos in the values array
                  indices[pos] = index;
              }
              values[pos] = value;
          }
          // The value is zero but previously held a spot in the matrix, so
          // remove its position and shift everything over
          else if (value == 0 && pos >= 0) {
              int newLength = indices.length - 1;
              int[] newIndices = new int[newLength];
              int[] newValues = new int[newLength];
              for (int i = 0, j = 0; i < indices.length; ++i) {
                  if (i != pos) {
                      newIndices[j] = indices[i];
                      newValues[j] = values[i];            
                      j++;
                  }
              }
  
              // swap the arrays
              indices = newIndices;
              values = newValues;
          }
  
      }
docs: Sets the value of the index to the value using the Java primitives
  without auto-boxing.  if {@code value} is 0, and the value at {@code
  index} is already zero, this will be a no-op.