Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Nested set tricks

pripple edited this page Apr 24, 2012 · 3 revisions

(Please add to this page)

Check how many descendents node i has:

For every descendent that i has, two numbers will be required (left (lft) boundary and right (rgt) boundary). Therefore the number of descendents of a node will be half of the difference between its boundaries.

   x = (i.rgt-i.lft)/2

There seems to be an instance method for doing exactly that: (see lib/nested_set/descendants.rb)

i.descendants_count