File: bitset.h

package info (click to toggle)
cups-filters 1.28.17-3%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,096 kB
  • sloc: ansic: 54,489; cpp: 7,023; sh: 1,911; makefile: 963; xml: 127; perl: 73; php: 28; python: 8
file content (38 lines) | stat: -rw-r--r-- 722 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef _BITSET_H
#define _BITSET_H

#include <stdlib.h>

typedef int * BITSET;

static inline void bit_set(BITSET bs,int num)
{
  bs[num/(8*sizeof(int))]|=1<<(num%(8*sizeof(int)));
}

static inline int bit_check(BITSET bs,int num)
{
  return bs[num/(8*sizeof(int))]&1<<(num%(8*sizeof(int)));
}

// use free() when done. returns NULL on bad_alloc
static inline BITSET bitset_new(int size)
{
  return (BITSET)calloc(1,((size+8*sizeof(int)-1)&~(8*sizeof(int)-1))/8);
}

static inline int bits_used(BITSET bits,int size) // {{{  returns true if any bit is used
{
  size=(size+8*sizeof(int)-1)/(8*sizeof(int));
  while (size>0) {
    if (*bits) {
      return 1;
    }
    bits++;
    size--;
  }
  return 0;
}
// }}}

#endif