
// This file is part of the FXT library.
// Copyright (C) 2012 Joerg Arndt
// License: GNU General Public License version 3 or later,
// see the file COPYING.txt in the main directory.

#include "fxttypes.h"


ulong
check_setpart_rgs(const ulong *x, ulong n)
// Check whether x[0,1,...,n-1] is a valid
// RGS of a set partition.
// Return the number of sets if valid, else 0.
{
    if ( n==0 )  return 1;  // The empty set

    if ( x[0] != 0 )  return 0;  // not valid

    ulong m = 0;  // maximum of prefix
    for (ulong j=0; j<n; ++j)
    {
        if ( x[j] > m+1 )  return  0;
        if ( x[j] > m )  m = x[j];
    }
    return m + 1;
}
// -------------------------


bool
is_prefix_max(const ulong *x, ulong n, const ulong *m1)
// Check (for j=1,2,...,n-1) whether
// m1[j] contains max(x[0,1,...,j-1] + 1).
{
    if ( n==0 )  return true;  // Nothing to check

    ulong m = 0;
    for (ulong j=1; j<n; ++j)
    {
        if ( m1[j] != m+1 )  return false;
        if ( x[j] > m )  m = x[j];
    }
    return true;
}
// -------------------------
