home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 8.ddi / usr / include / sys / bitmap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  2.1 KB  |  83 lines

  1. /*    Copyright (c) 1990 UNIX System Laboratories, Inc.    */
  2. /*    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T    */
  3. /*      All Rights Reserved      */
  4.  
  5. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF         */
  6. /*    UNIX System Laboratories, Inc.                         */
  7. /*    The copyright notice above does not evidence any       */
  8. /*    actual or intended publication of such source code.    */
  9.  
  10. #ifndef _SYS_BITMAP_H
  11. #define _SYS_BITMAP_H
  12.  
  13. #ident    "@(#)/usr/include/sys/bitmap.h.sl 1.1 4.0 12/08/90 18843 AT&T-USL"
  14.  
  15. /*
  16.  * Operations on bitmaps of arbitrary size
  17.  * A bitmap is a vector of 1 or more ulongs.
  18.  * The user of the package is responsible for range checks and keeping
  19.  * track of sizes.
  20.  */
  21.  
  22. /*
  23.  * REQUIRES sys/types.h
  24.  */
  25.  
  26. #define BT_NBIPUL    32    /* n bits per ulong */
  27. #define BT_ULSHIFT    5    /* log base 2 of BT_NBIPUL,
  28.                  * to extract word index
  29.                  */
  30. #define BT_ULMASK    0x1f    /* to extract bit index */
  31.  
  32. /* 
  33.  * bitmap is a ulong *, bitindex an index_t
  34.  *
  35.  * The macros BT_WIM and BT_BIW internal; there is no need
  36.  * for users of this package to use them.
  37.  */
  38.  
  39. /*
  40.  * word in map
  41.  */
  42. #define BT_WIM(bitmap, bitindex) \
  43.     ((bitmap)[(bitindex) >> BT_ULSHIFT])
  44. /*
  45.  * bit in word
  46.  */
  47. #define BT_BIW(bitindex) \
  48.     (1 << ((bitindex) & BT_ULMASK))
  49.  
  50. /*
  51.  * These are public macros
  52.  *
  53.  * BT_BITOUL == n bits to n ulongs
  54.  */
  55. #define BT_BITOUL(nbits) \
  56.     (((nbits) + BT_NBIPUL -1) / BT_NBIPUL)
  57. #define BT_TEST(bitmap, bitindex) \
  58.     ((BT_WIM((bitmap), (bitindex)) & BT_BIW(bitindex)) ? 1 : 0)
  59. #define BT_SET(bitmap, bitindex) \
  60.     { BT_WIM((bitmap), (bitindex)) |= BT_BIW(bitindex); }
  61. #define BT_CLEAR(bitmap, bitindex) \
  62.     { BT_WIM((bitmap), (bitindex)) &= ~BT_BIW(bitindex); }
  63.  
  64.  
  65. #if defined(__STDC__)
  66. /*
  67.  * return next available bit index from map with specified number of bits
  68.  */
  69. extern index_t    bt_availbit(ulong *bitmap, size_t nbits);
  70. /*
  71.  * find the highest order bit that is on, and is within or below
  72.  * the word specified by wx
  73.  */
  74. extern void    bt_gethighbit(ulong *mapp, int wx, int *bitposp);
  75. extern int     bt_range(ulong *bitmap, size_t *pos1, size_t *pos2, size_t nbits);
  76. #else
  77. extern index_t    bt_availbit();
  78. extern void    bt_gethighbit();
  79. extern int    bt_range();
  80. #endif
  81.  
  82. #endif    /* _SYS_BITMAP_H */
  83.