[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

m order b-tree

sngtnair84

7/19/2008 12:22:00 PM

Hello,

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

Thanks,
1 Answer

SHINDO Motoaki

7/22/2008 11:52:00 AM

0


On 2008/07/19, at 21:21, sngtnair84@gmail.com 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?

=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
<motoakira@mac.com>
=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