SphinxBase  5prealpha
bitarr.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 2015 Carnegie Mellon University. All rights
4  * reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * This work was supported in part by funding from the Defense Advanced
19  * Research Projects Agency and the National Science Foundation of the
20  * United States of America, and the CMU Sphinx Speech Consortium.
21  *
22  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * ====================================================================
35  *
36  */
37 
38 #ifndef _LIBUTIL_BITARR_H_
39 #define _LIBUTIL_BITARR_H_
40 
41 #include <assert.h>
42 #include <string.h>
43 #include <stdint.h>
44 
45 #include <sphinxbase/prim_type.h>
46 /* Win32/WinCE DLL gunk */
47 #include <sphinxbase/sphinxbase_export.h>
48 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 #if 0
60 /* Fool Emacs. */
61 }
62 #endif
63 
67 typedef struct bitarr_mask_s {
68  uint8 bits;
69  uint32 mask;
71 
75 typedef struct bitarr_address_s {
76  void *base;
77  uint32 offset;
79 
88 SPHINXBASE_EXPORT
89 uint64
90 bitarr_read_int57(bitarr_address_t address, uint8 length, uint64 mask);
91 
100 SPHINXBASE_EXPORT
101 void
102 bitarr_write_int57(bitarr_address_t address, uint8 length, uint64 value);
103 
112 SPHINXBASE_EXPORT
113 uint32
114 bitarr_read_int25(bitarr_address_t address, uint8 length, uint32 mask);
115 
124 SPHINXBASE_EXPORT
125 void
126 bitarr_write_int25(bitarr_address_t address, uint8 length, uint32 value);
127 
134 SPHINXBASE_EXPORT
135 float
137 
144 SPHINXBASE_EXPORT
145 void
146 bitarr_write_negfloat(bitarr_address_t address, float value);
147 
153 SPHINXBASE_EXPORT
154 float
156 
162 SPHINXBASE_EXPORT
163 void
164 bitarr_write_float(bitarr_address_t address, float value);
165 
171 SPHINXBASE_EXPORT
172 void
173 bitarr_mask_from_max(bitarr_mask_t *bit_mask, uint32 max_value);
174 
180 SPHINXBASE_EXPORT
181 uint8
182 bitarr_required_bits(uint32 max_value);
183 
184 #ifdef __cplusplus
185 }
186 #endif
187 
188 #endif /* _LIBUTIL_BITARR_H_ */
SPHINXBASE_EXPORT void bitarr_write_negfloat(bitarr_address_t address, float value)
Writes non positive float32 to bit array.
Definition: bitarr.c:150
SPHINXBASE_EXPORT void bitarr_mask_from_max(bitarr_mask_t *bit_mask, uint32 max_value)
Fills mask for certain int range according to provided max value.
Definition: bitarr.c:172
SPHINXBASE_EXPORT uint8 bitarr_required_bits(uint32 max_value)
Computes amount of bits required ti store integers upto value provided.
Definition: bitarr.c:178
struct bitarr_mask_s bitarr_mask_t
Structure that specifies bits required to efficiently store certain data.
Basic type definitions used in Sphinx.
SPHINXBASE_EXPORT float bitarr_read_negfloat(bitarr_address_t address)
Read non positive float32 from bit array.
Definition: bitarr.c:141
SPHINXBASE_EXPORT void bitarr_write_int25(bitarr_address_t address, uint8 length, uint32 value)
Write specified value into bit array.
Definition: bitarr.c:128
Structure that stores address of certain value in bit array.
Definition: bitarr.h:75
SPHINXBASE_EXPORT uint32 bitarr_read_int25(bitarr_address_t address, uint8 length, uint32 mask)
Read uint32 value from bit array.
Definition: bitarr.c:116
SPHINXBASE_EXPORT void bitarr_write_float(bitarr_address_t address, float value)
Writes float32 to bit array.
Definition: bitarr.c:165
SPHINXBASE_EXPORT void bitarr_write_int57(bitarr_address_t address, uint8 length, uint64 value)
Write specified value into bit array.
Definition: bitarr.c:103
Structure that specifies bits required to efficiently store certain data.
Definition: bitarr.h:67
SPHINXBASE_EXPORT float bitarr_read_float(bitarr_address_t address)
Reads float32 from bit array.
Definition: bitarr.c:158
struct bitarr_address_s bitarr_address_t
Structure that stores address of certain value in bit array.
SPHINXBASE_EXPORT uint64 bitarr_read_int57(bitarr_address_t address, uint8 length, uint64 mask)
Read uint64 value from bit array.
Definition: bitarr.c:98