'Splits full node in two separate ones, first half of records stays on old position,
second half is written as new leaf at the end of file.'

def _split_node(self, node_start, nr_of_keys_to_rewrite, new_key, new_pointer, children_flag, create_new_root=False):

    half_size = (self.node_capacity / 2)
    if ((self.node_capacity % 2) == 0):
        old_node_size = new_node_size = half_size
    else:
        old_node_size = half_size
        new_node_size = (half_size + 1)
    if create_new_root:
        self._create_new_root_from_node(node_start, children_flag, nr_of_keys_to_rewrite, new_node_size, old_node_size, new_key, new_pointer)
    else:
        blanks = (((self.node_capacity - new_node_size) * (self.key_size + self.pointer_size)) * '\x00')
        if (nr_of_keys_to_rewrite == new_node_size):
            self.buckets.seek((self._calculate_key_position(node_start, old_node_size, 'n') + self.pointer_size))
            data = self.buckets.read((nr_of_keys_to_rewrite * (self.key_size + self.pointer_size)))
            old_node_data = struct.unpack(('<' + (nr_of_keys_to_rewrite * (self.key_format + self.pointer_format))), data)
            self.buckets.seek(0, 2)
            new_node_start = self.buckets.tell()
            new_node = struct.pack(((('<' + self.node_heading_format) + self.pointer_format) + ((self.key_format + self.pointer_format) * new_node_size)), new_node_size, children_flag, new_pointer, *old_node_data)
            new_node += blanks
            self.buckets.write(new_node)
            self._update_size(node_start, old_node_size)
            self._read_single_node_key.delete(node_start)
            self._read_node_nr_of_elements_and_children_flag.delete(node_start)
            return (new_node_start, new_key)
        elif (nr_of_keys_to_rewrite > half_size):
            self.buckets.seek((self._calculate_key_position(node_start, (self.node_capacity - nr_of_keys_to_rewrite), 'n') + self.pointer_size))
            data = self.buckets.read((nr_of_keys_to_rewrite * (self.key_size + self.pointer_size)))
            old_node_data = struct.unpack(('<' + (nr_of_keys_to_rewrite * (self.key_format + self.pointer_format))), data)
            key_moved_to_parent_node = old_node_data[((- (new_node_size + 1)) * 2)]
            self.buckets.seek(0, 2)
            new_node_start = self.buckets.tell()
            new_node = struct.pack(((('<' + self.node_heading_format) + self.pointer_format) + ((self.key_format + self.pointer_format) * new_node_size)), new_node_size, children_flag, old_node_data[(((- new_node_size) * 2) - 1)], *old_node_data[((- new_node_size) * 2):])
            new_node += blanks
            self.buckets.write(new_node)
            self._update_size(node_start, old_node_size)
            self.buckets.seek((self._calculate_key_position(node_start, (self.node_capacity - nr_of_keys_to_rewrite), 'n') + self.pointer_size))
            self.buckets.write(struct.pack(('<' + ((self.key_format + self.pointer_format) * (nr_of_keys_to_rewrite - new_node_size))), new_key, new_pointer, *old_node_data[:((- (new_node_size + 1)) * 2)]))
            self._read_single_node_key.delete(node_start)
            self._read_node_nr_of_elements_and_children_flag.delete(node_start)
            return (new_node_start, key_moved_to_parent_node)
        else:
            self.buckets.seek((self._calculate_key_position(node_start, old_node_size, 'n') + self.pointer_size))
            data = self.buckets.read((new_node_size * (self.key_size + self.pointer_size)))
            old_node_data = struct.unpack(('<' + (new_node_size * (self.key_format + self.pointer_format))), data)
            key_moved_to_parent_node = old_node_data[0]
            self.buckets.seek(0, 2)
            new_node_start = self.buckets.tell()
            index_of_records_split = (nr_of_keys_to_rewrite * 2)
            first_leaf_pointer = old_node_data[1]
            old_node_data = old_node_data[2:]
            if index_of_records_split:
                keys_before = old_node_data[:(- index_of_records_split)]
                keys_after = old_node_data[(- index_of_records_split):]
            else:
                keys_before = old_node_data
                keys_after = []
            new_node = struct.pack(((('<' + self.node_heading_format) + self.pointer_format) + ((self.key_format + self.pointer_format) * ((new_node_size - nr_of_keys_to_rewrite) - 1))), new_node_size, children_flag, first_leaf_pointer, *keys_before)
            new_node += struct.pack(('<' + ((self.key_format + self.pointer_format) * (nr_of_keys_to_rewrite + 1))), new_key, new_pointer, *keys_after)
            new_node += blanks
            self.buckets.write(new_node)
            self._update_size(node_start, old_node_size)
            self._read_single_node_key.delete(node_start)
            self._read_node_nr_of_elements_and_children_flag.delete(node_start)
            return (new_node_start, key_moved_to_parent_node)
