Unset (delete) value at given JPath within given structure.

    For performance reasons this method is intentionally not written as
    recursive.

    :param str structure: data structure to be trimmed
    :param str jpath: JPath to be evaluated

def jpath_unset(structure, jpath):
    """
    Unset (delete) value at given JPath within given structure.

    For performance reasons this method is intentionally not written as
    recursive.

    :param str structure: data structure to be trimmed
    :param str jpath: JPath to be evaluated
    """
    chunks = jpath_parse_c(jpath)
    size = len(chunks) - 1

    # Current working node set.
    nodes_a = [structure]

    # Next iteration working node set.
    nodes_b = []

    # Process chunks in order, enumeration is used for detection of the last JPath chunk.
    for i, chnk in enumerate(chunks):
        # Process all currently active nodes.
        for node in nodes_a:
            key = chnk['n']

            if not isinstance(node, dict) and not isinstance(node, collections.Mapping):
                raise JPathException("Expected dict-like structure to drop node '{}'".format(chnk['p']))

            # Process indexed nodes.
            if 'i' in chnk:
                idx = chnk['i']

                # Skip nodes for non-existent keys.
                if not key in node:
                    continue
                if not isinstance(node[key], list) and not isinstance(node[key], collections.MutableSequence):
                    raise JPathException("Expected list-like object under structure key '{}'".format(key))

                # Detection of the last JPath chunk - node somewhere in the middle.
                if i != size:
                    # Attempt to access node at given index.
                    try:
                        # Handle '*' special index - append all nodes.
                        if str(idx) == '*':
                            nodes_b.extend(node[key])
                        else:
                            nodes_b.append(node[key][idx])
                    # IndexError: list index out of range
                    except (IndexError, TypeError):
                        continue

                # Detection of the last JPath chunk - node at the end.
                else:
                    # Attempt to delete value at given index.
                    try:
                        # Handle '*' special index - delete all nodes.
                        if str(idx) == '*':
                            del node[key]
                        else:
                            del node[key][idx]
                    # IndexError: list index out of range
                    except (IndexError, TypeError):
                        continue

            # Process unindexed nodes.
            else:
                # Detection of the last JPath chunk - node somewhere in the middle.
                if i != size:
                    # Skip nodes for non-existent keys.
                    if not key in node:
                        continue
                    if isinstance(node[key], list):
                        nodes_b.extend(node[key])
                        continue
                    if not isinstance(node[key], dict) and not isinstance(node[key], collections.Mapping):
                        raise JPathException("Expected dict-like object under structure key '{}'".format(key))
                    nodes_b.append(node[key])

                # Detection of the last JPath chunk - node at the end.
                else:
                    # Attempt to delete value at given index.
                    try:
                        del node[key]
                    # KeyError: key does not exist
                    except KeyError:
                        continue

        nodes_a = nodes_b
        nodes_b = []