def split_node
      unless @parent
        # The node is the root node. We need to create a parent node first.
        self.parent = @store.new(BigArrayNode, @tree, false)
        @parent.offsets[0] = 0
        @parent.children[0] = myself
        @tree.root = @parent
      end

      # Create the new sibling that will take the 2nd half of the
      # node content.
      sibling = @store.new(BigArrayNode, @tree, is_leaf?, @parent, myself,
                           @next_sibling)
      # Determine the index of the middle element that gets moved to the
      # parent. The node size must be an uneven number.
      mid = size / 2
      if is_leaf?
        # Before:
        #    +--------------------------+
        #    | 0         4         7    |
        #      |         |         |
        #      v         v         v
        # +---------++-------++----------+
        # | A B C D || E F G || H I J K  |
        #
        # After:
        #    +--------------------------+
        #    | 0    2       4         7 |
        #      |    |       |         |
        #      v    v       v         v
        # +-----++----++-------++----------+
        # | A B || C D || E F G || H I J K  |
        #
        #
        # Insert the middle element key into the parent node
        @parent.insert_child_after_peer(mid, sibling, self)
        # Copy the values from the mid element onwards into the new
        # sibling node.
        sibling.values += @values[mid..-1]
        # Delete the copied offsets and values from this node.
        @values.slice!(mid..-1)
      else
        # Before:
        #    +--------------+
        #    | 0         11 |
        #      |          |
        #      v          v
        # +----------++-------+
        # | 0 4 7 10 || 0 2 5 |
        #   | | | |     | | |
        #   v v v v     v v v
        #
        # After:
        #  +------------------+
        #  | 0      7      11 |
        #    |      |       |
        #    v      v       v
        # +-----++-----++-------+
        # | 0 4    0 3 || 0 2 5 |
        #   | |    | |    | | |
        #   v v    v v    v v v
        #
        # Insert the new sibling into the parent node.
        offset_delta = @offsets[mid]
        @parent.insert_child_after_peer(offset_delta, sibling, self)
        # Copy the offsets from after the mid value onwards to the new sibling
        # node. We substract the offset delta from each of them.
        sibling.offsets += @offsets[mid..-1].map{ |v| v - offset_delta }
        # Delete the copied offsets from this node.
        @offsets.slice!(mid..-1)
        # Same copy for the children.
        sibling.children += @children[mid..-1]
        # Reparent the children to the new sibling parent.
        sibling.children.each { |c| c.parent = sibling }
        # And delete the copied children references.
        @children.slice!(mid..-1)
      end

      @parent
    end
def split_node
      unless @parent
        # The node is the root node. We need to create a parent node first.
        self.parent = @store.new(BigArrayNode, @tree, false)
        @parent.offsets[0] = 0
        @parent.children[0] = myself
        @tree.root = @parent
      end

      # Create the new sibling that will take the 2nd half of the
      # node content.
      sibling = @store.new(BigArrayNode, @tree, is_leaf?, @parent, myself,
                           @next_sibling)
      # Determine the index of the middle element that gets moved to the
      # parent. The node size must be an uneven number.
      mid = size / 2
      if is_leaf?
        # Before:
        #    +--------------------------+
        #    | 0         4         7    |
        #      |         |         |
        #      v         v         v
        # +---------++-------++----------+
        # | A B C D || E F G || H I J K  |
        #
        # After:
        #    +--------------------------+
        #    | 0    2       4         7 |
        #      |    |       |         |
        #      v    v       v         v
        # +-----++----++-------++----------+
        # | A B || C D || E F G || H I J K  |
        #
        #
        # Insert the middle element key into the parent node
        @parent.insert_child_after_peer(mid, sibling, self)
        # Copy the values from the mid element onwards into the new
        # sibling node.
        sibling.values += @values[mid..-1]
        # Delete the copied offsets and values from this node.
        @values.slice!(mid..-1)
      else
        # Before:
        #    +--------------+
        #    | 0         11 |
        #      |          |
        #      v          v
        # +----------++-------+
        # | 0 4 7 10 || 0 2 5 |
        #   | | | |     | | |
        #   v v v v     v v v
        #
        # After:
        #  +------------------+
        #  | 0      7      11 |
        #    |      |       |
        #    v      v       v
        # +-----++-----++-------+
        # | 0 4    0 3 || 0 2 5 |
        #   | |    | |    | | |
        #   v v    v v    v v v
        #
        # Insert the new sibling into the parent node.
        offset_delta = @offsets[mid]
        @parent.insert_child_after_peer(offset_delta, sibling, self)
        # Copy the offsets from after the mid value onwards to the new sibling
        # node. We substract the offset delta from each of them.
        sibling.offsets += @offsets[mid..-1].map{ |v| v - offset_delta }
        # Delete the copied offsets from this node.
        @offsets.slice!(mid..-1)
        # Same copy for the children.
        sibling.children += @children[mid..-1]
        # Reparent the children to the new sibling parent.
        sibling.children.each { |c| c.parent = sibling }
        # And delete the copied children references.
        @children.slice!(mid..-1)
      end

      @parent
    end
Split the current node into two nodes. The upper half of the elements
 will be moved into a newly created node. This node will retain the lower
 half.
 @return [BigArrayNode] common parent of the two nodes