Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
mie::ZmZ< V, Tag > Class Template Reference

#include <zm.h>

Inheritance diagram for mie::ZmZ< V, Tag >:
Collaboration diagram for mie::ZmZ< V, Tag >:

Public Types

typedef void base_type
 
typedef V::value_type value_type
 

Public Member Functions

 ZmZ (int x=0)
 
 ZmZ (const std::string &str)
 
 ZmZ (const V &rhs)
 
void set (const ZmZ &x)
 
void set (int x)
 
void set (const std::string &str)
 
void set (const uint32_t *x, size_t size)
 
void set (const uint64_t *x, size_t size)
 
void set (const V &rhs)
 
bool isZero () const
 
void clear ()
 
const Vget () const
 
std::string toString (int base=10) const
 
const value_typeoperator[] (size_t i) const
 
value_typeoperator[] (size_t i)
 
size_t size () const
 
- Public Member Functions inherited from mie::local::addsubmul< ZmZ< Vuint, Vuint >, local::comparable< ZmZ< Vuint, Vuint >, local::hasNegative< ZmZ< Vuint, Vuint >, local::inversible< ZmZ< Vuint, Vuint > > > > >
MIE_FORCE_INLINE ZmZ< Vuint, Vuint > & operator+= (const N &rhs)
 
MIE_FORCE_INLINE ZmZ< Vuint, Vuint > & operator-= (const ZmZ< Vuint, Vuint > &rhs)
 
MIE_FORCE_INLINE ZmZ< Vuint, Vuint > & operator*= (const ZmZ< Vuint, Vuint > &rhs)
 
- Public Member Functions inherited from mie::local::hasNegative< ZmZ< Vuint, Vuint >, local::inversible< ZmZ< Vuint, Vuint > > >
MIE_FORCE_INLINE ZmZ< Vuint, Vuintoperator- () const
 
- Public Member Functions inherited from mie::local::inversible< ZmZ< Vuint, Vuint > >
MIE_FORCE_INLINE void inverse ()
 
MIE_FORCE_INLINE ZmZ< Vuint, Vuint > & operator/= (const ZmZ< Vuint, Vuint > &x)
 

Static Public Member Functions

static int compare (const ZmZ &x, const ZmZ &y)
 
static void add (ZmZ &out, const ZmZ &x, const ZmZ &y)
 
static void sub (ZmZ &out, const ZmZ &x, const ZmZ &y)
 
static void neg (ZmZ &out, const ZmZ &x)
 
static void mul (ZmZ &out, const ZmZ &x, const ZmZ &y)
 
static void inv (ZmZ &out, const ZmZ &x)
 
static void setModulo (const V &m)
 
static const VgetModulo ()
 

Friends

std::ostream & operator<< (std::ostream &os, const ZmZ &x)
 

Detailed Description

template<class V = Vuint, class Tag = Vuint>
class mie::ZmZ< V, Tag >

Z/mZ class by Vuint

Note
Tag is prepared for multi instances of different m

Definition at line 1169 of file zm.h.

Member Typedef Documentation

◆ base_type

template<class V = Vuint, class Tag = Vuint>
void mie::ZmZ< V, Tag >::base_type

Definition at line 1174 of file zm.h.

◆ value_type

template<class V = Vuint, class Tag = Vuint>
V::value_type mie::ZmZ< V, Tag >::value_type

Definition at line 1175 of file zm.h.

Constructor & Destructor Documentation

◆ ZmZ() [1/3]

template<class V = Vuint, class Tag = Vuint>
mie::ZmZ< V, Tag >::ZmZ ( int x = 0)
inline

Definition at line 1184 of file zm.h.

1185 {
1186 set(x);
1187 }
bool set

◆ ZmZ() [2/3]

template<class V = Vuint, class Tag = Vuint>
mie::ZmZ< V, Tag >::ZmZ ( const std::string & str)
inlineexplicit

Definition at line 1188 of file zm.h.

1189 {
1190 set(str);
1191 }

◆ ZmZ() [3/3]

template<class V = Vuint, class Tag = Vuint>
mie::ZmZ< V, Tag >::ZmZ ( const V & rhs)
inline

Definition at line 1192 of file zm.h.

1193 : v_(rhs)
1194 {
1195 modulo();
1196 }

Member Function Documentation

◆ add()

template<class V = Vuint, class Tag = Vuint>
static void mie::ZmZ< V, Tag >::add ( ZmZ< V, Tag > & out,
const ZmZ< V, Tag > & x,
const ZmZ< V, Tag > & y )
inlinestatic

