Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
bn::util Namespace Reference

Functions

template<class T >
void put (const T &x, size_t len)
 
template<class T >
void put (const T &x)
 
template<class Vec >
void convertToBinary (Vec &v, const mie::Vuint &x)
 
template<class Vec >
size_t getContinuousVal (const Vec &v, size_t pos, int val)
 
template<class Vec >
void convertToNAF (Vec &v, const Vec &in)
 
template<class Vec >
size_t getNumOfNonZeroElement (const Vec &v)
 
template<class Vec >
bool getGoodRepl (Vec &v, const mie::Vuint &x)
 

Function Documentation

◆ convertToBinary()

template<class Vec >
void bn::util::convertToBinary ( Vec & v,
const mie::Vuint & x )

Definition at line 103 of file bn.h.

104{
105 const size_t len = x.bitLen();
106 v.clear();
107 for (size_t i = 0; i < len; i++) {
108 v.push_back(x.testBit(len - 1 - i) ? 1 : 0);
109 }
110}
size_t bitLen() const
Definition zm.h:526
bool testBit(size_t i) const
Definition zm.h:539
size_t len
Here is the call graph for this function:
Here is the caller graph for this function:

◆ convertToNAF()

template<class Vec >
void bn::util::convertToNAF ( Vec & v,
const Vec & in )

Definition at line 121 of file bn.h.

122{
123 v = in;
124 size_t pos = v.size() - 1;
125 for (;;) {
126 size_t p = getContinuousVal(v, pos, 0);
127 if (p == 1) return;
128 assert(v[p] == 1);
129 size_t q = getContinuousVal(v, p, 1);
130 if (q == 1) return;
131 assert(v[q] == 0);
132 if (p - q <= 1) {
133 pos = p - 1;
134 continue;
135 }
136 v[q] = 1;
137 for (size_t i = q + 1; i < p; i++) {
138 v[i] = 0;
139 }
140 v[p] = -1;
141 pos = q;
142 }
143}
const mie::Vuint & p
Definition bn.cpp:27
size_t getContinuousVal(const Vec &v, size_t pos, int val)
Definition bn.h:112
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getContinuousVal()

template<class Vec >
size_t bn::util::getContinuousVal ( const Vec & v,
size_t pos,
int val )

Definition at line 112 of file bn.h.

113{
114 while (pos >= 2) {
115 if (v[pos] != val) break;
116 pos--;
117 }
118 return pos;
119}
Here is the caller graph for this function:

◆ getGoodRepl()

template<class Vec >
bool bn::util::getGoodRepl ( Vec & v,
const mie::Vuint & x )

Definition at line 159 of file bn.h.

160{
161 Vec bin;
162 util::convertToBinary(bin, x);
163 Vec naf;
164 util::convertToNAF(naf, bin);
165 const size_t binW = util::getNumOfNonZeroElement(bin);
166 const size_t nafW = util::getNumOfNonZeroElement(naf);
167 if (nafW < binW) {
168 v.swap(naf);
169 return true;
170 } else {
171 v.swap(bin);
172 return false;
173 }
174}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNumOfNonZeroElement()

template<class Vec >
size_t bn::util::getNumOfNonZeroElement ( const Vec & v)

Definition at line 145 of file bn.h.

146{
147 size_t w = 0;
148 for (size_t i = 0; i < v.size(); i++) {
149 if (v[i]) w++;
150 }
151 return w;
152}
Here is the caller graph for this function:

◆ put() [1/2]

template<class T >
void bn::util::put ( const T & x)

Definition at line 98 of file bn.h.

99{
100 put(x, x.size());
101}
void put()
Definition gen_code.cpp:234
Here is the call graph for this function:

◆ put() [2/2]

template<class T >
void bn::util::put ( const T & x,
size_t len )

Definition at line 90 of file bn.h.

91{
92 for (size_t i = 0; i < len; i++) {
93 printf("% 2d,", x[i]);
94 }
95 printf("\n");
96}