1/** 2 * \file 3 * \brief header specifying the interface of libnuma 4 * 5 * This is derived from: 6 * 7 * Linux man pages "numa" 8 * libnuma from http://oss.sgi.com/projects/libnuma/ 9 * 10 */ 11 12/* 13 * Copyright (c) 2014, ETH Zurich. 14 * All rights reserved. 15 * 16 * This file is distributed under the terms in the attached LICENSE file. 17 * If you do not find this file, copies can be found by writing to: 18 * ETH Zurich D-INFK, CAB F.78, Universitaetstr. 6, CH-8092 Zurich. 19 * Attn: Systems Group. 20 */ 21 22#ifndef __BITMAP_H 23#define __BITMAP_H 1 24 25#ifdef __cplusplus 26extern "C" { 27#endif 28 29/* 30 * Bitmap implementation 31 * 32 * - the bitmap is zero indexed 33 */ 34 35///< bitmap structure public declaration 36struct bitmap; 37 38typedef int32_t bitmap_bit_t; 39 40///< value returned if the bits are invalid. 41#define BITMAP_BIT_NONE ((bitmap_bit_t)-1) 42 43///< bitmap list separator 44#define BITMAP_LIST_SEPARATOR ',' 45 46/* allocation and free */ 47struct bitmap *bitmap_alloc(uint32_t n); 48void bitmap_free(struct bitmap *bm); 49 50/* intput/output */ 51size_t bitmap_format(char *outbuf, size_t length, struct bitmap *bm, uint8_t hex); 52size_t bitmap_parse(struct bitmap *outbm, char *inbuf, size_t length, uint8_t hex); 53errval_t bitmap_serialize(void *dest, size_t length, const struct bitmap *bm); 54errval_t bitmap_deserialize(struct bitmap *bm, const void *src, size_t length); 55 56/* bitmap meta information queries */ 57uint32_t bitmap_get_nbytes(const struct bitmap *bm); 58uint32_t bitmap_get_nbits(const struct bitmap *bm); 59uint32_t bitmap_get_weight(const struct bitmap *bm); 60void *bitmap_raw(struct bitmap *bm); 61 62/* bitmap queries */ 63bool bitmap_is_bit_set(const struct bitmap *bm, bitmap_bit_t i); 64bool bitmap_is_bit_clear(const struct bitmap *bm, bitmap_bit_t i); 65bool bitmap_is_all_set(const struct bitmap *bm); 66bool bitmap_is_all_clear(const struct bitmap *bm); 67bitmap_bit_t bitmap_get_first(const struct bitmap *bm); 68bitmap_bit_t bitmap_get_next(const struct bitmap *bm, bitmap_bit_t i); 69bitmap_bit_t bitmap_get_prev(const struct bitmap *bm, bitmap_bit_t i); 70bitmap_bit_t bitmap_get_last(const struct bitmap *bm); 71 72/* Bitmap Manipulations */ 73void bitmap_set_bit(struct bitmap *bm, bitmap_bit_t i); 74void bitmap_clear_bit(struct bitmap *bm, bitmap_bit_t i); 75void bitmap_set_all(struct bitmap *bm); 76void bitmap_clear_all(struct bitmap *bm); 77void bitmap_set_range(struct bitmap *bm, bitmap_bit_t from, bitmap_bit_t to); 78void bitmap_clear_range(struct bitmap *bm, bitmap_bit_t from, bitmap_bit_t tp); 79void bitmap_keep_range(struct bitmap *bm, uint32_t i, uint32_t j); 80 81void bitmap_copy(struct bitmap *to, const struct bitmap *from); 82 83/* bitmap comparisons */ 84bool bitmap_equal(const struct bitmap *bm1, const struct bitmap *bm2); 85bool bitmap_subset(const struct bitmap *bm1, const struct bitmap *bm2); 86bool bitmap_disjoint(const struct bitmap *bm1, const struct bitmap *bm2); 87bool bitmap_intersects(const struct bitmap *bm1, const struct bitmap *bm2); 88 89/* bitmap operations */ 90void bitmap_complement(struct bitmap *bm); 91void bitmap_shift_right(struct bitmap *bm, bitmap_bit_t n); 92void bitmap_shift_left(struct bitmap *bm, bitmap_bit_t n); 93void bitmap_and(struct bitmap *dst, const struct bitmap *src); 94void bitmap_nand(struct bitmap *dst, const struct bitmap *src); 95void bitmap_or(struct bitmap *dst, const struct bitmap *src); 96void bitmap_xor(struct bitmap *dst, const struct bitmap *src); 97 98/* debug operations */ 99void bitmap_dump(const struct bitmap *bm); 100 101#ifdef __cplusplus 102} 103#endif 104 105#endif /* __BITMAP_H */ 106