1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-09 08:35:19 +02:00
eda-tools/b2/bitset.h

83 lines
1.3 KiB
C
Raw Normal View History

2012-03-18 18:24:12 +02:00
/*
* bitset.h - Bit sets
*
* Copyright 2012 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#ifndef BITSET_H
#define BITSET_H
#include <stdint.h>
#include "bitset.h"
struct bitset {
uint64_t v;
};
static inline void bitset_zero(struct bitset *b)
{
b->v = 0;
}
static inline void bitset_set(struct bitset *b, int n)
{
b->v |= (uint64_t) 1 << n;
}
static inline void bitset_clear(struct bitset *b, int n)
{
b->v &= ~((uint64_t) 1 << n);
}
static inline int bitset_get(const struct bitset *b, int n)
{
return !!(b->v & ((uint64_t) 1 << n));
}
static inline int bitset_empty(const struct bitset *b)
{
2012-04-29 04:49:40 +03:00
return !b->v;
2012-03-18 18:24:12 +02:00
}
static inline int bitset_first(const struct bitset *b)
{
int i;
for (i = 0; i != sizeof(b->v)*8; i++)
if (b->v & ((uint64_t) 1 << i))
return i;
return -1;
}
static inline int bitset_last(const struct bitset *b)
{
int i = sizeof(b->v)*8;
while (--i)
if (b->v & ((uint64_t) 1 << i))
break;
return i;
}
static inline int bitset_common(const struct bitset *a, const struct bitset *b)
{
return (a->v & b->v) != 0;
}
#endif /* !BITSET_H */