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?
=3D=3D=3D source follows (contains Kanji, see it in UTF-8)
class CommentTree
def initialize(root)
@root =3D root
@last =3D root
@changed =3D false
end
def root
@root
end
alias top root
def changed?
@changed
end
def clear
@changed =3D false
=3Dbegin
as some trivial work-around, this method is here
=3Dend
end
def seek(id)
@root.seek(id)
end
=09
def put(node)
parent =3D seek(node.parent_num)
if parent.nil? then nil
else
parent.put(node)
@last =3D node
@changed =3D true
parent
end
end
=09
def remove(id, note)
ruin =3D nil
node =3D seek(id)
if node.nil?
else
ruin =3D node.emptize(note)
@changed =3D true
end
ruin
end
=09
def each(&block)
@root.each &block
end
def overview
print '=C3=82=C2=A5n'
@root.each { |node|
print '=C3=82=C2=A5n'
node.generation.times {print '=C3=82=C2=A5t'}
print node.id
}
print '=C3=82=C2=A5n'
end
def entry(node)
line =3D""
node.generation.times {line +=3D "—"}
line +=3D node.entry
line +=3D "<br>=C3=82=C2=A5n"
end
def entries(cgi)
lines =3D ""
each { |node|
lines +=3D cgi.a({"href" =3D> =
"./article.cgi?cueto=3D#{node.id}",
"target" =3D> "Article"}) { =
entry(node) }
}
cgi.p { lines }
end
=09
=3Dbegin=09
These methods are of imaginations, but I won't implement 'em
def next(node)
end
def prev(node)
end=09
=09
def car
end
def cdr
end
=09
def subtree(generation)
end
=09
def leaf(serial)
end
def leaves
end
=3Dend
end
=3D=3D=3D source ends
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
ContextSwitcher
Shindo Motoakira
<
[email protected]>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D