Skip to content

Subnet inserts #2

@FynnMazurkiewicz

Description

@FynnMazurkiewicz

Hey, thanks for this great package. I made an adaption to add subnet inserts, instead of passing them. Inserts always overwrite the previous data record. The guts is a change on gts_merger/writer.py:458

            previous_node = None
            supernet_leaf = None  # Tracks whether we are inserting into a subnet
            for (index, ip_bit) in enumerate(bits[:-1]):
                previous_node = current_node
                current_node = previous_node.get_or_create(ip_bit)
                next_bit = bits[index + 1]

                if isinstance(current_node, SearchTreeLeaf):
                    logger.info(f"Inserting {cidr} into subnet of {current_node.value['network']}")
                    supernet_leaf = current_node
                    current_node = SearchTreeNode()
                    previous_node[ip_bit] = current_node

                if supernet_leaf:
                    # Insert supernet information on each inverse bit of the current subnet
                    current_node[1 - next_bit] = supernet_leaf

Are you interested to add this to your package? Then I will test it with your examples. I also added sibling-merging, so I'd need to clean my code first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions