M4RI  20140914
graycode.h
Go to the documentation of this file.
1 
12 #ifndef M4RI_GRAYFLEX_H
13 #define M4RI_GRAYFLEX_H
14 
15 /******************************************************************************
16 *
17 * M4RI: Linear Algebra over GF(2)
18 *
19 * Copyright (C) 2007 Gregory Bard <gregory.bard@ieee.org>
20 * Copyright (C) 2007 Martin Albrecht <malb@informatik.uni-bremen.de>
21 *
22 * Distributed under the terms of the GNU General Public License (GPL)
23 * version 2 or higher.
24 *
25 * This code is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * General Public License for more details.
29 *
30 * The full text of the GPL is available at:
31 *
32 * http://www.gnu.org/licenses/
33 ******************************************************************************/
34 
39 #define __M4RI_MAXKAY 16
40 
65 typedef struct {
69  int *ord;
73  int *inc;
74 } code;
75 
82 extern code **m4ri_codebook;
83 
93 int m4ri_gray_code(int i, int l);
94 
107 void m4ri_build_code(int *ord, int *inc, int l);
108 
118 void m4ri_build_all_codes(void);
119 
129 void m4ri_destroy_all_codes(void);
130 
135 static inline int log2_floor(int v) {
136  static unsigned const int b[] = { 0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000 };
137  static unsigned const int S[] = { 1, 2, 4, 8, 16 };
138  unsigned int r = 0;
139  for (int i = 4; i >= 0; --i)
140  {
141  if ((v & b[i]))
142  {
143  v >>= S[i];
144  r |= S[i];
145  }
146  }
147  return r;
148 }
149 
150 
166 int m4ri_opt_k(int a,int b,int c);
167 
168 #endif // M4RI_GRAYFLEX_H
int m4ri_gray_code(int i, int l)
Definition: graycode.c:31
void m4ri_build_code(int *ord, int *inc, int l)
Definition: graycode.c:42
int * ord
Definition: graycode.h:69
int m4ri_opt_k(int a, int b, int c)
Return the optimal var k for the given parameters.
Definition: graycode.c:82
void m4ri_destroy_all_codes(void)
Definition: graycode.c:68
code ** m4ri_codebook
Definition: graycode.c:29
static int log2_floor(int v)
Definition: graycode.h:135
Gray codes.
Definition: graycode.h:65
int * inc
Definition: graycode.h:73
void m4ri_build_all_codes(void)
Generates global code book.
Definition: graycode.c:54