Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make children branch collections #80

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions lib/baes/actions/bisect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ def find_middle_branch(success_branch, fail_branch)
start_number = success_branch.number

child_branch =
success_branch.children.find do |next_child_branch|
next_child_branch.base_name == fail_branch.base_name
end

success_branch.children.find_by_base_name(fail_branch.base_name)
start_number ||= child_branch.number

middle_number = (start_number + end_number) / 2
Expand All @@ -63,9 +60,7 @@ def find_middle_branch(success_branch, fail_branch)

while next_branch.number < middle_number
next_branch =
next_branch.children.find do |next_child_branch|
next_child_branch.base_name == fail_branch.base_name
end
next_branch.children.find_by_base_name(fail_branch.base_name)
end

next_branch
Expand Down
2 changes: 1 addition & 1 deletion lib/baes/branch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(name)
_, base_name, number = name.match(/(\A[a-zA-Z_-]+)(\d+)$/).to_a
self.base_name = base_name || name
self.number = number && Integer(number, 10)
self.children = []
self.children = Baes::BranchCollection.new
end

# return an array for use as a hash key
Expand Down
20 changes: 20 additions & 0 deletions lib/baes/branch_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@ def find_by_name(name)
branches.find { |branch| branch.name == name }
end

# find a branch by base name
def find_by_base_name(base_name)
branches.find { |branch| branch.base_name == base_name }
end

# add a branch
def <<(branch)
branches << branch
end

# delete a branch if the block returns true
def delete_if(&block)
branches.delete_if(&block)
end

# iterate over each branch with object
def each_with_object(obj, &block)
branches.each_with_object(obj, &block)
Expand All @@ -39,6 +49,16 @@ def each(&block)
branches.each(&block)
end

# return true if there are no branches
def empty?
branches.empty?
end

# iterate over each branch and return the result
def map(&block)
branches.map(&block)
end

# return the first branch
def first
branches.first
Expand Down
Loading