skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

bitarray.html (5145B)


      1 <html>
      2   <head>
      3     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      4     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      5     <meta http-equiv="Content-Language" content="en" />
      6     <title>skalibs: the bitarray library interface</title>
      7     <meta name="Description" content="skalibs: the bitarray library interface" />
      8     <meta name="Keywords" content="skalibs c unix bitarray library libstddjb" />
      9     <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> -->
     10   </head>
     11 <body>
     12 
     13 <p>
     14 <a href="index.html">libstddjb</a><br />
     15 <a href="../libskarnet.html">libskarnet</a><br />
     16 <a href="../index.html">skalibs</a><br />
     17 <a href="//skarnet.org/software/">Software</a><br />
     18 <a href="//skarnet.org/">skarnet.org</a>
     19 </p>
     20 
     21 <h1> The <tt>bitarray</tt> library interface </h1>
     22 
     23 <p>
     24  The following functions are declared in the <tt>skalibs/bitarray.h</tt> header,
     25 and implemented in the <tt>libskarnet.a</tt> or <tt>libskarnet.so</tt> library.
     26 </p>
     27 
     28 <h2> General information </h2>
     29 
     30 <p>
     31  <tt>bitarray</tt> is a set of primitives to operate efficiently on
     32 large bitfields.
     33 </p>
     34 
     35 <p>
     36  A bitfield is represented by a pre-allocated block of
     37 <tt>unsigned char</tt>; <tt>bitarray</tt> does not care if that
     38 block has been BSS-, stack- or heap-allocated. Bitfields that
     39 can grow in size should be stored in a
     40 <a href="stralloc.html">stralloc</a>.
     41 </p>
     42 
     43 <p>
     44  Bits in a bitfield of length <em>n</em> are numbered from 0 to <em>n</em>-1.
     45 </p>
     46 
     47 <h2> Functions </h2>
     48 
     49 <p>
     50 <code> size_t bitarray_div8 (size_t n) </code> <br />
     51 Returns the minimum number of bytes needed to store a field of <em>n</em> bits.
     52 
     53 </p>
     54 
     55 <p>
     56 <code> void bitarray_clearsetn (unsigned char *s, size_t start, size_t len, int h) </code> <br />
     57 Sets (if <em>h</em> is nonzero) or clears (if <em>h</em> is zero)
     58 <em>len</em> bits in field <em>s</em>, starting at bit <em>start</em>.
     59 </p>
     60 
     61 <p>
     62 <code> void bitarray_clearn (unsigned char *s, size_t start, size_t len) </code> <br />
     63 Clears <em>len</em> bits in field <em>s</em>, starting at bit <em>start</em>.
     64 </p>
     65 
     66 <p>
     67 <code> void bitarray_setn (unsigned char *s, size_t start, size_t len) </code> <br />
     68 Sets <em>len</em> bits in field <em>s</em>, starting at bit <em>start</em>.
     69 </p>
     70 
     71 <p>
     72 <code> int bitarray_peek (unsigned char const *s, size_t n) </code> <br />
     73 Returns the value of the <em>n</em>th bit in field <em>s</em>.
     74 </p>
     75 
     76 <p>
     77 <code> void bitarray_poke (unsigned char *s, size_t n, int h) </code> <br />
     78 Sets (if <em>h</em> is nonzero) or clears (if <em>h</em> is zero)
     79 the <em>n</em>th bit in field <em>s</em>.
     80 </p>
     81 
     82 <p>
     83 <code> void bitarray_clear (unsigned char *s, size_t n) </code> <br />
     84 Clears the <em>n</em>th bit in field <em>s</em>.
     85 </p>
     86 
     87 <p>
     88 <code> void bitarray_set (unsigned char *s, size_t n) </code> <br />
     89 Sets the <em>n</em>th bit in field <em>s</em>.
     90 </p>
     91 
     92 <p>
     93 <code> int bitarray_testandpoke (unsigned char *s, size_t n, int h) </code> <br />
     94 Sets (if <em>h</em> is nonzero) or clears (if <em>h</em> is zero)
     95 the <em>n</em>th bit in field <em>s</em>,
     96 and returns the previous value of that bit.
     97 </p>
     98 
     99 <p>
    100 <code> int bitarray_testandclear (unsigned char *s, size_t n) </code> <br />
    101 Clear the <em>n</em>th bit in field <em>s</em>,
    102 and returns the previous value of that bit.
    103 </p>
    104 
    105 <p>
    106 <code> int bitarray_testandset (unsigned char *s, size_t n) </code> <br />
    107 Sets the <em>n</em>th bit in field <em>s</em>,
    108 and returns the previous value of that bit.
    109 </p>
    110 
    111 <p>
    112 <code> size_t bitarray_first (unsigned char const *s, size_t len, int h) </code> <br />
    113 Returns the number of the first set (if <em>h</em> is nonzero) or clear
    114 (if <em>h</em> is zero) bit in <em>s</em>, <em>len</em> being
    115 the total number of bits. If all bits in <em>s</em> are the negation of
    116 <em>h</em>, then <em>len</em> is returned.
    117 </p>
    118 
    119 <p>
    120 <code> size_t bitarray_firstclear (unsigned char const *s, size_t len) </code> <br />
    121 Returns the number of the first clear bit in <em>s</em>, <em>len</em> being
    122 the total number of bits. If all bits in <em>s</em> are set, <em>len</em> is returned.
    123 </p>
    124 
    125 <p>
    126 <code> size_t bitarray_firstclear_skip (unsigned char const *s, size_t len, size_t skip) </code> <br />
    127 Like <tt>bitarray_firstclear</tt>, but the first <em>skip</em> bits are
    128 ignored: the function cannot return less than <em>skip</em>. It is a
    129 programming error if <em>skip</em> &gt; <em>len</em>.
    130 </p>
    131 
    132 <p>
    133 <code> size_t bitarray_firstset (unsigned char const *s, size_t len) </code> <br />
    134 Returns the number of the first set bit in <em>s</em>, <em>len</em> being
    135 the total number of bits. If all bits in <em>s</em> are clear, <em>len</em> is returned.
    136 </p>
    137 
    138 <p>
    139 <code> size_t bitarray_firstset_skip (unsigned char const *s, size_t len, size_t skip) </code> <br />
    140 Like <tt>bitarray_firstset</tt>, but the first <em>skip</em> bits are
    141 ignored: the function cannot return less than <em>skip</em>. It is a
    142 programming error if <em>skip</em> &gt; <em>len</em>.
    143 </p>
    144 
    145 <p>
    146 <code> size_t bitarray_countones (unsigned char const *s, size_t len) </code> <br />
    147 Returns the number of set bits in <em>s</em>, <em>len</em> being the
    148 total number of bits being tested.
    149 </p>
    150 
    151 </body>
    152 </html>