lib/jumoku/builders/shared.rb
# Removes a branch from the tree.
#
# You cannot remove non terminal branches as it would break
# the connectivity constraint of the tree.
#
# I may add an option which would allow to force removal
# of internal nodes and return two new trees from this
# destructive operation.
#
# @overload remove_branch!(i, j)
#   @param [node] i
#   @param [node] j
# @overload remove_branch!(b)
#   @param [Branch] b
# @return [RawTree] self
Removes a branch from the tree.
You cannot remove non terminal branches as it would break
the connectivity constraint of the tree.

I may add an option which would allow to force removal
of internal nodes and return two new trees from this
destructive operation.
Removes a branch from the tree . You cannot remove non terminal branches as it would break the connectivity constraint of the tree . I may add an option which would allow to force removal of internal nodes and return two new trees from this destructive operation .
def remove_branch! u, v = nil
      if u.is_a? _branch_type
        v = u.target
        u = u.source
      end
      if has_node? u and has_node? v
        if terminal? u and terminal? v
          remove_edge! u, v
          if [u, v].all? { |node| nodes.include? node } and nodes.size == 2
            remove_node! u, true
            remove_node! v, true
          end
        elsif terminal? u and not terminal? v
          remove_node! u
        elsif terminal? v and not terminal? u
          remove_node! v
        else
          raise RawTreeError, "Can't remove a non terminal branch in a tree."
        end
      else
        raise RawTreeError, "Can't remove a branch which does not exist."
      end
    end
def remove_branch! u , v = nil if u . is_a? _branch_type v = u . target u = u . source end if has_node? u and has_node? v if terminal? u and terminal? v remove_edge! u , v if [ u , v ] . all? { | node | nodes . include? node } and nodes . size == 2 remove_node! u , true remove_node! v , true end elsif terminal? u and not terminal? v remove_node! u elsif terminal? v and not terminal? u remove_node! v else raise RawTreeError , "Can't remove a non terminal branch in a tree." end else raise RawTreeError , "Can't remove a branch which does not exist." end end
Removes a branch from the tree.
Removes a branch from the tree .
# empty the tree if u and v are the last two nodes, for they're # not connected anymore
None
RawTree
u
<not_specific>
v
<not_specific>
overload
remove_branch!(i, j) @param [node] i @param [node] j
remove_branch! ( i j ) @param [ node ] i @param [ node ] j
overload
remove_branch!(b) @param [Branch] b
remove_branch! ( b ) @param [ Branch ] b