class_docstr: A set of rewrite rules.
  
  Forms a structure for fast rewriting over a set of rewrite rules. This
  allows for syntactic matching of terms to patterns for many patterns at
  the same time.
  
  Examples
  --------
  
  >>> import dask.rewrite as dr
  >>> def f(*args): pass
  >>> def g(*args): pass
  >>> def h(*args): pass
  >>> from operator import add
  
  >>> rs = dr.RuleSet(
  ...         dr.RewriteRule((add, 'x', 0), 'x', ('x',)),
  ...         dr.RewriteRule((f, (g, 'x'), 'y'),
  ...                        (h, 'x', 'y'),
  ...                        ('x', 'y')))
  
  >>> rs.rewrite((add, 2, 0))
  2
  
  >>> rs.rewrite((f, (g, 'a', 3)))    # doctest: +ELLIPSIS
  (<function h at ...>, 'a', 3)
  
  >>> dsk = {'a': (add, 2, 0),
  ...        'b': (f, (g, 'a', 3))}
  
  >>> from toolz import valmap
  >>> valmap(rs.rewrite, dsk)         # doctest: +ELLIPSIS
  {'a': 2, 'b': (<function h at ...>, 'a', 3)}
  
  Attributes
  ----------
  rules : list
      A list of `RewriteRule`s included in the `RuleSet`.
class_docstr_tok: ["A","set","of","rewrite","rules",".","Forms","a","structure","for","fast","rewriting","over","a","set","of","rewrite","rules",".","This","allows","for","syntactic","matching","of","terms","to","patterns","for","many","patterns","at","the","same","time",".","Examples","--","--","--","--",">",">",">","import","dask.rewrite","as","dr",">",">",">","def","f","(","*","args",")",":","pass",">",">",">","def","g","(","*","args",")",":","pass",">",">",">","def","h","(","*","args",")",":","pass",">",">",">","from","operator","import","add",">",">",">","rs","=","dr.RuleSet","(","...","dr.RewriteRule","(","(","add",",","'","x","'",",","0",")",",","'","x","'",",","(","'","x","'",",",")",")",",","...","dr.RewriteRule","(","(","f",",","(","g",",","'","x","'",")",",","'","y","'",")",",","...","(","h",",","'","x","'",",","'","y","'",")",",","...","(","'","x","'",",","'","y","'",")",")",")",">",">",">","rs.rewrite","(","(","add",",","2",",","0",")",")","2",">",">",">","rs.rewrite","(","(","f",",","(","g",",","'","a","'",",","3",")",")",")","#","doctest",":","+ELLIPSIS","(","<","function","h","at","...",">",",","'","a","'",",","3",")",">",">",">","dsk","=","{","'","a","'",":","(","add",",","2",",","0",")",",","...","'","b","'",":","(","f",",","(","g",",","'","a","'",",","3",")",")","}",">",">",">","from","toolz","import","valmap",">",">",">","valmap","(","rs.rewrite",",","dsk",")","#","doctest",":","+ELLIPSIS","{","'","a","'",":","2",",","'","b","'",":","(","<","function","h","at","...",">",",","'","a","'",",","3",")","}","Attributes","--","--","--","--","--","rules",":","list","A","list","of","`","RewriteRule","`","s","included","in","the","`","RuleSet","`","."]
docstr: Add a rule to the RuleSet.
  
  Parameters
  ----------
  rule : RewriteRule
docstr_tok: ["Add","a","rule","to","the","RuleSet",".","Parameters","--","--","--","--","--","rule",":","RewriteRule"]
code: def add(self, rule):
      """Add a rule to the RuleSet.
  
      Parameters
      ----------
      rule : RewriteRule
      """
  
      if not isinstance(rule, RewriteRule):
          raise TypeError("rule must be instance of RewriteRule")
      vars = rule.vars
      curr_node = self._net
      ind = len(self.rules)
      # List of variables, in order they appear in the POT of the term
      for t in Traverser(rule.lhs):
          prev_node = curr_node
          if t in vars:
              t = VAR
          if t in curr_node.edges:
              curr_node = curr_node.edges[t]
          else:
              curr_node.edges[t] = Node()
              curr_node = curr_node.edges[t]
      # We've reached a leaf node. Add the term index to this leaf.
      prev_node.edges[t].patterns.append(ind)
      self.rules.append(rule)
  
imports: from __future__ import annotations
  from collections import deque
  from dask.core import istask, subs
label_desc: Use image node_id 2 for calling the RuleSet obj's underlying member method code with example usage: obj.add(rule) without return types