Fix comparisons in ATNConfigSet.__contains__ of Python targets.

The __contains__ method of ATNConfigSet used different hashing
function (hash) for indexing the config dictionary than the
getOrAdd method (hashCodeForConfigSet) which filled it.
Furthermore, they also used different methods for comparing
ATNConfig objects. The patch makes them consistent.
This commit is contained in:
Renata Hodovan 2016-08-09 22:41:59 +02:00
parent 47e268dfea
commit 543a069440
2 changed files with 12 additions and 4 deletions

View File

@ -195,9 +195,13 @@ class ATNConfigSet(object):
def __contains__(self, config):
if self.configLookup is None:
raise UnsupportedOperationException("This method is not implemented for readonly sets.")
h = hash(config)
h = config.hashCodeForConfigSet()
l = self.configLookup.get(h, None)
return l is not None and config in l
if l is not None:
for c in l:
if config.equalsForConfigSet(c):
return True
return False
def clear(self):
if self.readonly:

View File

@ -198,9 +198,13 @@ class ATNConfigSet(object):
def __contains__(self, config):
if self.configLookup is None:
raise UnsupportedOperationException("This method is not implemented for readonly sets.")
h = hash(config)
h = config.hashCodeForConfigSet()
l = self.configLookup.get(h, None)
return l is not None and config in l
if l is not None:
for c in l:
if config.equalsForConfigSet(c):
return True
return False
def clear(self):
if self.readonly: