Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate map.addOrSet in favor of map.addOrReplace #22733

Merged
merged 5 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/packages/ArgumentParser.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ module ArgumentParser {
proc _setArguments(argStack: map(string, ArgumentHandler)) {
_argStack = new map(string, borrowed ArgumentHandler);
for k in argStack.keys() {
_argStack.addOrSet(k,try! argStack[k] );
_argStack.addOrReplace(k,try! argStack[k] );
}
generateSections();
}
Expand Down
4 changes: 2 additions & 2 deletions modules/packages/ConcurrentMap.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ module ConcurrentMap {
set it to `v`. If the map already contains a value at position
`k`, update it to the value `v`.
*/
proc addOrSet(key: keyType, val: valType, tok : owned TokenWrapper = getToken()) throws {
proc addOrReplace(key: keyType, val: valType, tok : owned TokenWrapper = getToken()) throws {
tok.pin();
var elist = getEList(key, true, tok);
for i in 0..#elist!.count {
Expand All @@ -853,7 +853,7 @@ module ConcurrentMap {
*/
proc extend(m : ConcurrentMap(keyType, valType)) throws {
forall (key, value) in m with (var tok = getToken()) {
addOrSet(key, value, tok);
addOrReplace(key, value, tok);
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/packages/SortedMap.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ module SortedMap {
set it to `v`. If the sortedMap already contains a value at position
`k`, update it to the value `v`.
*/
proc addOrSet(in k: keyType, in v: valType) {
proc addOrReplace(in k: keyType, in v: valType) {
_enter(); defer _leave();
_set.remove((k, nil));
_set.add((k, new shared _valueWrapper(v)?));
Expand Down
12 changes: 6 additions & 6 deletions modules/packages/UnitTest.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -1168,12 +1168,12 @@ module UnitTest {

for test in testSuite {
const testName = test: string;
testStatus.addOrSet(testName, false);
testsFailed.addOrSet(testName, false);
testsErrored.addOrSet(testName, false);
testsLocalFails.addOrSet(testName, false);
testsPassed.addOrSet(testName, false);
testsSkipped.addOrSet(testName, false);
testStatus.addOrReplace(testName, false);
testsFailed.addOrReplace(testName, false);
testsErrored.addOrReplace(testName, false);
testsLocalFails.addOrReplace(testName, false);
testsPassed.addOrReplace(testName, false);
testsSkipped.addOrReplace(testName, false);
}
if testNames != "None" {
for test in testNames.split(" ") {
Expand Down
7 changes: 6 additions & 1 deletion modules/standard/Map.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,16 @@ module Map {
set it to `v`. If the map already contains a value at position
`k`, update it to the value `v`.
*/
proc addOrSet(in k: keyType, in v: valType) {
proc addOrReplace(in k: keyType, in v: valType) {
_enter(); defer _leave();
var (found, slot) = table.findAvailableSlot(k);
table.fillSlot(slot, k, v);
}

@deprecated(notes="'map.addOrSet' is deprecated. Please use 'map.addOrReplace' instead.")
proc addOrSet(in k: keyType, in v: valType) {
addOrReplace(k, v);
}

/*
Removes the key `k` and its value from the map. If the key `k`
Expand Down
2 changes: 1 addition & 1 deletion test/classes/weakPointers/passiveCache.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PassiveCache {
proc buildAndSave(key: int) : shared dataType {
const item = new shared dataType(key);
const weak_ptr = new weak(item);
this.items.addOrSet(key, weak_ptr);
this.items.addOrReplace(key, weak_ptr);
return item;
}
}
Expand Down
14 changes: 14 additions & 0 deletions test/deprecated/Map/testAddOrSet.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use Map;

class C {
var a: int;
}

var m: map(int, shared C);

var a = new shared C(1);

m.addOrSet(1, a);
m.addOrSet(2, m.getAndRemove(1));

writeln(m);
3 changes: 3 additions & 0 deletions test/deprecated/Map/testAddOrSet.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testAddOrSet.chpl:11: warning: 'map.addOrSet' is deprecated. Please use 'map.addOrReplace' instead.
testAddOrSet.chpl:12: warning: 'map.addOrSet' is deprecated. Please use 'map.addOrReplace' instead.
{2: {a = 1}}
2 changes: 1 addition & 1 deletion test/library/draft/DistributedMap/use-distributed-map.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ do
agg.add(s);

// independent of the above: test updateManager by itself
reference.addOrSet("1234", 1_000_000);
reference.addOrReplace("1234", 1_000_000);
manage dm2.updateManager("1234") as element do
element = 1_000_000;
assert(dm2.contains("1234"));
Expand Down
6 changes: 3 additions & 3 deletions test/library/draft/DistributedMap/v2/DistributedMap.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ module DistributedMap {
ch._readLiteral(": ");
ch.read(val);

this.addOrSetUnlocked(key, val);
this.addOrReplaceUnlocked(key, val);
}

ch._readLiteral("}");
Expand Down Expand Up @@ -612,7 +612,7 @@ module DistributedMap {
set it to `v`. If the map already contains a value at position
`k`, update it to the value `v`.
*/
proc addOrSet(in k: keyType, in v: valType) {
proc addOrReplace(in k: keyType, in v: valType) {
var loc: int = this.getLocaleForKey(k);

on loc {
Expand All @@ -629,7 +629,7 @@ module DistributedMap {
// only be used when you know you control the accesses to the map and will
// be managing race conditions yourself
@chpldoc.nodoc
proc addOrSetUnlocked(in k: keyType, in v: valType) {
proc addOrReplaceUnlocked(in k: keyType, in v: valType) {
var loc: int = this.getLocaleForKey(k);

on loc {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use DistributedMap;

var m = new distributedMap(int, int);

m.addOrSet(3, 17);
m.addOrReplace(3, 17);
m.add(11, 2);
writeln(m.contains(3)); // should be true
writeln(m.contains(11)); // should be true
m.addOrSet(11, -4);
m.addOrReplace(11, -4);
writeln(m.contains(11)); // should still be true
writeln(m.contains(3)); // should be true

Expand Down
2 changes: 1 addition & 1 deletion test/library/draft/DistributedMap/v3/DistributedMap.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ module DistributedMap {
return ret;
}

proc addOrSet(in k: keyType, in v: valType) {
proc addOrReplace(in k: keyType, in v: valType) {
const loc = this._localeFor(k);
on loc {
this.locks[loc.id].lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use SortedMap;

var m = new sortedMap(int, int, false, defaultComparator);
for i in 1..10 {
m.addOrSet(i, i);
m.addOrReplace(i, i);
}

for i in 1..10 {
assert(m[i] == i);
m.addOrSet(i, i+1);
m.addOrReplace(i, i+1);
assert(m[i] == i+1);
}
4 changes: 2 additions & 2 deletions test/library/standard/Map/testAddRemoved.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var m: map(int, shared C);

var a = new shared C(1);

m.addOrSet(1, a);
m.addOrSet(2, m.getAndRemove(1));
m.addOrReplace(1, a);
m.addOrReplace(2, m.getAndRemove(1));

writeln(m);
Loading