@@ -88,7 +88,9 @@ vector<command> program;
88
88
// vector of the indices. Plain variables are stored using an index
89
89
// vector of zero length.
90
90
typedef map<vector<mpz_class>,value_t > indexmap;
91
+ typedef map<value_t ,set<vector<mpz_class>>> valuemap;
91
92
map<string,indexmap> variable, preset;
93
+ map<string,valuemap> rev_variable, rev_preset;
92
94
93
95
// List of loop starting commands like REP, initialized in checksyntax.
94
96
set<string> loop_cmds;
@@ -276,11 +278,20 @@ void setvar(expr var, value_t val, int use_preset = 0)
276
278
ind.push_back (mpz_class (eval (var.args [i])));
277
279
}
278
280
281
+ map<string,indexmap> *varlist = &variable;
282
+ map<string,valuemap> *revlist = &rev_variable;
279
283
if ( use_preset ) {
280
- preset[var][ind] = val;
281
- } else {
282
- variable[var][ind] = val;
284
+ varlist = &preset;
285
+ revlist = &rev_preset;
286
+ }
287
+
288
+ // Remove previously existing value -> index:
289
+ if ( (*varlist)[var].count (ind) ) {
290
+ (*revlist)[var][val].erase (ind);
291
+ if ( (*revlist)[var][val].size ()==0 ) (*revlist)[var].erase (val);
283
292
}
293
+ (*varlist)[var][ind] = val;
294
+ (*revlist)[var][val].insert (ind);
284
295
}
285
296
286
297
void setvars (vector<parse_t > varlist, int use_preset = 0 )
@@ -294,6 +305,7 @@ void unsetvars(args_t varlist)
294
305
{
295
306
for (size_t i=0 ; i<varlist.size (); i++) {
296
307
variable.erase (varlist[i].val );
308
+ rev_variable.erase (varlist[i].val );
297
309
}
298
310
}
299
311
@@ -578,10 +590,7 @@ bool inarray(expr e, expr array)
578
590
exit (exit_failure);
579
591
}
580
592
581
- for (indexmap::iterator it=variable[var].begin (); it!=variable[var].end (); ++it) {
582
- if ( it->second ==val ) return true ;
583
- }
584
- return false ;
593
+ return rev_variable[var].count (val) && rev_variable[var][val].size ()>0 ;
585
594
}
586
595
587
596
bool dotest (test t)
0 commit comments