'Add a node to the sort input.  The ``name`` should be a string or
any other hashable object, the ``val`` should be the sortable (doesn\'t
need to be hashable).  ``after`` and ``before`` represents the name of
one of the other sortables (or a sequence of such named) or one of the
special sentinel values :attr:`pyramid.util.FIRST`` or
:attr:`pyramid.util.LAST` representing the first or last positions
respectively.  ``FIRST`` and ``LAST`` can also be part of a sequence
passed as ``before`` or ``after``.  A sortable should not be added
after LAST or before FIRST.  An example::
sorter = TopologicalSorter()
sorter.add(\'a\', {\'a\':1}, before=LAST, after=\'b\')
sorter.add(\'b\', {\'b\':2}, before=LAST, after=\'c\')
sorter.add(\'c\', {\'c\':3})
sorter.sorted() # will be {\'c\':3}, {\'b\':2}, {\'a\':1}'

def add(self, name, val, after=None, before=None):

    if (name in self.names):
        self.remove(name)
    self.names.append(name)
    self.name2val[name] = val
    if ((after is None) and (before is None)):
        before = self.default_before
        after = self.default_after
    if (after is not None):
        if (not is_nonstr_iter(after)):
            after = (after,)
        self.name2after[name] = after
        self.order += [(u, name) for u in after]
        self.req_after.add(name)
    if (before is not None):
        if (not is_nonstr_iter(before)):
            before = (before,)
        self.name2before[name] = before
        self.order += [(name, o) for o in before]
        self.req_before.add(name)
