MCPcopy Index your code
hub / github.com/golang/mobile / put

Method put

bind/java/Seq.java:326–355  ·  view source on GitHub ↗
(int key, Ref obj)

Source from the content-addressed store, hash-verified

324 }
325
326 void put(int key, Ref obj) {
327 if (obj == null) {
328 throw new RuntimeException("put a null ref (with key "+key+")");
329 }
330 int i = Arrays.binarySearch(keys, 0, next, key);
331 if (i >= 0) {
332 if (objs[i] == null) {
333 objs[i] = obj;
334 live++;
335 }
336 if (objs[i] != obj) {
337 throw new RuntimeException("replacing an existing ref (with key "+key+")");
338 }
339 return;
340 }
341 if (next >= keys.length) {
342 grow();
343 i = Arrays.binarySearch(keys, 0, next, key);
344 }
345 i = ~i;
346 if (i < next) {
347 // Insert, shift everything afterwards down.
348 System.arraycopy(keys, i, keys, i+1, next-i);
349 System.arraycopy(objs, i, objs, i+1, next-i);
350 }
351 keys[i] = key;
352 objs[i] = obj;
353 live++;
354 next++;
355 }
356
357 private void grow() {
358 // Compact and (if necessary) grow backing store.

Callers 3

testRefMapMethod · 0.95
incMethod · 0.80
BenchmarksClass · 0.80

Calls 1

growMethod · 0.95

Tested by 1

testRefMapMethod · 0.76