plugins/ruby/ruby-autogen-defs.rb
# do a binary search in an ordered vector for a specific target attribute
# ex: world.history.figures.binsearch(unit.hist_figure_id)
do a binary search in an ordered vector for a specific target attribute
ex: world.history.figures.binsearch(unit.hist_figure_id)
do a binary search in an ordered vector for a specific target attribute ex : world . history . figures . binsearch ( unit . hist_figure_id )
def binsearch(target, field=:id)
                o_start = 0
                o_end = length - 1
                while o_end >= o_start
                    o_half = o_start + (o_end-o_start)/2
                    obj = self[o_half]
                    oval = obj.send(field)
                    if oval == target
                        return obj
                    elsif oval < target
                        o_start = o_half+1
                    else
                        o_end = o_half-1
                    end
                end
            end
def binsearch ( target , field = :id ) o_start = 0 o_end = length - 1 while o_end >= o_start o_half = o_start + ( o_end - o_start ) / 2 obj = self [ o_half ] oval = obj . send ( field ) if oval == target return obj elsif oval < target o_start = o_half + 1 else o_end = o_half - 1 end end end
do a binary search in an ordered vector for a specific target attribute
ex: world.history.figures.binsearch(unit.hist_figure_id)
do a binary search in an ordered vector for a specific target attribute ex : world . history . figures . binsearch ( unit . hist_figure_id )
target
<not_specific>
field
<not_specific>