MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / insertValue

Method insertValue

JSAT/src/jsat/linear/SparseVector.java:267–286  ·  view source on GitHub ↗

Takes the negative insert location value returned by Arrays#binarySearch(int[], int, int, int) and adjust the vector to add the given value into this location. Should only be called with negative input returned by said method. Should never be called for an index that in fact does already ex

(int insertLocation, int index, double val)

Source from the content-addressed store, hash-verified

265 * @param val the value that is being added for the given index
266 */
267 private void insertValue(int insertLocation, int index, double val)
268 {
269 insertLocation = -(insertLocation+1);//Convert from negative value to the location is should be placed, see JavaDoc of binarySearch
270 if(used == indexes.length)//Full, expand
271 {
272 int newIndexesSize = Math.max(Math.min(indexes.length*2, Integer.MAX_VALUE), 8);
273 indexes = Arrays.copyOf(indexes, newIndexesSize);
274 values = Arrays.copyOf(values, newIndexesSize);
275 }
276
277 if(insertLocation < used)//Instead of moving indexes over manualy, set it up to use a native System call to move things out of the way
278 {
279 System.arraycopy(indexes, insertLocation, indexes, insertLocation+1, used-insertLocation);
280 System.arraycopy(values, insertLocation, values, insertLocation+1, used-insertLocation);
281 }
282
283 indexes[insertLocation] = index;
284 values[insertLocation] = val;
285 used++;
286 }
287
288 @Override
289 public Vec sortedCopy()

Callers 2

incrementMethod · 0.95
setMethod · 0.95

Calls 3

copyOfMethod · 0.80
maxMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected