libosmocore
0.9.3
Osmocom core library
|
00001 #pragma once 00002 00003 /* bit vector utility routines */ 00004 00005 /* (C) 2009 by Harald Welte <laforge@gnumonks.org> 00006 * 00007 * All Rights Reserved 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License along 00020 * with this program; if not, write to the Free Software Foundation, Inc., 00021 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00022 * 00023 */ 00024 00033 #include <stdint.h> 00034 00039 enum bit_value { 00040 ZERO = 0, 00041 ONE = 1, 00042 L = 2, 00043 H = 3, 00044 }; 00045 00047 struct bitvec { 00048 unsigned int cur_bit; 00049 unsigned int data_len; 00050 uint8_t *data; 00051 }; 00052 00053 enum bit_value bitvec_get_bit_pos(const struct bitvec *bv, unsigned int bitnr); 00054 enum bit_value bitvec_get_bit_pos_high(const struct bitvec *bv, 00055 unsigned int bitnr); 00056 unsigned int bitvec_get_nth_set_bit(const struct bitvec *bv, unsigned int n); 00057 int bitvec_set_bit_pos(struct bitvec *bv, unsigned int bitnum, 00058 enum bit_value bit); 00059 int bitvec_set_bit(struct bitvec *bv, enum bit_value bit); 00060 int bitvec_get_bit_high(struct bitvec *bv); 00061 int bitvec_set_bits(struct bitvec *bv, enum bit_value *bits, int count); 00062 int bitvec_set_uint(struct bitvec *bv, unsigned int in, int count); 00063 int bitvec_get_uint(struct bitvec *bv, int num_bits); 00064 int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val); 00065 int bitvec_spare_padding(struct bitvec *bv, unsigned int up_to_bit); 00066