libosmocore  0.9.3
Osmocom core library
bitvec.h
Go to the documentation of this file.
1 #pragma once
2 
3 /* bit vector utility routines */
4 
5 /* (C) 2009 by Harald Welte <laforge@gnumonks.org>
6  *
7  * All Rights Reserved
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  *
23  */
24 
33 #include <stdint.h>
34 
39 enum bit_value {
40  ZERO = 0,
41  ONE = 1,
42  L = 2,
43  H = 3,
44 };
45 
47 struct bitvec {
48  unsigned int cur_bit;
49  unsigned int data_len;
50  uint8_t *data;
51 };
52 
53 enum bit_value bitvec_get_bit_pos(const struct bitvec *bv, unsigned int bitnr);
54 enum bit_value bitvec_get_bit_pos_high(const struct bitvec *bv,
55  unsigned int bitnr);
56 unsigned int bitvec_get_nth_set_bit(const struct bitvec *bv, unsigned int n);
57 int bitvec_set_bit_pos(struct bitvec *bv, unsigned int bitnum,
58  enum bit_value bit);
59 int bitvec_set_bit(struct bitvec *bv, enum bit_value bit);
60 int bitvec_get_bit_high(struct bitvec *bv);
61 int bitvec_set_bits(struct bitvec *bv, enum bit_value *bits, int count);
62 int bitvec_set_uint(struct bitvec *bv, unsigned int in, int count);
63 int bitvec_get_uint(struct bitvec *bv, int num_bits);
64 int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val);
65 int bitvec_spare_padding(struct bitvec *bv, unsigned int up_to_bit);
66