Otawa  0.10
BitSetManager.h
Go to the documentation of this file.
1 /*
2  * BitSetManager class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2013, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
22 
23 #ifndef OTAWA_BITSETMANAGER_H_
24 #define OTAWA_BITSETMANAGER_H_
25 
26 #include <elm/types.h>
27 #include <elm/assert.h>
28 
29 using namespace elm;
30 
32 public:
33  typedef t::uint32 word_t;
34  typedef word_t *t;
35  inline int size(void) const { return (n + 0x1f) >> 5; }
36  inline word_t *top(t v) const { return v + size(); }
37  inline BitSetManager(int _n): n(_n) { }
38  inline t create(void) const { return new word_t[size()]; }
39  inline void free(t v) const { delete [] v; }
40  inline bool contains(t v, int i) const { return word(v, i) & mask(i); }
41  inline void add(t v, int i) const { word(v, i) |= mask(i); }
42  inline void remove(t v, int i) const { word(v, i) &= ~mask(i); }
43  inline void empty(t d) const { while(d < top(d)) *d++ = 0; }
44  inline void fill(t d) const { while(d < top(d)) *d++ = word_t(-1); }
45  inline void copy(t d, t s) const { while(d < top(d)) *d++ = *s++; }
46  inline void join(t d, t s) const { while(d < top(d)) *d++ |= *s++; }
47  inline void meet(t d, t s) const { while(d < top(d)) *d++ &= *s++; }
48  inline void diff(t d, t s) const { while(d < top(d)) *d++ &= ~*s++; }
49  inline bool isEmpty(t v) const { while(v < top(v)) if(*v) return false; return true; }
50  inline bool include(t d, t s) const { while(d < top(d)) { if((*d | *s) != *d) return false; d++; s++; } return true; }
51  inline bool equals(t d, t s) const { while(d < top(d)) if(*d != *s) return false; return true; }
52 private:
53  inline word_t& word(t v , int i) const { ASSERT(i >= 0 && i < n); return v[i >> 5]; }
54  inline word_t mask(int i) const { return 1 << (i & 0x1f); }
55  int n;
56 };
57 
58 #endif /* BITSETMANAGER_H_ */
bool isEmpty(t v) const
Definition: BitSetManager.h:49
void free(t v) const
Definition: BitSetManager.h:39
void copy(t d, t s) const
Definition: BitSetManager.h:45
int size(void) const
Definition: BitSetManager.h:35
bool equals(t d, t s) const
Definition: BitSetManager.h:51
bool include(t d, t s) const
Definition: BitSetManager.h:50
WAHVector::word_t word_t
word_t * top(t v) const
Definition: BitSetManager.h:36
BitSetManager(int _n)
Definition: BitSetManager.h:37
void add(t v, int i) const
Definition: BitSetManager.h:41
void join(t d, t s) const
Definition: BitSetManager.h:46
int n
Definition: BitSetManager.h:55
uint32 size
Definition: BitSetManager.h:31
bool contains(t v, int i) const
Definition: BitSetManager.h:40
void meet(t d, t s) const
Definition: BitSetManager.h:47
word_t * t
Definition: BitSetManager.h:34
void diff(t d, t s) const
Definition: BitSetManager.h:48
void empty(t d) const
Definition: BitSetManager.h:43
word_t & word(t v, int i) const
Definition: BitSetManager.h:53
word_t mask(int n)
t create(void) const
Definition: BitSetManager.h:38
void fill(t d) const
Definition: BitSetManager.h:44
word_t mask(int i) const
Definition: BitSetManager.h:54
t::uint32 word_t
Definition: BitSetManager.h:33
uint32_t uint32