Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Defines | Typedefs | Enumerations | Functions

bitmapset.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Bitmapset

Defines

#define BITS_PER_BITMAPWORD   32

Typedefs

typedef uint32 bitmapword
typedef int32 signedbitmapword
typedef struct Bitmapset Bitmapset

Enumerations

enum  BMS_Comparison { BMS_EQUAL, BMS_SUBSET1, BMS_SUBSET2, BMS_DIFFERENT }
enum  BMS_Membership { BMS_EMPTY_SET, BMS_SINGLETON, BMS_MULTIPLE }

Functions

Bitmapsetbms_copy (const Bitmapset *a)
bool bms_equal (const Bitmapset *a, const Bitmapset *b)
Bitmapsetbms_make_singleton (int x)
void bms_free (Bitmapset *a)
Bitmapsetbms_union (const Bitmapset *a, const Bitmapset *b)
Bitmapsetbms_intersect (const Bitmapset *a, const Bitmapset *b)
Bitmapsetbms_difference (const Bitmapset *a, const Bitmapset *b)
bool bms_is_subset (const Bitmapset *a, const Bitmapset *b)
BMS_Comparison bms_subset_compare (const Bitmapset *a, const Bitmapset *b)
bool bms_is_member (int x, const Bitmapset *a)
bool bms_overlap (const Bitmapset *a, const Bitmapset *b)
bool bms_nonempty_difference (const Bitmapset *a, const Bitmapset *b)
int bms_singleton_member (const Bitmapset *a)
int bms_num_members (const Bitmapset *a)
BMS_Membership bms_membership (const Bitmapset *a)
bool bms_is_empty (const Bitmapset *a)
Bitmapsetbms_add_member (Bitmapset *a, int x)
Bitmapsetbms_del_member (Bitmapset *a, int x)
Bitmapsetbms_add_members (Bitmapset *a, const Bitmapset *b)
Bitmapsetbms_int_members (Bitmapset *a, const Bitmapset *b)
Bitmapsetbms_del_members (Bitmapset *a, const Bitmapset *b)
Bitmapsetbms_join (Bitmapset *a, Bitmapset *b)
int bms_first_member (Bitmapset *a)
uint32 bms_hash_value (const Bitmapset *a)

Define Documentation

#define BITS_PER_BITMAPWORD   32

Definition at line 28 of file bitmapset.h.

Referenced by tbm_iterate().


Typedef Documentation

typedef struct Bitmapset Bitmapset
typedef uint32 bitmapword

Definition at line 29 of file bitmapset.h.

Definition at line 30 of file bitmapset.h.


Enumeration Type Documentation

Enumerator:
BMS_EQUAL 
BMS_SUBSET1 
BMS_SUBSET2 
BMS_DIFFERENT 

Definition at line 40 of file bitmapset.h.

{
    BMS_EQUAL,                  /* sets are equal */
    BMS_SUBSET1,                /* first set is a subset of the second */
    BMS_SUBSET2,                /* second set is a subset of the first */
    BMS_DIFFERENT               /* neither set is a subset of the other */
} BMS_Comparison;

Enumerator:
BMS_EMPTY_SET 
BMS_SINGLETON 
BMS_MULTIPLE 

Definition at line 49 of file bitmapset.h.

{
    BMS_EMPTY_SET,              /* 0 members */
    BMS_SINGLETON,              /* 1 member */
    BMS_MULTIPLE                /* >1 member */
} BMS_Membership;


Function Documentation

Bitmapset* bms_add_member ( Bitmapset a,
int  x 
)

Definition at line 624 of file bitmapset.c.

References BITNUM, bms_make_singleton(), elog, ERROR, i, NULL, Bitmapset::nwords, pfree(), WORDNUM, and Bitmapset::words.

Referenced by _readBitmapset(), adjust_relid_set(), adjust_view_column_set(), alias_relid_set(), build_subplan(), check_index_only(), checkInsertTargets(), classify_index_clause_usage(), convert_EXISTS_sublink_to_join(), create_index_paths(), create_lateral_join_info(), DoCopy(), EvalPlanQualBegin(), ExecNestLoop(), ExecRecursiveUnion(), ExecReScanRecursiveUnion(), ExecReScanSetParamPlan(), ExecScanSubPlan(), ExplainPreScanNode(), finalize_plan(), finalize_primnode(), find_hash_columns(), find_unaggregated_cols_walker(), fixup_inherited_columns(), fixup_whole_row_references(), func_get_detail(), get_relids_in_jointree(), intorel_startup(), load_enum_cache_data(), make_datum_param(), make_one_rel(), make_row_comparison_op(), make_windowInputTargetList(), makeDependencyGraphWalker(), markRTEForSelectPriv(), offset_relid_set(), postgresGetForeignPaths(), pull_up_sublinks_jointree_recurse(), pull_varattnos_walker(), pull_varnos_walker(), qual_is_pushdown_safe(), RelationGetIndexAttrBitmap(), RememberFsyncRequest(), remove_rel_from_query(), RI_Initial_Check(), set_join_column_names(), SS_finalize_plan(), transformUpdateStmt(), translate_col_privs(), and view_is_auto_updatable().

{
    int         wordnum,
                bitnum;

    if (x < 0)
        elog(ERROR, "negative bitmapset member not allowed");
    if (a == NULL)
        return bms_make_singleton(x);
    wordnum = WORDNUM(x);
    bitnum = BITNUM(x);
    if (wordnum >= a->nwords)
    {
        /* Slow path: make a larger set and union the input set into it */
        Bitmapset  *result;
        int         nwords;
        int         i;

        result = bms_make_singleton(x);
        nwords = a->nwords;
        for (i = 0; i < nwords; i++)
            result->words[i] |= a->words[i];
        pfree(a);
        return result;
    }
    /* Fast path: x fits in existing set */
    a->words[wordnum] |= ((bitmapword) 1 << bitnum);
    return a;
}

Bitmapset* bms_add_members ( Bitmapset a,
const Bitmapset b 
)

Definition at line 682 of file bitmapset.c.

References bms_copy(), i, NULL, Bitmapset::nwords, pfree(), and Bitmapset::words.

Referenced by add_child_rel_equivalences(), add_eq_member(), add_vars_to_targetlist(), build_index_paths(), check_outerjoin_delay(), choose_bitmap_and(), create_lateral_join_info(), deconstruct_recurse(), finalize_plan(), make_outerjoininfo(), mark_placeholder_maybe_needed(), pull_varnos_walker(), reduce_outer_joins_pass1(), reduce_outer_joins_pass2(), SS_finalize_plan(), and update_placeholder_eval_levels().

{
    Bitmapset  *result;
    const Bitmapset *other;
    int         otherlen;
    int         i;

    /* Handle cases where either input is NULL */
    if (a == NULL)
        return bms_copy(b);
    if (b == NULL)
        return a;
    /* Identify shorter and longer input; copy the longer one if needed */
    if (a->nwords < b->nwords)
    {
        result = bms_copy(b);
        other = a;
    }
    else
    {
        result = a;
        other = b;
    }
    /* And union the shorter input into the result */
    otherlen = other->nwords;
    for (i = 0; i < otherlen; i++)
        result->words[i] |= other->words[i];
    if (result != a)
        pfree(a);
    return result;
}

Bitmapset* bms_copy ( const Bitmapset a  ) 
Bitmapset* bms_del_member ( Bitmapset a,
int  x 
)

Definition at line 662 of file bitmapset.c.

References BITNUM, elog, ERROR, NULL, WORDNUM, and Bitmapset::words.

Referenced by adjust_relid_set(), build_index_paths(), finalize_plan(), finalize_primnode(), fixup_whole_row_references(), postgresGetForeignPaths(), preprocess_rowmarks(), remove_rel_from_query(), substitute_multiple_relids_walker(), and TopologicalSort().

{
    int         wordnum,
                bitnum;

    if (x < 0)
        elog(ERROR, "negative bitmapset member not allowed");
    if (a == NULL)
        return NULL;
    wordnum = WORDNUM(x);
    bitnum = BITNUM(x);
    if (wordnum < a->nwords)
        a->words[wordnum] &= ~((bitmapword) 1 << bitnum);
    return a;
}

Bitmapset* bms_del_members ( Bitmapset a,
const Bitmapset b 
)

Definition at line 744 of file bitmapset.c.

References i, Min, NULL, Bitmapset::nwords, and Bitmapset::words.

Referenced by calc_nestloop_required_outer(), and SS_finalize_plan().

{
    int         shortlen;
    int         i;

    /* Handle cases where either input is NULL */
    if (a == NULL)
        return NULL;
    if (b == NULL)
        return a;
    /* Remove b's bits from a; we need never copy */
    shortlen = Min(a->nwords, b->nwords);
    for (i = 0; i < shortlen; i++)
        a->words[i] &= ~b->words[i];
    return a;
}

Bitmapset* bms_difference ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 283 of file bitmapset.c.

References bms_copy(), i, Min, NULL, Bitmapset::nwords, and Bitmapset::words.

Referenced by add_child_rel_equivalences(), add_paths_to_joinrel(), check_partial_indexes(), and finalize_plan().

{
    Bitmapset  *result;
    int         shortlen;
    int         i;

    /* Handle cases where either input is NULL */
    if (a == NULL)
        return NULL;
    if (b == NULL)
        return bms_copy(a);
    /* Copy the left input */
    result = bms_copy(a);
    /* And remove b's bits from result */
    shortlen = Min(a->nwords, b->nwords);
    for (i = 0; i < shortlen; i++)
        result->words[i] &= ~b->words[i];
    return result;
}

bool bms_equal ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 130 of file bitmapset.c.

References bms_is_empty(), i, NULL, Bitmapset::nwords, and Bitmapset::words.

Referenced by add_path_precheck(), bitmap_match(), bms_equal_any(), choose_bitmap_and(), create_append_path(), create_merge_append_path(), create_unique_path(), find_ec_member_for_tle(), find_join_rel(), fix_indexqual_references(), generate_implied_equalities_for_column(), get_appendrel_parampathinfo(), get_baserel_parampathinfo(), get_eclass_for_sort_expr(), get_joinrel_parampathinfo(), join_is_legal(), join_is_removable(), make_join_rel(), make_one_rel(), match_pathkeys_to_index(), prepare_sort_from_pathkeys(), remove_rel_from_query(), and set_append_rel_pathlist().

{
    const Bitmapset *shorter;
    const Bitmapset *longer;
    int         shortlen;
    int         longlen;
    int         i;

    /* Handle cases where either input is NULL */
    if (a == NULL)
    {
        if (b == NULL)
            return true;
        return bms_is_empty(b);
    }
    else if (b == NULL)
        return bms_is_empty(a);
    /* Identify shorter and longer input */
    if (a->nwords <= b->nwords)
    {
        shorter = a;
        longer = b;
    }
    else
    {
        shorter = b;
        longer = a;
    }
    /* And process */
    shortlen = shorter->nwords;
    for (i = 0; i < shortlen; i++)
    {
        if (shorter->words[i] != longer->words[i])
            return false;
    }
    longlen = longer->nwords;
    for (; i < longlen; i++)
    {
        if (longer->words[i] != 0)
            return false;
    }
    return true;
}

int bms_first_member ( Bitmapset a  ) 

Definition at line 812 of file bitmapset.c.

References NULL, Bitmapset::nwords, RIGHTMOST_ONE, rightmost_one_pos, and Bitmapset::words.

Referenced by _outBitmapset(), add_join_clause_to_rels(), adjust_view_column_set(), alias_relid_set(), check_relation_privileges(), check_selective_binary_conversion(), convert_EXISTS_sublink_to_join(), ExecCheckRTEPerms(), find_hash_columns(), fixup_inherited_columns(), get_loop_count(), HeapSatisfiesHOTandKeyUpdate(), make_row_comparison_op(), mdsync(), offset_relid_set(), postgresPlanForeignModify(), remove_join_clause_from_rels(), and setup_param_list().

{
    int         nwords;
    int         wordnum;

    if (a == NULL)
        return -1;
    nwords = a->nwords;
    for (wordnum = 0; wordnum < nwords; wordnum++)
    {
        bitmapword  w = a->words[wordnum];

        if (w != 0)
        {
            int         result;

            w = RIGHTMOST_ONE(w);
            a->words[wordnum] &= ~w;

            result = wordnum * BITS_PER_BITMAPWORD;
            while ((w & 255) == 0)
            {
                w >>= 8;
                result += 8;
            }
            result += rightmost_one_pos[w & 255];
            return result;
        }
    }
    return -1;
}

void bms_free ( Bitmapset a  ) 
uint32 bms_hash_value ( const Bitmapset a  ) 

Definition at line 853 of file bitmapset.c.

References DatumGetUInt32, hash_any(), NULL, Bitmapset::nwords, and Bitmapset::words.

Referenced by bitmap_hash().

{
    int         lastword;

    if (a == NULL)
        return 0;               /* All empty sets hash to 0 */
    for (lastword = a->nwords; --lastword >= 0;)
    {
        if (a->words[lastword] != 0)
            break;
    }
    if (lastword < 0)
        return 0;               /* All empty sets hash to 0 */
    return DatumGetUInt32(hash_any((const unsigned char *) a->words,
                                   (lastword + 1) * sizeof(bitmapword)));
}

Bitmapset* bms_int_members ( Bitmapset a,
const Bitmapset b 
)

Definition at line 718 of file bitmapset.c.

References i, Min, NULL, Bitmapset::nwords, pfree(), and Bitmapset::words.

Referenced by check_outerjoin_delay(), find_nonnullable_rels_walker(), make_outerjoininfo(), and make_row_comparison_op().

{
    int         shortlen;
    int         i;

    /* Handle cases where either input is NULL */
    if (a == NULL)
        return NULL;
    if (b == NULL)
    {
        pfree(a);
        return NULL;
    }
    /* Intersect b into a; we need never copy */
    shortlen = Min(a->nwords, b->nwords);
    for (i = 0; i < shortlen; i++)
        a->words[i] &= b->words[i];
    for (; i < a->nwords; i++)
        a->words[i] = 0;
    return a;
}

Bitmapset* bms_intersect ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 251 of file bitmapset.c.

References bms_copy(), i, NULL, Bitmapset::nwords, and Bitmapset::words.

Referenced by make_outerjoininfo(), process_equivalence(), reconsider_full_join_clause(), reconsider_outer_join_clause(), and UpdateChangedParamSet().

{
    Bitmapset  *result;
    const Bitmapset *other;
    int         resultlen;
    int         i;

    /* Handle cases where either input is NULL */
    if (a == NULL || b == NULL)
        return NULL;
    /* Identify shorter and longer input; copy the shorter one */
    if (a->nwords <= b->nwords)
    {
        result = bms_copy(a);
        other = b;
    }
    else
    {
        result = bms_copy(b);
        other = a;
    }
    /* And intersect the longer input with the result */
    resultlen = result->nwords;
    for (i = 0; i < resultlen; i++)
        result->words[i] &= other->words[i];
    return result;
}

bool bms_is_empty ( const Bitmapset a  ) 
bool bms_is_member ( int  x,
const Bitmapset a 
)
bool bms_is_subset ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 307 of file bitmapset.c.

References bms_is_empty(), i, Min, NULL, Bitmapset::nwords, and Bitmapset::words.

Referenced by add_child_rel_equivalences(), add_lateral_info(), add_placeholders_to_joinrel(), add_vars_to_targetlist(), check_index_only(), check_outerjoin_delay(), clause_sides_match_join(), convert_ANY_sublink_to_join(), convert_EXISTS_sublink_to_join(), create_index_paths(), create_nestloop_plan(), create_unique_path(), distribute_qual_to_rels(), drop_indexable_join_clauses(), eclass_already_used(), eclass_useful_for_merging(), final_cost_hashjoin(), finalize_plan(), generate_implied_equalities_for_column(), generate_join_implied_equalities_broken(), generate_join_implied_equalities_normal(), get_cheapest_fractional_path_for_pathkeys(), get_cheapest_path_for_pathkeys(), get_join_index_paths(), get_join_variables(), get_switched_clauses(), has_join_restriction(), has_relevant_eclass_joinclause(), have_join_order_restriction(), initial_cost_mergejoin(), is_simple_subquery(), join_clause_is_movable_into(), join_is_legal(), join_is_removable(), make_join_rel(), make_outerjoininfo(), process_subquery_nestloop_params(), reparameterize_path(), replace_nestloop_params_mutator(), subbuild_joinrel_joinlist(), subbuild_joinrel_restrictlist(), update_placeholder_eval_levels(), and use_physical_tlist().

{
    int         shortlen;
    int         longlen;
    int         i;

    /* Handle cases where either input is NULL */
    if (a == NULL)
        return true;            /* empty set is a subset of anything */
    if (b == NULL)
        return bms_is_empty(a);
    /* Check common words */
    shortlen = Min(a->nwords, b->nwords);
    for (i = 0; i < shortlen; i++)
    {
        if ((a->words[i] & ~b->words[i]) != 0)
            return false;
    }
    /* Check extra words */
    if (a->nwords > b->nwords)
    {
        longlen = a->nwords;
        for (; i < longlen; i++)
        {
            if (a->words[i] != 0)
                return false;
        }
    }
    return true;
}

Bitmapset* bms_join ( Bitmapset a,
Bitmapset b 
)

Definition at line 765 of file bitmapset.c.

References i, NULL, Bitmapset::nwords, pfree(), and Bitmapset::words.

Referenced by add_paths_to_joinrel(), alias_relid_set(), finalize_primnode(), find_nonnullable_rels_walker(), find_placeholders_recurse(), get_base_rel_indexes(), get_bitmap_tree_required_outer(), get_relids_in_jointree(), process_equivalence(), pull_up_sublinks_jointree_recurse(), pull_varnos_walker(), and UpdateChangedParamSet().

{
    Bitmapset  *result;
    Bitmapset  *other;
    int         otherlen;
    int         i;

    /* Handle cases where either input is NULL */
    if (a == NULL)
        return b;
    if (b == NULL)
        return a;
    /* Identify shorter and longer input; use longer one as result */
    if (a->nwords < b->nwords)
    {
        result = b;
        other = a;
    }
    else
    {
        result = a;
        other = b;
    }
    /* And union the shorter input into the result */
    otherlen = other->nwords;
    for (i = 0; i < otherlen; i++)
        result->words[i] |= other->words[i];
    if (other != result)        /* pure paranoia */
        pfree(other);
    return result;
}

Bitmapset* bms_make_singleton ( int  x  ) 
BMS_Membership bms_membership ( const Bitmapset a  ) 

Definition at line 560 of file bitmapset.c.

References BMS_EMPTY_SET, HAS_MULTIPLE_ONES, NULL, Bitmapset::nwords, and Bitmapset::words.

Referenced by add_placeholders_to_base_rels(), bms_is_subset_singleton(), clauselist_selectivity(), distribute_qual_to_rels(), distribute_restrictinfo_to_rels(), examine_variable(), find_join_input_rel(), fix_placeholder_input_needed_levels(), generate_base_implied_equalities_broken(), generate_base_implied_equalities_const(), generate_base_implied_equalities_no_const(), join_is_removable(), and treat_as_join_clause().

{
    BMS_Membership result = BMS_EMPTY_SET;
    int         nwords;
    int         wordnum;

    if (a == NULL)
        return BMS_EMPTY_SET;
    nwords = a->nwords;
    for (wordnum = 0; wordnum < nwords; wordnum++)
    {
        bitmapword  w = a->words[wordnum];

        if (w != 0)
        {
            if (result != BMS_EMPTY_SET || HAS_MULTIPLE_ONES(w))
                return BMS_MULTIPLE;
            result = BMS_SINGLETON;
        }
    }
    return result;
}

bool bms_nonempty_difference ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 464 of file bitmapset.c.

References bms_is_empty(), i, Min, NULL, Bitmapset::nwords, and Bitmapset::words.

Referenced by add_placeholders_to_base_rels(), add_placeholders_to_joinrel(), build_joinrel_tlist(), and use_physical_tlist().

{
    int         shortlen;
    int         i;

    /* Handle cases where either input is NULL */
    if (a == NULL)
        return false;
    if (b == NULL)
        return !bms_is_empty(a);
    /* Check words in common */
    shortlen = Min(a->nwords, b->nwords);
    for (i = 0; i < shortlen; i++)
    {
        if ((a->words[i] & ~b->words[i]) != 0)
            return true;
    }
    /* Check extra words in a */
    for (; i < a->nwords; i++)
    {
        if (a->words[i] != 0)
            return true;
    }
    return false;
}

int bms_num_members ( const Bitmapset a  ) 

Definition at line 531 of file bitmapset.c.

References NULL, number_of_ones, Bitmapset::nwords, and Bitmapset::words.

Referenced by build_join_rel(), and NumRelids().

{
    int         result = 0;
    int         nwords;
    int         wordnum;

    if (a == NULL)
        return 0;
    nwords = a->nwords;
    for (wordnum = 0; wordnum < nwords; wordnum++)
    {
        bitmapword  w = a->words[wordnum];

        /* we assume here that bitmapword is an unsigned type */
        while (w != 0)
        {
            result += number_of_ones[w & 255];
            w >>= 8;
        }
    }
    return result;
}

bool bms_overlap ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 442 of file bitmapset.c.

References i, Min, NULL, Bitmapset::nwords, and Bitmapset::words.

Referenced by add_child_rel_equivalences(), add_paths_to_joinrel(), calc_nestloop_required_outer(), calc_non_nestloop_required_outer(), check_outerjoin_delay(), choose_bitmap_and(), create_nestloop_path(), create_nestloop_plan(), create_unique_path(), distribute_qual_to_rels(), eclass_useful_for_merging(), ExecBRUpdateTriggers(), generate_implied_equalities_for_column(), generate_join_implied_equalities(), get_appendrel_parampathinfo(), get_baserel_parampathinfo(), get_joinrel_parampathinfo(), has_join_restriction(), has_legal_joinclause(), has_relevant_eclass_joinclause(), have_join_order_restriction(), have_relevant_eclass_joinclause(), have_relevant_joinclause(), join_clause_is_movable_into(), join_is_legal(), join_is_removable(), join_search_one_level(), make_join_rel(), make_outerjoininfo(), make_rels_by_clause_joins(), make_rels_by_clauseless_joins(), make_restrictinfo_internal(), match_join_clauses_to_index(), postgresGetForeignPaths(), reduce_outer_joins_pass2(), replace_nestloop_params_mutator(), select_outer_pathkeys_for_merge(), try_hashjoin_path(), try_mergejoin_path(), try_nestloop_path(), and update_placeholder_eval_levels().

{
    int         shortlen;
    int         i;

    /* Handle cases where either input is NULL */
    if (a == NULL || b == NULL)
        return false;
    /* Check words in common */
    shortlen = Min(a->nwords, b->nwords);
    for (i = 0; i < shortlen; i++)
    {
        if ((a->words[i] & b->words[i]) != 0)
            return true;
    }
    return false;
}

int bms_singleton_member ( const Bitmapset a  ) 

Definition at line 496 of file bitmapset.c.

References elog, ERROR, HAS_MULTIPLE_ONES, NULL, Bitmapset::nwords, rightmost_one_pos, and Bitmapset::words.

Referenced by add_placeholders_to_base_rels(), distribute_restrictinfo_to_rels(), examine_variable(), find_join_input_rel(), fix_append_rel_relids(), generate_base_implied_equalities_no_const(), join_is_removable(), and remove_useless_joins().

{
    int         result = -1;
    int         nwords;
    int         wordnum;

    if (a == NULL)
        elog(ERROR, "bitmapset is empty");
    nwords = a->nwords;
    for (wordnum = 0; wordnum < nwords; wordnum++)
    {
        bitmapword  w = a->words[wordnum];

        if (w != 0)
        {
            if (result >= 0 || HAS_MULTIPLE_ONES(w))
                elog(ERROR, "bitmapset has multiple members");
            result = wordnum * BITS_PER_BITMAPWORD;
            while ((w & 255) == 0)
            {
                w >>= 8;
                result += 8;
            }
            result += rightmost_one_pos[w & 255];
        }
    }
    if (result < 0)
        elog(ERROR, "bitmapset is empty");
    return result;
}

BMS_Comparison bms_subset_compare ( const Bitmapset a,
const Bitmapset b 
)

Definition at line 344 of file bitmapset.c.

References BMS_EQUAL, bms_is_empty(), BMS_SUBSET1, BMS_SUBSET2, i, Min, NULL, Bitmapset::nwords, and Bitmapset::words.

Referenced by add_path(), consider_index_join_outer_rels(), and set_cheapest().

{
    BMS_Comparison result;
    int         shortlen;
    int         longlen;
    int         i;

    /* Handle cases where either input is NULL */
    if (a == NULL)
    {
        if (b == NULL)
            return BMS_EQUAL;
        return bms_is_empty(b) ? BMS_EQUAL : BMS_SUBSET1;
    }
    if (b == NULL)
        return bms_is_empty(a) ? BMS_EQUAL : BMS_SUBSET2;
    /* Check common words */
    result = BMS_EQUAL;         /* status so far */
    shortlen = Min(a->nwords, b->nwords);
    for (i = 0; i < shortlen; i++)
    {
        bitmapword  aword = a->words[i];
        bitmapword  bword = b->words[i];

        if ((aword & ~bword) != 0)
        {
            /* a is not a subset of b */
            if (result == BMS_SUBSET1)
                return BMS_DIFFERENT;
            result = BMS_SUBSET2;
        }
        if ((bword & ~aword) != 0)
        {
            /* b is not a subset of a */
            if (result == BMS_SUBSET2)
                return BMS_DIFFERENT;
            result = BMS_SUBSET1;
        }
    }
    /* Check extra words */
    if (a->nwords > b->nwords)
    {
        longlen = a->nwords;
        for (; i < longlen; i++)
        {
            if (a->words[i] != 0)
            {
                /* a is not a subset of b */
                if (result == BMS_SUBSET1)
                    return BMS_DIFFERENT;
                result = BMS_SUBSET2;
            }
        }
    }
    else if (a->nwords < b->nwords)
    {
        longlen = b->nwords;
        for (; i < longlen; i++)
        {
            if (b->words[i] != 0)
            {
                /* b is not a subset of a */
                if (result == BMS_SUBSET2)
                    return BMS_DIFFERENT;
                result = BMS_SUBSET1;
            }
        }
    }
    return result;
}

Bitmapset* bms_union ( const Bitmapset a,
const Bitmapset b 
)