Arbortext Command Language > Functions by Alphabetical Listing > oid_level
  
oid_level
oid_level (oid1, oid2)
This function returns the number of levels of ancestry between the elements specified by oid1 and oid2 or 0 if the elements are not related, that is, neither OID contains the other. If oid1 contains oid2, then the level number is positive. If oid2 contains oid1, then the level number is negative.
Examples
This function could be written using oid_parent as follows:
function oid_level(o1, o2)
{
local i, p, o
if (o1 == o2) { return 0;}
if (o1 < o2) {
o = o1
p = oid_parent(o2)
} else {
o = o2
p = oid_parent(o1)
}
# walk up parent tree until o is found
for (i = 0; oid_valid(p); ) {
i++;
if (p == o)
{ return o == o1 ? i : -i;}
p = oid_parent(p)
}
return 0; # not related
}
Related Topics
oid_parent function