Пример #1
0
def copy_postings_list(L):
    if not L:
        return None

    # Stage 1: Makes a copy of the original list without assigning the jump
    #          field, and creates the mapping for each node in the original
    #          list to the copied list.
    it = L
    while it:
        new_node = PostingListNode(it.order, it.next, None)
        it.next = new_node
        it = new_node.next

    # Stage 2: Assigns the jump field in the copied list.
    it = L
    while it:
        if it.jump:
            it.next.jump = it.jump.next
        it = it.next.next

    # Stage 3: Reverts the original list, and assigns the next field of
    #          the copied list.
    it = L
    new_list_head = it.next
    while it.next:
        it.next, it = it.next.next, it.next
    return new_list_head
Пример #2
0
def copy_postings_list(L):
    if not L:
        return L

    it = L
    while it:
        copy = PostingListNode(it.order, it.next, it.jump)
        it.next = copy
        it = it.next.next
    copy_head = L.next

    u = L
    while u:
        if u.jump:
            u.next.jump = u.jump.next
        u = u.next.next
    # it = L
    # while it:
    #     copy = it.next
    #     if copy.jump:
    #         copy.jump = it.jump.next
    #     it = it.next.next

    it = L
    while it:
        it.next = it.next.next
        it = it.next

    return copy_head
Пример #3
0
    def create_posting_list(serialized):
        key_mapping = dict()
        head = None
        for (order, _) in reversed(serialized):
            head = PostingListNode(order, head)
            key_mapping[order] = head

        list_it = head
        for (_, jump_index) in serialized:
            if jump_index != -1:
                list_it.jump = key_mapping.get(jump_index, None)
                if not list_it.jump:
                    raise RuntimeError('Jump index out of range')

        return head