ABY Framework  1.0
Arithmetic Bool Yao Framework
 All Classes Files Functions Variables Enumerations Enumerator Macros
graycode.h
Go to the documentation of this file.
1 
12 #ifndef GRAYCODE_H_
13 #define GRAYCODE_H_
14 
15 #include "typedefs.h"
16 
17 /******************************************************************************
18  *
19  * M4RI: Linear Algebra over GF(2)
20  *
21  * Copyright (C) 2007 Gregory Bard <gregory.bard@ieee.org>
22  * Copyright (C) 2007 Martin Albrecht <malb@informatik.uni-bremen.de>
23  *
24  * Distributed under the terms of the GNU General Public License (GPL)
25  * version 2 or higher.
26  *
27  * This code is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30  * General Public License for more details.
31  *
32  * The full text of the GPL is available at:
33  *
34  * http://www.gnu.org/licenses/
35  ******************************************************************************/
36 
61 typedef struct {
65  int *ord;
69  int *inc;
70 } code;
71 
81 int gray_code(int i, int l);
82 
95 code* build_code(int l);
96 
106 void destroy_code(code* codebook);
107 
112 static inline int log2_floor(int v) {
113  static unsigned const int b[] = { 0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000 };
114  static unsigned const int S[] = { 1, 2, 4, 8, 16 };
115  unsigned int r = 0;
116  for (int i = 4; i >= 0; --i) {
117  if ((v & b[i])) {
118  v >>= S[i];
119  r |= S[i];
120  }
121  }
122  return r;
123 }
124 
125 #endif /* GRAYCODE_H_ */
int * ord
Definition: graycode.h:65
code * build_code(int l)
Definition: graycode.cpp:35
Gray codes.
Definition: graycode.h:61
int * inc
Definition: graycode.h:69
Typedefs Implementation.
int gray_code(int i, int l)
Definition: graycode.cpp:24
void destroy_code(code *codebook)
Definition: graycode.cpp:54