1 /* Copyright (C) 2014 InfiniDB, Inc. 2 3 This program is free software; you can redistribute it and/or 4 modify it under the terms of the GNU General Public License 5 as published by the Free Software Foundation; version 2 of 6 the License. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 16 MA 02110-1301, USA. */ 17 18 #ifndef UTIL_H 19 #define UTIL_H 20 21 #include <stdlib.h> 22 23 #define MALLOC(type) ((type*)calloc(1, sizeof(type))) 24 25 /* bitmap manipulation */ 26 #define BITS_PER_ITEM(map) (sizeof(map[0])*8) 27 #define MASK(pos,map) (1 << ((pos) % (BITS_PER_ITEM(map)))) 28 #define POS(pos,map) ((pos) / BITS_PER_ITEM(map)) 29 #define SET_BIT(x, map) (map[POS(x,map)] |= MASK(x,map)) 30 #define CLR_BIT(x, map) (map[POS(x,map)] &= ~MASK(x,map)) 31 #define BIT_ISSET(x, map) (map[POS(x,map)] & MASK(x,map)) 32 33 34 #endif 35