Definition at line 1236 of file zm.h.

1237 {
1238 V::add(out.v_, x.v_, y.v_);
1239 if (out.v_ >= m_) {
1240 out.v_ -= m_;
1241 }
1242 }
uint64_t y
Definition sha3.cpp:34

◆ clear()

template<class V = Vuint, class Tag = Vuint>
void mie::ZmZ< V, Tag >::clear ( )
inline

Definition at line 1287 of file zm.h.

1287{ v_ = 0; }

◆ compare()

template<class V = Vuint, class Tag = Vuint>
static int mie::ZmZ< V, Tag >::compare ( const ZmZ< V, Tag > & x,
const ZmZ< V, Tag > & y )
inlinestatic

Definition at line 1232 of file zm.h.

1233 {
1234 return V::compare(x.v_, y.v_);
1235 }

◆ get()

template<class V = Vuint, class Tag = Vuint>
const V & mie::ZmZ< V, Tag >::get ( ) const
inline

Definition at line 1288 of file zm.h.

1288{ return v_; }

◆ getModulo()

template<class V = Vuint, class Tag = Vuint>
static const V & mie::ZmZ< V, Tag >::getModulo ( )
inlinestatic

Definition at line 1335 of file zm.h.

1336 {
1337 return m_;
1338 }

◆ inv()

template<class V = Vuint, class Tag = Vuint>
static void mie::ZmZ< V, Tag >::inv ( ZmZ< V, Tag > & out,
const ZmZ< V, Tag > & x )
inlinestatic

Definition at line 1292 of file zm.h.

1293 {
1294 assert(!x.isZero());
1295 ZmZ a = 1;
1296 if (a.v_ == x.v_) {
1297 out = a;
1298 return;
1299 }
1300
1301 V t;
1302 ZmZ q;
1303 V::div(&q.v_, t, m_, x.v_);
1304 assert(!t.isZero()); // because m_ is prime
1305 V s = x.v_;
1306 ZmZ b = -q;
1307
1308 for (;;) {
1309 V::div(&q.v_, s, s, t);
1310 if (s.isZero()) {
1311 out = b;
1312 return;
1313 }
1314 a -= b * q;
1315
1316 V::div(&q.v_, t, t, s);
1317 if (t.isZero()) {
1318 out = a;
1319 return;
1320 }
1321 b -= a * q;
1322 }
1323 }
ZmZ(int x=0)
Definition zm.h:1184
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
Definition test_zm.cpp:19
char * s
Here is the call graph for this function:

◆ isZero()

template<class V = Vuint, class Tag = Vuint>
bool mie::ZmZ< V, Tag >::isZero ( ) const
inline

Definition at line 1286 of file zm.h.

1286{ return v_.isZero(); }
Here is the caller graph for this function:

◆ mul()

template<class V = Vuint, class Tag = Vuint>
static void mie::ZmZ< V, Tag >::mul ( ZmZ< V, Tag > & out,
const ZmZ< V, Tag > & x,
const ZmZ< V, Tag > & y )
inlinestatic

Definition at line 1265 of file zm.h.

1266 {
1267#if 0 // for only FixedBuffer(this code is dangerous and not good)
1268 const size_t xn = x.size();
1269 const size_t yn = y.size();
1270
1271 V *t = new(MIE_ALLOCA_(sizeof(value_type) * (xn + yn))) V;
1272 t->forceAlloc(xn + yn);
1273 V::mul(&(*t)[0], &x[0], xn, &y[0], yn);
1274 t->trim();
1275 V::div(0, out.v_, *t, m_);
1276 out.v_.trim();
1277#else
1278 V::mul(out.v_, x.v_, y.v_);
1279 out.modulo();
1280#endif
1281 }
V::value_type value_type
Definition zm.h:1175
#define MIE_ALLOCA_(x)
Definition zm.h:56
Here is the call graph for this function:

◆ neg()

template<class V = Vuint, class Tag = Vuint>
static void mie::ZmZ< V, Tag >::neg ( ZmZ< V, Tag > & out,
const ZmZ< V, Tag > & x )
inlinestatic

Definition at line 1257 of file zm.h.

1258 {
1259 if (x.isZero()) {
1260 out = x;
1261 } else {
1262 V::sub(out.v_, m_, x.v_);
1263 }
1264 }
Here is the call graph for this function:

