Z3
Public Member Functions | Data Fields
AstMap Class Reference

Public Member Functions

def __init__ (self, m=None, ctx=None)
 
def __del__ (self)
 
def __len__ (self)
 
def __contains__ (self, key)
 
def __getitem__ (self, key)
 
def __setitem__ (self, k, v)
 
def __repr__ (self)
 
def erase (self, k)
 
def reset (self)
 
def keys (self)
 

Data Fields

 map
 
 ctx
 

Detailed Description

A mapping from ASTs to ASTs.

Definition at line 5119 of file z3py.py.

Constructor & Destructor Documentation

§ __init__()

def __init__ (   self,
  m = None,
  ctx = None 
)

Definition at line 5122 of file z3py.py.

5122  def __init__(self, m=None, ctx=None):
5123  self.map = None
5124  if m is None:
5125  self.ctx = _get_ctx(ctx)
5126  self.map = Z3_mk_ast_map(self.ctx.ref())
5127  else:
5128  self.map = m
5129  assert ctx is not None
5130  self.ctx = ctx
5131  Z3_ast_map_inc_ref(self.ctx.ref(), self.map)
5132 

§ __del__()

def __del__ (   self)

Definition at line 5133 of file z3py.py.

5133  def __del__(self):
5134  if self.map is not None and self.ctx.ref() is not None:
5135  Z3_ast_map_dec_ref(self.ctx.ref(), self.map)
5136 

Member Function Documentation

§ __contains__()

def __contains__ (   self,
  key 
)
Return `True` if the map contains key `key`.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x] = x + 1
>>> x in M
True
>>> x+1 in M
False

Definition at line 5150 of file z3py.py.

5150  def __contains__(self, key):
5151  """Return `True` if the map contains key `key`.
5152 
5153  >>> M = AstMap()
5154  >>> x = Int('x')
5155  >>> M[x] = x + 1
5156  >>> x in M
5157  True
5158  >>> x+1 in M
5159  False
5160  """
5161  return Z3_ast_map_contains(self.ctx.ref(), self.map, key.as_ast())
5162 

§ __getitem__()

def __getitem__ (   self,
  key 
)
Retrieve the value associated with key `key`.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x] = x + 1
>>> M[x]
x + 1

Definition at line 5163 of file z3py.py.

5163  def __getitem__(self, key):
5164  """Retrieve the value associated with key `key`.
5165 
5166  >>> M = AstMap()
5167  >>> x = Int('x')
5168  >>> M[x] = x + 1
5169  >>> M[x]
5170  x + 1
5171  """
5172  return _to_ast_ref(Z3_ast_map_find(self.ctx.ref(), self.map, key.as_ast()), self.ctx)
5173 

§ __len__()

def __len__ (   self)
Return the size of the map.

>>> M = AstMap()
>>> len(M)
0
>>> x = Int('x')
>>> M[x] = IntVal(1)
>>> len(M)
1

Definition at line 5137 of file z3py.py.

5137  def __len__(self):
5138  """Return the size of the map.
5139 
5140  >>> M = AstMap()
5141  >>> len(M)
5142  0
5143  >>> x = Int('x')
5144  >>> M[x] = IntVal(1)
5145  >>> len(M)
5146  1
5147  """
5148  return int(Z3_ast_map_size(self.ctx.ref(), self.map))
5149 

§ __repr__()

def __repr__ (   self)

Definition at line 5190 of file z3py.py.

5190  def __repr__(self):
5191  return Z3_ast_map_to_string(self.ctx.ref(), self.map)
5192 

§ __setitem__()

def __setitem__ (   self,
  k,
  v 
)
Add/Update key `k` with value `v`.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x] = x + 1
>>> len(M)
1
>>> M[x]
x + 1
>>> M[x] = IntVal(1)
>>> M[x]
1

Definition at line 5174 of file z3py.py.

5174  def __setitem__(self, k, v):
5175  """Add/Update key `k` with value `v`.
5176 
5177  >>> M = AstMap()
5178  >>> x = Int('x')
5179  >>> M[x] = x + 1
5180  >>> len(M)
5181  1
5182  >>> M[x]
5183  x + 1
5184  >>> M[x] = IntVal(1)
5185  >>> M[x]
5186  1
5187  """
5188  Z3_ast_map_insert(self.ctx.ref(), self.map, k.as_ast(), v.as_ast())
5189 

§ erase()

def erase (   self,
  k 
)
Remove the entry associated with key `k`.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x] = x + 1
>>> len(M)
1
>>> M.erase(x)
>>> len(M)
0

Definition at line 5193 of file z3py.py.

5193  def erase(self, k):
5194  """Remove the entry associated with key `k`.
5195 
5196  >>> M = AstMap()
5197  >>> x = Int('x')
5198  >>> M[x] = x + 1
5199  >>> len(M)
5200  1
5201  >>> M.erase(x)
5202  >>> len(M)
5203  0
5204  """
5205  Z3_ast_map_erase(self.ctx.ref(), self.map, k.as_ast())
5206 

§ keys()

def keys (   self)
Return an AstVector containing all keys in the map.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x]   = x + 1
>>> M[x+x] = IntVal(1)
>>> M.keys()
[x, x + x]

Definition at line 5222 of file z3py.py.

5222  def keys(self):
5223  """Return an AstVector containing all keys in the map.
5224 
5225  >>> M = AstMap()
5226  >>> x = Int('x')
5227  >>> M[x] = x + 1
5228  >>> M[x+x] = IntVal(1)
5229  >>> M.keys()
5230  [x, x + x]
5231  """
5232  return AstVector(Z3_ast_map_keys(self.ctx.ref(), self.map), self.ctx)
5233 

§ reset()

def reset (   self)
Remove all entries from the map.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x]   = x + 1
>>> M[x+x] = IntVal(1)
>>> len(M)
2
>>> M.reset()
>>> len(M)
0

Definition at line 5207 of file z3py.py.

5207  def reset(self):
5208  """Remove all entries from the map.
5209 
5210  >>> M = AstMap()
5211  >>> x = Int('x')
5212  >>> M[x] = x + 1
5213  >>> M[x+x] = IntVal(1)
5214  >>> len(M)
5215  2
5216  >>> M.reset()
5217  >>> len(M)
5218  0
5219  """
5220  Z3_ast_map_reset(self.ctx.ref(), self.map)
5221 

Field Documentation

§ ctx

ctx

§ map

map

Definition at line 5123 of file z3py.py.