# M order b-tree

**URL:** <https://www.ruby-forum.com/t/m-order-b-tree/143500>\
**Category:** Ruby\
**Created:** [July 19, 2008, 2:27pm UTC](https://www.ruby-forum.com/t/m-order-b-tree/143500 "2008-07-19T14:27:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 19, 2008, 2:27pm UTC](https://www.ruby-forum.com/t/m-order-b-tree/143500/1 "2008-07-19T14:27:27Z")

</div>

Hello,

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

Thanks,

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 22, 2008, 1:58pm UTC](https://www.ruby-forum.com/t/m-order-b-tree/143500/2 "2008-07-22T13:58:51Z")

</div>

On 2008/07/19, at 21:21, removed\_email\_address@domain.invalid 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
<removed_email_address@domain.invalid>

```

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