static int traverseForward(StorageImpl db, int pageId, int type, int height, 
                               Object[] result, int pos)
    {
        Page pg = db.getPage(pageId);
        int oid;
        try { 
            int i, n = getnItems(pg);
            if (--height != 0) {
                if (type == ClassDescriptor.tpString || type == ClassDescriptor.tpArrayOfByte) { // page of strings
                    for (i = 0; i <= n; i++) { 
                        pos = traverseForward(db, getKeyStrOid(pg, i), type, height, result, pos);
                    }
                } else { 
                    for (i = 0; i <= n; i++) { 
                        pos = traverseForward(db, getReference(pg, maxItems-i-1), type, height, result, pos);
                    }
                }
            } else { 
                if (type == ClassDescriptor.tpString || type == ClassDescriptor.tpArrayOfByte) { // page of strings
                    for (i = 0; i < n; i++) {
                        oid = getKeyStrOid(pg, i);
                        result[pos++] = db.lookupObject(oid, null);
                    }
                } else { // page of scalars
                    for (i = 0; i < n; i++) { 
                        oid = getReference(pg, maxItems-1-i);
                        result[pos++] = db.lookupObject(oid, null);
                    }
                }
            }
            return pos;
        } finally { 
            db.pool.unfix(pg);
        }
    }