Merge pull request #1248 from renatahodovan/configset-contains

Fix comparisons in ATNConfigSet.__contains__ of Python targets.
This commit is contained in:
Terence Parr 2016-11-21 10:08:51 -08:00 committed by GitHub
commit 37ff8a3161
2 changed files with 12 additions and 4 deletions

View File

@ -186,9 +186,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

@ -189,9 +189,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: