Source File include/bitmask.h

    1    | /***************************************
    2    |   $Revision: 1.5 $
    3    |
    4    |   bitmask (ma) - bitmask.h - header file for bitmask library
    5    |
    6    |   Status: NOT REVUED, TESTED, INCOMPLETE
    7    |
    8    |   Design and implementation by: Marek Bukowy
    9    |
    10   |   ******************/ /******************
    11   |   Copyright (c) 1999                              RIPE NCC
    12   |
    13   |   All Rights Reserved
    14   |
    15   |   Permission to use, copy, modify, and distribute this software and its
    16   |   documentation for any purpose and without fee is hereby granted,
    17   |   provided that the above copyright notice appear in all copies and that
    18   |   both that copyright notice and this permission notice appear in
    19   |   supporting documentation, and that the name of the author not be
    20   |   used in advertising or publicity pertaining to distribution of the
    21   |   software without specific, written prior permission.
    22   |
    23   |   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
    24   |   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
    25   |   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
    26   |   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
    27   |   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    28   |   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    29   |   ***************************************/
    30   |
    31   |
    32   | #ifndef READ_BITMASK
    33   | #define READ_BITMASK
    34   |
    35   | #define MASK_BITS_BASETYPE unsigned int
    36   | #define MASK_BITS_BASESIZE (8 * sizeof (MASK_BITS_BASETYPE))
    37   |
    38   | /* size of the mask: to keep things simple, there is only one size
    39   |    that must suit everybody. The requirements are listed below.
    40   |
    41   |    Marek: Aspects. Not many so far, about 30-40 possible.
    42   |    Chris: Query types, 78 at the moment, probably less than 128 at the end
    43   | */
    44   |
    45   |
    46   | #define MASK_MAX 128
    47   | #define MASK_BITS_WORDS    (MASK_MAX / MASK_BITS_BASESIZE + 1)
    48   |
    49   | typedef struct {
    50   |   MASK_BITS_BASETYPE  data[MASK_BITS_WORDS];
    51   | } mask_t;
    52   |
    53   |
    54   | #define MA_END (-1)
    55   |
    56   | void MA_free(mask_t *m);
    57   | int MA_isset(mask_t d, int b);
    58   | void MA_set(mask_t *m_ptr, unsigned b, int v);
    59   | void MA_clear(mask_t *m_ptr);
    60   | mask_t MA_new(int n,...);
    61   | void MA_prt(mask_t m);
    62   | mask_t MA_and(mask_t a, mask_t b);
    63   | mask_t MA_xor(mask_t a, mask_t b);
    64   | mask_t MA_or(mask_t a, mask_t b);
    65   | int MA_bitcount(mask_t m);
    66   | char *MA_to_string(mask_t mask, char * const *tokens);
    67   |
    68   | #endif /* READ_BITMASK */