M4RI 20200125
graycode.h
Go to the documentation of this file.
1
11
12#ifndef M4RI_GRAYFLEX_H
13#define M4RI_GRAYFLEX_H
14
15#ifdef HAVE_CONFIG_H
16 #include "config.h"
17#endif
18
19#ifdef _WIN32
20 #if defined(DLL_EXPORT) && defined(M4RI_BUILDING_M4RI)
21 #define M4RI_DLL_EXPORT __declspec(dllexport)
22 #elif defined(M4RI_USE_DLL) && !defined(M4RI_BUILDING_M4RI)
23 #define M4RI_DLL_EXPORT __declspec(dllimport)
24 #else
25 #define M4RI_DLL_EXPORT
26 #endif
27#else
28 #define M4RI_DLL_EXPORT
29#endif
30
31/******************************************************************************
32*
33* M4RI: Linear Algebra over GF(2)
34*
35* Copyright (C) 2007 Gregory Bard <gregory.bard@ieee.org>
36* Copyright (C) 2007 Martin Albrecht <malb@informatik.uni-bremen.de>
37*
38* Distributed under the terms of the GNU General Public License (GPL)
39* version 2 or higher.
40*
41* This code is distributed in the hope that it will be useful,
42* but WITHOUT ANY WARRANTY; without even the implied warranty of
43* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44* General Public License for more details.
45*
46* The full text of the GPL is available at:
47*
48* http://www.gnu.org/licenses/
49******************************************************************************/
50
54
55#define __M4RI_MAXKAY 16
56
80
81typedef struct {
85 int *ord;
89 int *inc;
90} code;
91
97
98M4RI_DLL_EXPORT extern code **m4ri_codebook;
99
108
109int m4ri_gray_code(int i, int l);
110
122
123void m4ri_build_code(int *ord, int *inc, int l);
124
133
134void m4ri_build_all_codes(void);
135
144
145void m4ri_destroy_all_codes(void);
146
150
151static inline int log2_floor(int v) {
152 static unsigned const int b[] = { 0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000 };
153 static unsigned const int S[] = { 1, 2, 4, 8, 16 };
154 unsigned int r = 0;
155 for (int i = 4; i >= 0; --i)
156 {
157 if ((v & b[i]))
158 {
159 v >>= S[i];
160 r |= S[i];
161 }
162 }
163 return r;
164}
165
166
181
182int m4ri_opt_k(int a,int b,int c);
183
184#endif // M4RI_GRAYFLEX_H
int m4ri_opt_k(int a, int b, int c)
Return the optimal var k for the given parameters.
Definition graycode.c:82
int m4ri_gray_code(int i, int l)
Definition graycode.c:31
void m4ri_destroy_all_codes(void)
Definition graycode.c:68
void m4ri_build_all_codes(void)
Generates global code book.
Definition graycode.c:54
void m4ri_build_code(int *ord, int *inc, int l)
Definition graycode.c:42
static int log2_floor(int v)
Definition graycode.h:151
Gray codes.
Definition graycode.h:81
int * ord
Definition graycode.h:85
int * inc
Definition graycode.h:89