def defragment_map(current_index: list, excluded={}) -> tuple:
    """Build new index without excluded slots (ie deleted objects)."""
    new_index = [{'o_num': 0, 'o_gen': 0, 'o_ver': 0, 'doc_ver': 0}]
    mapping = {}
    nb = 0
    for i, o in enumerate(current_index):
        if i == 0: #trailer
            continue
        if 'DELETED' in o or i in excluded:
            continue
        else:
            nb += 1
            old_ref = complex(o['o_gen'], o['o_num'])
            new_o = deepcopy(o)
            new_o['o_gen'] = 0
            new_o['o_ver'] = 0
            new_o['doc_ver'] = 0
            new_o['OLD_REF'] = old_ref
            if 'abs_pos' in new_o:
                del new_o['abs_pos']
            if 'abs_next' in new_o:
                del new_o['abs_next']
            new_index.append(new_o)
            new_ref = complex(0, nb) 
            if old_ref != new_ref:
                mapping[old_ref] = new_ref
    return new_index, mapping
Build new index without excluded slots (ie deleted objects).
pdfsyntax/docstruct.py