ROFL-pipeline  v0.6.0dev
bitmap.h
Go to the documentation of this file.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #ifndef __BITMAP_TYPES_H__
6 #define __BITMAP_TYPES_H__
7 
8 #include <inttypes.h>
9 #include <stdbool.h>
10 
19 //Some helper typdefs for code readability
20 typedef uint32_t bitmap32_t;
21 typedef uint64_t bitmap64_t;
22 typedef struct{
23  bitmap64_t __submap[2];
24 }bitmap128_t;
25 
29 static inline void bitmap128_clean(bitmap128_t* bitmap){
30  bitmap->__submap[0] = 0x0ULL;
31  bitmap->__submap[1] = 0x0ULL;
32 }
33 
37 static inline void bitmap128_set_all(bitmap128_t* bitmap){
38  bitmap->__submap[0] = 0xFFFFFFFFFFFFFFFFULL;
39  bitmap->__submap[1] = 0xFFFFFFFFFFFFFFFFULL;
40 }
41 
45 static inline bool bitmap128_is_bit_set(const bitmap128_t* bitmap, unsigned int pos){
46  if(pos >= 64)
47  return ( bitmap->__submap[1] & 1ULL<<(pos-64) ) > 0;
48  else
49  return ( bitmap->__submap[0] & 1ULL<<pos ) > 0;
50 }
51 
55 static inline void bitmap128_set(bitmap128_t* bitmap, unsigned int pos){
56  if(pos >= 64)
57  bitmap->__submap[1] |= 1ULL<<(pos-64);
58  else
59  bitmap->__submap[0] |= 1ULL<<(pos);
60 }
61 
65 static inline void bitmap128_unset(bitmap128_t* bitmap, unsigned int pos){
66  if(pos >= 64)
67  bitmap->__submap[1] &= ~(1ULL << (pos-64));
68  else
69  bitmap->__submap[0] &= ~(1ULL << pos);
70 }
71 
75 static inline bool bitmap128_is_empty(bitmap128_t* bitmap){
76  if( bitmap->__submap[0] == 0x0 && bitmap->__submap[1] == 0x0)
77  return true;
78 
79  return false;
80 }
81 
82 
86 static inline bitmap128_t bitmap128_and(bitmap128_t* bitmap1, bitmap128_t* bitmap2){
87  bitmap128_t result;
88 
89  result.__submap[0] = bitmap1->__submap[0]&bitmap2->__submap[0];
90  result.__submap[1] = bitmap1->__submap[1]&bitmap2->__submap[1];
91 
92  return result;
93 }
94 
95 
99 static inline bool bitmap128_check_mask(bitmap128_t* bitmap, bitmap128_t* mask){
100  if( (bitmap->__submap[0]&mask->__submap[0]) != bitmap->__submap[0])
101  return false;
102 
103  return (bitmap->__submap[1]&mask->__submap[1]) == bitmap->__submap[1];
104 }
105 #endif //__BITMAP_TYPES_H__
static void bitmap128_clean(bitmap128_t *bitmap)
Set bitmap to 0.
Definition: bitmap.h:29
static bool bitmap128_is_bit_set(const bitmap128_t *bitmap, unsigned int pos)
Check if bit is set in the 128bit bitmap.
Definition: bitmap.h:45
static bool bitmap128_is_empty(bitmap128_t *bitmap)
Is bitmap empty.
Definition: bitmap.h:75
static bool bitmap128_check_mask(bitmap128_t *bitmap, bitmap128_t *mask)
Check whether a bitmap is within a certain mask (bitmap&mask == bitmap)
Definition: bitmap.h:99
static bitmap128_t bitmap128_and(bitmap128_t *bitmap1, bitmap128_t *bitmap2)
Make a logical and over to bitmaps.
Definition: bitmap.h:86
static void bitmap128_set_all(bitmap128_t *bitmap)
Set bitmap to 1.
Definition: bitmap.h:37
static void bitmap128_unset(bitmap128_t *bitmap, unsigned int pos)
Unset(zero) a bit in the 128bit bitmap.
Definition: bitmap.h:65
static void bitmap128_set(bitmap128_t *bitmap, unsigned int pos)
Set a bit in the 128bit bitmap.
Definition: bitmap.h:55