by P3rv3rt B3ar on Thu Aug 03, 2006 6:53 pm
Well if we take for example music database... supercategory could be cat called "music", which contains albums, while subcat could be "musicdetails", which contains individual songs.
But thats just example, in general relation is supercat contains subcat and depth of subcat is one less than supercat.
Heres pseudo code for u:
count (catpath)
{
if (catpath is leaf) return 1
else
{
int lkm=0;
divide catpath to currentcat and restofcatpath
XpluginHelper.sendCommand("command:category:reset:"+currentcat);
while(!catwalk complete)
{
lkm+=count(restofcatpath)
walk to next item in currentcat;
}
return lkm
}
}
Definition of rest of terminology:
Catwalk: Moving in category using nextItem command. Catwalk is said to be complete when current cat has been walked trough.
CatPath: Expression to fully descripe a category. for example in above category structure example catpath to "musicdetails" cat would be "music>musicdetails".
Oh, and here leaf refers to ""-sentinel, or item actually, empty string in restofcatpath when theres no more subcategories left to enter.
That pseudo algorith is general. It can handle any depth (thanks to recursion) and any categories. Only limitation is that u have to have all categories mentioned on catpath, though these can be dummy categories, and u need a way to determinate when catwalk is complete, hence u need a keyfield, which has unique value. Both of these limitations exist in xPerT too cause this is how xPerTs catwalk algorithms are implemented.
Now if u want to count all your songs and your music database structure is as mentioned abowe u use count with catpath "music>musicdetails"
and if u want to count how many songs particular album has, u have to first catwalk to that particular album and then call count with catpath "musicdetails".