The question is pretty clear; I want to be able to check if the associative array contains the value that I am going to (potentially) insert before inserting it. Is there an easy way to do this without searching through dict.keys ? Maybe something like if (dict.contains(val)) ... ?
dict.keys
if (dict.contains(val)) ...
To check if a key is in an associative array, use the in operator:
in
string[int] aa; string* ps = 100 in aa; if(ps) { // 100 is a key in aa, ps is a pointer to the corresponding value } else { // 100 is not a key in aa }
To check if a value exists, you need to search through aa.values .
aa.values
if (!dict.get(key, null)) dict[key] = val;