Skip to content

Commit

Permalink
adds setAll utility metho on transient
Browse files Browse the repository at this point in the history
  • Loading branch information
slawo-ch committed Feb 17, 2020
1 parent 14acb3a commit fed5714
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,42 @@ public void setAll(Map<K, V> src) {
setAll(src.entrySet());
}

public void setAll(K[] keys, V[] values){
if (!mutable.get()) {
throw new IllegalStateException("Transient already frozen.");
}

final UpdateResult<K, V> ur = UpdateResult.unchanged();

for (int i = 0; i < keys.length; i++) {
K key = keys[i];
V val = values[i];

final int keyHash = key.hashCode();

final ChampNode<K, V> newRootNode = rootNode.update(mutable, key, val, keyHash, 0, ur);

if (ur.isModified()) {
if (ur.hasReplacedValue()) {
final V old = ur.getReplacedValue();

final int valHashOld = old.hashCode();
final int valHashNew = val.hashCode();

rootNode = newRootNode;
cachedHashCode = cachedHashCode + (keyHash ^ valHashNew) - (keyHash ^ valHashOld);
} else {
final int valHashNew = val.hashCode();
rootNode = newRootNode;
cachedHashCode += (keyHash ^ valHashNew);
cachedSize += 1;
}
ur.reset();
}
}

}

public void setAll(ChampMap<K, V> src) {

if (!mutable.get()) {
Expand Down

0 comments on commit fed5714

Please sign in to comment.