◆ operator[]() [1/2]

template<class V = Vuint, class Tag = Vuint>
value_type & mie::ZmZ< V, Tag >::operator[] ( size_t i)
inline

Definition at line 1329 of file zm.h.

1329{ return v_[i]; }

◆ operator[]() [2/2]

template<class V = Vuint, class Tag = Vuint>
const value_type & mie::ZmZ< V, Tag >::operator[] ( size_t i) const
inline

Definition at line 1328 of file zm.h.

1328{ return v_[i]; }

◆ set() [1/6]

template<class V = Vuint, class Tag = Vuint>
void mie::ZmZ< V, Tag >::set ( const std::string & str)
inline

Definition at line 1212 of file zm.h.

1213 {
1214 v_.set(str);
1215 modulo();
1216 }

◆ set() [2/6]

template<class V = Vuint, class Tag = Vuint>
void mie::ZmZ< V, Tag >::set ( const uint32_t * x,
size_t size )
inline

Definition at line 1217 of file zm.h.

1218 {
1219 v_.set(x, size);
1220 modulo();
1221 }
size_t size() const
Definition zm.h:1330
Here is the call graph for this function:

◆ set() [3/6]

template<class V = Vuint, class Tag = Vuint>
void mie::ZmZ< V, Tag >::set ( const uint64_t * x,
size_t size )
inline

Definition at line 1222 of file zm.h.

1223 {
1224 v_.set(x, size);
1225 modulo();
1226 }
Here is the call graph for this function:

◆ set() [4/6]

template<class V = Vuint, class Tag = Vuint>
void mie::ZmZ< V, Tag >::set ( const V & rhs)
inline

Definition at line 1227 of file zm.h.

1228 {
1229 v_ = rhs;
1230 modulo();
1231 }

◆ set() [5/6]

template<class V = Vuint, class Tag = Vuint>
void mie::ZmZ< V, Tag >::set ( const ZmZ< V, Tag > & x)
inline

Definition at line 1197 of file zm.h.

1197{ v_ = x.v_; }
Here is the caller graph for this function:

◆ set() [6/6]

template<class V = Vuint, class Tag = Vuint>
void mie::ZmZ< V, Tag >::set ( int x)
inline

Definition at line 1198 of file zm.h.

1199 {
1200 if (x == 0) {
1201 v_.clear();
1202 } else if (x > 0) {
1203 v_.set(x);
1204 } else {
1205 if (x == -2147483647 - 1 || m_ < -x) {
1206 local::errExit("x is too small");
1207 }
1208 v_ = m_;
1209 v_ -= -x;
1210 }
1211 }

◆ setModulo()

template<class V = Vuint, class Tag = Vuint>
static void mie::ZmZ< V, Tag >::setModulo ( const V & m)
inlinestatic

Definition at line 1331 of file zm.h.

1332 {
1333 m_ = m;
1334 }
Here is the caller graph for this function:

◆ size()

template<class V = Vuint, class Tag = Vuint>
size_t mie::ZmZ< V, Tag >::size ( ) const
inline

Definition at line 1330 of file zm.h.

1330{ return v_.size(); }
Here is the caller graph for this function:

◆ sub()

template<class V = Vuint, class Tag = Vuint>
static void mie::ZmZ< V, Tag >::sub ( ZmZ< V, Tag > & out,
const ZmZ< V, Tag > & x,
const ZmZ< V, Tag > & y )
inlinestatic

Definition at line 1243 of file zm.h.

1244 {
1245 if (x.v_ < y.v_) {
1246 if (&out != &y) {
1247 V::add(out.v_, x.v_, m_);
1248 out.v_ -= y.v_;
1249 } else {
1250 V t = x.v_ + m_;
1251 out.v_ = t - y.v_;
1252 }
1253 } else {
1254 V::sub(out.v_, x.v_, y.v_);
1255 }
1256 }
Here is the caller graph for this function:

◆ toString()

template<class V = Vuint, class Tag = Vuint>
std::string mie::ZmZ< V, Tag >::toString ( int base = 10) const
inline

Definition at line 1324 of file zm.h.

1325 {
1326 return v_.toString(base);
1327 }
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<<

template<class V = Vuint, class Tag = Vuint>
std::ostream & operator<< ( std::ostream & os,
const ZmZ< V, Tag > & x )
friend

Definition at line 1282 of file zm.h.

1283 {
1284 return os << x.v_;
1285 }
os_t os

The documentation for this class was generated from the following file: