M order b-tree

Hello,

I need a ruby implementation of m-order B-tree, where m > 2.
Is anyone aware of an already existing implementation?

Thanks,

On 2008/07/19, at 21:21, [email protected] wrote:

I need a ruby implementation of m-order B-tree, where m > 2.

I don’t get you got some reply, so
I put my experimental code. would it work for you?

Yes(or Nope),
it’s not the Tree of its children is the Tree-itself, but
is it your STRICT Requirements?

=== source follows (contains Kanji, see it in UTF-8)

class CommentTree

def initialize(root)
@root = root
@last = root
@changed = false
end

def root
@root
end
alias top root
def changed?
@changed
end
def clear
@changed = false
=begin
as some trivial work-around, this method is here
=end
end
def seek(id)
@root.seek(id)
end

def put(node)
parent = seek(node.parent_num)
if parent.nil? then nil
else
parent.put(node)
@last = node
@changed = true
parent
end
end

def remove(id, note)
ruin = nil
node = seek(id)
if node.nil?
else
ruin = node.emptize(note)
@changed = true
end
ruin
end

def each(&block)
@root.each &block
end
def overview
print ‘Â¥n’
@root.each { |node|
print ‘Â¥n’
node.generation.times {print ‘Â¥t’}
print node.id
}
print ‘Â¥n’
end

def entry(node)
line =""
node.generation.times {line += “—”}
line += node.entry
line += “
Â¥n”
end
def entries(cgi)
lines = “”
each { |node|
lines += cgi.a({“href” => “./article.cgi?cueto=#{node.id}”,
“target” => “Article”}) { entry(node) }
}
cgi.p { lines }
end

=begin
These methods are of imaginations, but I won’t implement 'em
def next(node)
end
def prev(node)
end

def car
end
def cdr
end

def subtree(generation)
end

def leaf(serial)
end
def leaves
end
=end
end

=== source ends

=============================
ContextSwitcher

     Shindo  Motoakira
<[email protected]>

=============================

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs