MCPcopy Create free account
hub / github.com/e2wugui/zeze / getOrAdd

Method getOrAdd

ZezeJava/ZezeJava/src/main/java/Zeze/Raft/RocksRaft/Table.java:127–151  ·  view source on GitHub ↗
(K key)

Source from the content-addressed store, hash-verified

125 }
126
127 @SuppressWarnings("unchecked")
128 public V getOrAdd(K key) {
129 Transaction currentT = Transaction.getCurrent();
130 TableKey tkey = new TableKey(name, key);
131
132 var cr = currentT.getRecordAccessed(tkey);
133 if (cr != null) {
134 V crv = (V)cr.newestValue();
135 if (crv != null)
136 return crv;
137 // add
138 } else {
139 Record<K> r = getOrLoad(key);
140 cr = new Transaction.RecordAccessed(r);
141 currentT.addRecordAccessed(r.createRootInfoIfNeed(tkey), cr);
142 if (r.getValue() != null)
143 return (V)r.getValue();
144 // add
145 }
146
147 V add = newValue();
148 add.initRootInfo(cr.getOrigin().createRootInfoIfNeed(tkey), null);
149 cr.put(currentT, add);
150 return add;
151 }
152
153 private Record<K> getOrLoad(K key) {
154 return getOrLoad(key, null);

Callers 4

updateMethod · 0.45
verifyDataMethod · 0.45
editInContainerMethod · 0.45
getOrLoadMethod · 0.45

Calls 11

getCurrentMethod · 0.95
getRecordAccessedMethod · 0.95
getOrLoadMethod · 0.95
addRecordAccessedMethod · 0.95
newValueMethod · 0.95
getOriginMethod · 0.80
getValueMethod · 0.65
putMethod · 0.65
newestValueMethod · 0.45
createRootInfoIfNeedMethod · 0.45
initRootInfoMethod · 0.45

Tested by 3

updateMethod · 0.36
verifyDataMethod · 0.36
editInContainerMethod · 0.36