Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
mie::VuintT< Buffer > Struct Template Reference

#include <zm.h>

Inheritance diagram for mie::VuintT< Buffer >:
Collaboration diagram for mie::VuintT< Buffer >:

Public Types

typedef local::PrimitiveFunction F
 
typedef Buffer::value_type T
 

Public Member Functions

 VuintT (T x=0)
 
 VuintT (const std::string &str)
 
 VuintT (const uint32_t *x, size_t size)
 
 VuintT (const uint64_t *x, size_t size)
 
void set (T x)
 
void set (const uint32_t *x, size_t size)
 
void set (const uint64_t *x, size_t size)
 
T getAtWithCheck (size_t i) const
 
void clear ()
 
std::string toString (int base=10) const
 
void set (const std::string &str, int base=0)
 
void fromStr (const std::string &str, int base=10)
 
std::string toStr (int base=10) const
 
size_t size () const
 
bool isZero () const
 
size_t bitLen () const
 
bool testBit (size_t i) const
 
void trim ()
 
- Public Member Functions inherited from mie::local::dividable< VuintT< Buffer >, local::addsubmul< VuintT< Buffer >, local::comparable< VuintT< Buffer >, local::shiftable< VuintT< Buffer >, Buffer > > > >
MIE_FORCE_INLINE VuintT< Buffer > & operator/= (const VuintT< Buffer > &rhs)
 
MIE_FORCE_INLINE VuintT< Buffer > & operator%= (const VuintT< Buffer > &rhs)
 
- Public Member Functions inherited from mie::local::addsubmul< VuintT< Buffer >, local::comparable< VuintT< Buffer >, local::shiftable< VuintT< Buffer >, Buffer > > >
MIE_FORCE_INLINE VuintT< Buffer > & operator+= (const N &rhs)
 
MIE_FORCE_INLINE VuintT< Buffer > & operator-= (const VuintT< Buffer > &rhs)
 
MIE_FORCE_INLINE VuintT< Buffer > & operator*= (const VuintT< Buffer > &rhs)
 
- Public Member Functions inherited from mie::local::shiftable< VuintT< Buffer >, Buffer >
MIE_FORCE_INLINE VuintT< Buffer > operator<< (size_t n) const
 
MIE_FORCE_INLINE VuintT< Buffer > operator>> (size_t n) const
 
MIE_FORCE_INLINE VuintT< Buffer > & operator<<= (size_t n)
 
MIE_FORCE_INLINE VuintT< Buffer > & operator>>= (size_t n)
 

Static Public Member Functions

static int compare (const VuintT &x, const VuintT &y)
 
static bool add_in (VuintT &out, const VuintT &x, const VuintT &y)
 
static void add (VuintT &out, const VuintT &x, const VuintT &y)
 
static void add (VuintT &out, const VuintT &x, uint32_t y)
 
static bool sub_in (VuintT &out, const VuintT &x, const VuintT &y)
 
static void sub (VuintT &out, const VuintT &x, const VuintT &y)
 
static void mul1 (VuintT &out, const VuintT &x, T y)
 
static void mul (VuintT &out, const VuintT &x, const VuintT &y)
 
static T div1 (VuintT *q, const VuintT &x, T y)
 
static bool div (VuintT *q, VuintT &r, const VuintT &x, const VuintT &y)
 
static void shlUnit (VuintT &out, const VuintT &x, size_t n)
 
static void shlBit (VuintT &out, const VuintT &x, size_t n)
 
static void shrUnit (VuintT &out, const VuintT &x, size_t n)
 
static void shrBit (VuintT &out, const VuintT &x, size_t n)
 
static void shl (VuintT &out, const VuintT &x, size_t n)
 
static void shr (VuintT &out, const VuintT &x, size_t n)
 
static void mul (T *out, const T *x, size_t xn, const T *y, size_t yn)
 
static void div (T *q, T *x, size_t xn, const T *y, size_t yn)
 

Friends

std::ostream & operator<< (std::ostream &os, const VuintT &x)
 
std::istream & operator>> (std::istream &is, VuintT &x)
 

Detailed Description

template<class Buffer>
struct mie::VuintT< Buffer >

unsigned integer with variable length

Definition at line 318 of file zm.h.

Member Typedef Documentation

◆ F

template<class Buffer >
local::PrimitiveFunction mie::VuintT< Buffer >::F

Definition at line 322 of file zm.h.

◆ T

template<class Buffer >
Buffer::value_type mie::VuintT< Buffer >::T

Definition at line 323 of file zm.h.

Constructor & Destructor Documentation

◆ VuintT() [1/4]

template<class Buffer >
mie::VuintT< Buffer >::VuintT ( T x = 0)
inline

Definition at line 325 of file zm.h.

326 {
327 set(x);
328 }
bool set

◆ VuintT() [2/4]

template<class Buffer >
mie::VuintT< Buffer >::VuintT ( const std::string & str)
inlineexplicit

Definition at line 329 of file zm.h.

330 {
331 set(str);
332 }

◆ VuintT() [3/4]

template<class Buffer >
mie::VuintT< Buffer >::VuintT ( const uint32_t * x,
size_t size )
inline

Definition at line 333 of file zm.h.

334 {
335 set(x, size);
336 }
size_t size() const
Definition zm.h:519
Here is the call graph for this function:

◆ VuintT() [4/4]

template<class Buffer >
mie::VuintT< Buffer >::VuintT ( const uint64_t * x,
size_t size )
inline

Definition at line 337 of file zm.h.

338 {
339 set(x, size);
340 }
Here is the call graph for this function:

Member Function Documentation

◆ add() [1/2]

template<class Buffer >
static void mie::VuintT< Buffer >::add ( VuintT< Buffer > & out,
const VuintT< Buffer > & x,
const VuintT< Buffer > & y )
inlinestatic

Definition at line 564 of file zm.h.

565 {
566 bool c = add_in(out, x, y);
567 if (c) {
568 out.alloc(out.size() + 1);
569 out[out.size() - 1] = 1;
570 } else {
571 out.trim();
572 }
573 }
static bool add_in(VuintT &out, const VuintT &x, const VuintT &y)
Definition zm.h:547
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add() [2/2]

template<class Buffer >
static void mie::VuintT< Buffer >::add ( VuintT< Buffer > & out,
const VuintT< Buffer > & x,
uint32_t y )
inlinestatic

Definition at line 574 of file zm.h.

575 {
576 const size_t n = x.size();
577 out.alloc(n);
578 bool c = F::add1(&out[0], &x[0], n, y);
579 if (c) {
580 out.alloc(n + 1);
581 out[n] = 1;
582 }
583 }
Here is the call graph for this function:

◆ add_in()

template<class Buffer >
static bool mie::VuintT< Buffer >::add_in ( VuintT< Buffer > & out,
const VuintT< Buffer > & x,
const VuintT< Buffer > & y )
inlinestatic

Definition at line 547 of file zm.h.

548 {
549 const VuintT *px = &x;
550 const VuintT *py = &y;
551 if (y.size() > x.size()) {
552 std::swap(px, py);
553 }
554 size_t max = px->size();
555 size_t min = py->size();
556 out.alloc(max);
557 bool c = F::addN(&out[0], &(*px)[0], &(*py)[0], min);
558 if (max > min) {
559 c = F::add1(&out[min], &(*px)[min], max - min, c);
560 }
561 return c;
562 }
const T & min(const T &a, const T &b)
Definition utility.hpp:140
uint64_t y
Definition sha3.cpp:34
void swap(picojson::value &x, picojson::value &y)
VuintT(T x=0)
Definition zm.h:325
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bitLen()

template<class Buffer >
size_t mie::VuintT< Buffer >::bitLen ( ) const
inline

Definition at line 526 of file zm.h.

527 {
528 if (isZero()) return 0;
529
530 size_t size = this->size();
531 T v = (*this)[size - 1];
532 union di t;
533 t.f = (double)v;
534 size_t ret = 1 + (size_t(t.i >> 52) - (1 << 10) + 1) +
535 (size - 1) * sizeof(T) * 8;
536 return ret;
537 }
static const Reg16 di(Operand::DI)
bool isZero() const
Definition zm.h:521
Buffer::value_type T
Definition zm.h:323
CK_RV ret
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

template<class Buffer >
void mie::VuintT< Buffer >::clear ( )
inline

Definition at line 406 of file zm.h.

406{ set((T)0); }
Here is the caller graph for this function:

◆ compare()

template<class Buffer >
static int mie::VuintT< Buffer >::compare ( const VuintT< Buffer > & x,
const VuintT< Buffer > & y )
inlinestatic

Definition at line 515 of file zm.h.

516 {
517 return F::compare(&x[0], x.size(), &y[0], y.size());
518 }
Here is the call graph for this function:

◆ div() [1/2]

template<class Buffer >
static void mie::VuintT< Buffer >::div ( T * q,
T * x,
size_t xn,
const T * y,
size_t yn )
inlinestatic

Definition at line 926 of file zm.h.

927 {
928 assert(xn >= yn && yn >= 2);
929 if (q) {
930 std::fill(q, q + xn - yn + 1, 0);
931 }
932 Buffer t;
933 t.alloc(yn + 1);
934 double yt = GetApp(y, yn, true);
935 while (F::compare(x, xn, y, yn) >= 0) {
936 size_t len = yn;
937 double xt = GetApp(x, xn, false);
938 if (F::compare(&x[xn - len], yn, y, yn) < 0) {
939 xt *= double(1ULL << (sizeof(T) * 8 - 1)) * 2;
940 len++;
941 }
942 T qt = T(xt / yt);
943 if (qt == 0) qt = 1;
944 F::mul1(&t[0], y, yn, qt);
945 bool b = F::subN(&x[xn - len], &x[xn - len], &t[0], len);
946 if (b) {
947 assert(!b);
948 }
949 if (q) q[xn - len] += qt;
950
951 while (xn >= yn && x[xn - 1] == 0) {
952 xn--;
953 }
954 }
955 }
size_t len

◆ div() [2/2]

template<class Buffer >
static bool mie::VuintT< Buffer >::div ( VuintT< Buffer > * q,
VuintT< Buffer > & r,
const VuintT< Buffer > & x,
const VuintT< Buffer > & y )
inlinestatic
Parameters
q[out] x / y if q != 0
r[out] x % y
Return values
trueif y != 0 @retavl false if y == 0

Definition at line 661 of file zm.h.

662 {
663//std::cout << "x=" << x << std::endl;
664//std::cout << "y=" << y << std::endl;
665 assert(q != &r);
666 const size_t xn = x.size();
667 const size_t yn = y.size();
668 if (yn == 1) {
669 if (y[0] == 0) return false;
670 r.set(div1(q, x, y[0]));
671 return true;
672 }
673 int cmp = F::compare(&x[0], xn, &y[0], yn);
674 if (cmp < 0) {
675 if (&r != &x) {
676 r = x;
677 }
678 if (q) q->clear();
679 } else if (cmp == 0) {
680 // imply &x == &y
681 if (q) q->set(1);
682 r.clear();
683 } else {
684 assert(&x != &y);
685 VuintT qt;
686 Unit *pqt = 0;
687 bool directQ = false;
688 if (q == 0) {
689 pqt = 0;
690 } else if (q != &x && q != &y) {
691 q->alloc(xn - yn + 1);
692 pqt = &(*q)[0];
693 directQ = true;
694 } else {
695 qt.alloc(xn - yn + 1);
696 pqt = &qt[0];
697 }
698 VuintT rt;
699 Unit *prt = 0;
700 bool directR = false;
701 if (&r != &x && &r != &y) {
702 r = x;
703 directR = true;
704 prt = &r[0];
705 } else {
706 rt = x;
707 prt = &rt[0];
708 }
709 div(pqt, prt, xn, &y[0], yn);
710 if (q) {
711 if (directQ) {
712 q->trim();
713 } else {
714 qt.trim();
715 q->moveFrom(qt);
716 }
717 }
718 if (directR) {
719 r.trim();
720 } else {
721 rt.trim();
722 r.moveFrom(rt);
723 }
724 }
725//puts("out");
726 return true;
727 }
const mie::Vuint & r
Definition bn.cpp:28
uint32_t Unit
Definition zm.h:66
static T div1(VuintT *q, const VuintT &x, T y)
Definition zm.h:642
void clear()
Definition zm.h:406
void set(T x)
Definition zm.h:341
void trim()
Definition zm.h:894
static bool div(VuintT *q, VuintT &r, const VuintT &x, const VuintT &y)
Definition zm.h:661
void cmp(const Operand &op, uint32 imm)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ div1()

template<class Buffer >
static T mie::VuintT< Buffer >::div1 ( VuintT< Buffer > * q,
const VuintT< Buffer > & x,
T y )
inlinestatic
Parameters
q[out] q = x / y
x[in]
y[in] must be not zero
Returns
x % y

Definition at line 642 of file zm.h.

643 {
644 const size_t xn = x.size();
645 T r;
646 if (q) {
647 q->alloc(xn); // assume q is not destroyed if q == x
648 r = F::div1(&(*q)[0], &x[0], xn, y);
649 q->trim();
650 } else {
651 r = F::mod1(&x[0], xn, y);
652 }
653 return r;
654 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromStr()

template<class Buffer >
void mie::VuintT< Buffer >::fromStr ( const std::string & str,
int base = 10 )
inline

Definition at line 510 of file zm.h.

511 {
512 set(str, base);
513 }

◆ getAtWithCheck()

template<class Buffer >
T mie::VuintT< Buffer >::getAtWithCheck ( size_t i) const
inline

Definition at line 397 of file zm.h.

398 {
399 if (i >= this->size()) {
400 return 0;
401 } else {
402 return (*this)[i];
403 }
404 }
Here is the call graph for this function:

◆ isZero()

template<class Buffer >
bool mie::VuintT< Buffer >::isZero ( ) const
inline

Definition at line 521 of file zm.h.

522 {
523 return Buffer::size() == 1 && (*this)[0] == 0;
524 }
Here is the caller graph for this function:

◆ mul() [1/2]

template<class Buffer >
static void mie::VuintT< Buffer >::mul ( T * out,
const T * x,
size_t xn,
const T * y,
size_t yn )
inlinestatic

Definition at line 904 of file zm.h.

905 {
906 assert(xn > 0 && yn > 0);
907 if (yn > xn) {
908 std::swap(yn, xn);
909 std::swap(x, y);
910 }
911
912 std::fill(&out[xn + 1], &out[xn + yn], 0);
913 F::mul1(&out[0], x, xn, y[0]);
914
915#if 1
916 T *t2 = (T*)MIE_ALLOCA_(sizeof(T) * (xn + 1));
917#else
918 Buffer t2;
919 t2.alloc(xn + 1);
920#endif
921 for (size_t i = 1; i < yn; i++) {
922 F::mul1(&t2[0], x, xn, y[i]);
923 F::addN(&out[i], &out[i], &t2[0], xn + 1);
924 }
925 }
#define MIE_ALLOCA_(x)
Definition zm.h:56
Here is the call graph for this function:

◆ mul() [2/2]

template<class Buffer >
static void mie::VuintT< Buffer >::mul ( VuintT< Buffer > & out,
const VuintT< Buffer > & x,
const VuintT< Buffer > & y )
inlinestatic

Definition at line 613 of file zm.h.

614 {
615 const size_t xn = x.size();
616 const size_t yn = y.size();
617
618 VuintT xt, yt;
619 const Unit *px = &x[0], *py = &y[0];
620 if (&out == &x) {
621 xt = x;
622 px = &xt[0];
623 }
624 if (&out == &y) {
625 if (&x == &y) {
626 py = px;
627 } else {
628 yt = y;
629 py = &yt[0];
630 }
631 }
632 out.alloc(xn + yn);
633 mul(&out[0], px, xn, py, yn);
634 out.trim();
635 }
static void mul(VuintT &out, const VuintT &x, const VuintT &y)
Definition zm.h:613
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mul1()

template<class Buffer >
static void mie::VuintT< Buffer >::mul1 ( VuintT< Buffer > & out,
const VuintT< Buffer > & x,
T y )
inlinestatic

Definition at line 606 of file zm.h.

607 {
608 const size_t xn = x.size();
609 out.alloc(xn + 1);
610 F::mul1(&out[0], &x[0], xn, y);
611 out.trim();
612 }
Here is the call graph for this function:

◆ set() [1/4]

template<class Buffer >
void mie::VuintT< Buffer >::set ( const std::string & str,
int base = 0 )
inline

Definition at line 452 of file zm.h.

453 {
454 std::string t;
455 if (str.size() >= 2 && str[0] == '0') {
456 switch (str[1]) {
457 case 'x':
458 if (base != 0 && base != 16) local::errExit("bad base in set(str)");
459 base = 16;
460 t = str.substr(2);
461 break;
462 default:
463 local::errExit("not support base in set(str) 0x");
464 }
465 }
466 if (base == 0) {
467 base = 10;
468 }
469 if (t.empty()) t = str;
470
471 switch (base) {
472 case 16:
473 {
474 std::vector<uint32_t> x;
475 while (!t.empty()) {
476 size_t remain = std::min((int)t.size(), 8);
477 char *endp;
478 uint32_t v = strtoul(&t[t.size() - remain], &endp, 16);
479 if (*endp) goto ERR;
480 x.push_back(v);
481 t = t.substr(0, t.size() - remain);
482 }
483 set(&x[0], x.size());
484 }
485 break;
486 default:
487 case 10:
488 {
489 std::vector<uint32_t> x;
490 while (!t.empty()) {
491 size_t remain = std::min((int)t.size(), 9);
492 char *endp;
493 uint32_t v = strtol(&t[t.size() - remain], &endp, 10);
494 if (*endp) goto ERR;
495 x.push_back(v);
496 t = t.substr(0, t.size() - remain);
497 }
498 clear();
499 for (size_t i = 0, n = x.size(); i < n; i++) {
500 (*this) *= 1000000000;
501 (*this) += x[n - 1 - i];
502 }
503 }
504 break;
505 }
506 return;
507 ERR:
508 throw std::invalid_argument(std::string("bad digit `") + str + "`");
509 }
#define ERR(name, desc)
Definition error.c:21
return str
Definition CLI11.hpp:1359
unsigned int uint32_t
Definition stdint.h:126
Here is the call graph for this function:

◆ set() [2/4]

template<class Buffer >
void mie::VuintT< Buffer >::set ( const uint32_t * x,
size_t size )
inline

Definition at line 346 of file zm.h.

347 {
348 Buffer::clear();
349 if (size == 0) {
350 set((T)0);
351 return;
352 }
353#ifdef MIE_USE_UNIT32
354 Buffer::alloc(size);
355 for (size_t i = 0; i < size; i++) {
356 (*this)[i] = x[i];
357 }
358#else
359 Buffer::alloc((size + 1) / 2);
360 for (size_t i = 0; i < size / 2; i++) {
361 (*this)[i] = make64(x[i * 2 + 1], x[i * 2]);
362 }
363 if (size & 1) {
364 (*this)[size / 2] = x[size - 1];
365 }
366#endif
367 trim();
368 }
Here is the call graph for this function:

◆ set() [3/4]

template<class Buffer >
void mie::VuintT< Buffer >::set ( const uint64_t * x,
size_t size )
inline

Definition at line 369 of file zm.h.

370 {
371 Buffer::clear();
372 if (size == 0) {
373 set((T)0);
374 return;
375 }
376#ifdef MIE_USE_UNIT32
377 Buffer::alloc(size * 2);
378 for (size_t i = 0; i < size; i++) {
379 uint32_t L, H;
380 split64(&H, &L, x[i]);
381 (*this)[i * 2 + 0] = L;
382 (*this)[i * 2 + 1] = H;
383 }
384#else
385 Buffer::alloc(size);
386 for (size_t i = 0; i < size; i++) {
387 (*this)[i] = x[i];
388 }
389#endif
390 trim();
391 }
Here is the call graph for this function:

◆ set() [4/4]

template<class Buffer >
void mie::VuintT< Buffer >::set ( T x)
inline

Definition at line 341 of file zm.h.

342 {
343 Buffer::alloc(1);
344 (*this)[0] = x;
345 }
Here is the caller graph for this function:

◆ shl()

template<class Buffer >
static void mie::VuintT< Buffer >::shl ( VuintT< Buffer > & out,
const VuintT< Buffer > & x,
size_t n )
inlinestatic

Definition at line 813 of file zm.h.

814 {
815 if (n == 0) {
816 out = x;
817 } else {
818 const size_t unitSize = sizeof(T) * 8;
819 size_t q = n / unitSize;
820 size_t r = n % unitSize;
821 const VuintT *p = &x;
822 if (q) {
823 shlUnit(out, x, q);
824 p = &out;
825 }
826 if (r) {
827 shlBit(out, *p, r);
828 }
829 }
830 }
const mie::Vuint & p
Definition bn.cpp:27
static void shlUnit(VuintT &out, const VuintT &x, size_t n)
Definition zm.h:743
static void shlBit(VuintT &out, const VuintT &x, size_t n)
Definition zm.h:757
Here is the call graph for this function:

◆ shlBit()

template<class Buffer >
static void mie::VuintT< Buffer >::shlBit ( VuintT< Buffer > & out,
const VuintT< Buffer > & x,
size_t n )
inlinestatic

Definition at line 757 of file zm.h.

758 {
759 const size_t unitSize = sizeof(T) * 8;
760 assert(0 < n && n < unitSize);
761 const size_t xn = x.size();
762 out.alloc(xn);
763
764 T prev = 0;
765 size_t rn = unitSize - n;
766 for (size_t i = 0; i < xn; i++) {
767 T t = x[i];
768 out[i] = (t << n) | (prev >> rn);
769 prev = t;
770 }
771 prev >>= rn;
772 if (prev) {
773 out.alloc(xn + 1);
774 out[xn] = prev;
775 }
776 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shlUnit()

template<class Buffer >
static void mie::VuintT< Buffer >::shlUnit ( VuintT< Buffer > & out,
const VuintT< Buffer > & x,
size_t n )
inlinestatic

Definition at line 743 of file zm.h.

744 {
745 const size_t xn = x.size();
746 out.alloc(xn + n);
747 for (int i = (int)xn - 1; i >= 0; i--) {
748 out[i + n] = x[i];
749 }
750 std::fill(&out[0], &out[0] + n, 0);
751 out.trim();
752 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shr()

template<class Buffer >
static void mie::VuintT< Buffer >::shr ( VuintT< Buffer > & out,
const VuintT< Buffer > & x,
size_t n )
inlinestatic

Definition at line 831 of file zm.h.

832 {
833 if (n == 0) {
834 out = x;
835 } else {
836 const size_t unitSize = sizeof(T) * 8;
837 size_t q = n / unitSize;
838 size_t r = n % unitSize;
839 const VuintT *p = &x;
840 if (q) {
841 shrUnit(out, x, q);
842 p = &out;
843 }
844 if (r) {
845 shrBit(out, *p, r);
846 }
847 }
848 }
static void shrUnit(VuintT &out, const VuintT &x, size_t n)
Definition zm.h:780
static void shrBit(VuintT &out, const VuintT &x, size_t n)
Definition zm.h:798
Here is the call graph for this function:

◆ shrBit()

template<class Buffer >
static void mie::VuintT< Buffer >::shrBit ( VuintT< Buffer > & out,
const VuintT< Buffer > & x,
size_t n )
inlinestatic

Definition at line 798 of file zm.h.

799 {
800 const size_t unitSize = sizeof(T) * 8;
801 assert(0 < n && n < unitSize);
802 const size_t xn = x.size();
803 T prev = 0;
804 size_t rn = unitSize - n;
805 out.alloc(xn);
806 for (int i = (int)xn - 1; i >= 0; i--) {
807 T t = x[i];
808 out[i] = (t >> n) | (prev << rn);
809 prev = t;
810 }
811 out.trim();
812 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shrUnit()

template<class Buffer >
static void mie::VuintT< Buffer >::shrUnit ( VuintT< Buffer > & out,
const VuintT< Buffer > & x,
size_t n )
inlinestatic

Definition at line 780 of file zm.h.

781 {
782 const size_t xn = x.size();
783 if (xn <= n) {
784 out = 0;
785 } else {
786 out.alloc(xn); // not on because of x may be equal to out
787 const size_t on = xn - n;
788 for (size_t i = 0; i < on; i++) {
789 out[i] = x[i + n];
790 }
791 out.alloc(on);
792 }
793 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

template<class Buffer >
size_t mie::VuintT< Buffer >::size ( ) const
inline

Definition at line 519 of file zm.h.

519{ return Buffer::size(); }
Here is the caller graph for this function:

◆ sub()

template<class Buffer >
static void mie::VuintT< Buffer >::sub ( VuintT< Buffer > & out,
const VuintT< Buffer > & x,
const VuintT< Buffer > & y )
inlinestatic

Definition at line 597 of file zm.h.

598 {
599 bool c = sub_in(out, x, y);
600 if (c) {
601 local::errExit("can't sub");
602 }
603 out.trim();
604 }
static bool sub_in(VuintT &out, const VuintT &x, const VuintT &y)
Definition zm.h:584
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sub_in()

template<class Buffer >
static bool mie::VuintT< Buffer >::sub_in ( VuintT< Buffer > & out,
const VuintT< Buffer > & x,
const VuintT< Buffer > & y )
inlinestatic

Definition at line 584 of file zm.h.

585 {
586 const size_t xn = x.size();
587 const size_t yn = y.size();
588 assert(xn >= yn);
589 out.alloc(xn);
590 bool c = F::subN(&out[0], &x[0], &y[0], yn);
591 if (xn > yn) {
592 c = F::sub1(&out[yn], &x[yn], xn - yn, c);
593 }
594 return c;
595 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ testBit()

template<class Buffer >
bool mie::VuintT< Buffer >::testBit ( size_t i) const
inline

Definition at line 539 of file zm.h.

540 {
541 size_t unit_pos = i / (sizeof(T) * 8);
542 size_t bit_pos = i % (sizeof(T) * 8);
543 T mask = T(1) << bit_pos;
544 return ((*this)[unit_pos] & mask) != 0;
545 }
Here is the caller graph for this function:

◆ toStr()

template<class Buffer >
std::string mie::VuintT< Buffer >::toStr ( int base = 10) const
inline

Definition at line 514 of file zm.h.

514{ return toString(base); }
std::string toString(int base=10) const
Definition zm.h:407
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

template<class Buffer >
std::string mie::VuintT< Buffer >::toString ( int base = 10) const
inline

Definition at line 407 of file zm.h.

408 {
409 std::ostringstream os;
410 switch (base) {
411 case 10:
412 {
413 const uint32_t i1e9 = 1000000000U;
414 static const VuintT zero = 0;
415 VuintT x = *this;
416
417 std::vector<uint32_t> t;
418 while (x > zero) {
419 uint32_t r = (uint32_t)div1(&x, x, i1e9);
420 t.push_back(r);
421 }
422 if (t.empty()) {
423 return "0";
424 }
425 os << t[t.size() - 1];
426 for (size_t i = 1, n = t.size(); i < n; i++) {
427 os << std::setfill('0') << std::setw(9) << t[n - 1 - i];
428 }
429 }
430 break;
431 case 16:
432 {
433 os << "0x" << std::hex;
434 const size_t n = Buffer::size();
435 os << (*this)[n - 1];
436 for (size_t i = 1; i < n; i++) {
437 os << std::setfill('0') << std::setw(sizeof(Unit) * 2) << (*this)[n - 1 - i];
438 }
439 }
440 break;
441 default:
442 local::errExit("toString not support base");
443 }
444 return os.str();
445 }
os_t os
Here is the call graph for this function:
Here is the caller graph for this function:

◆ trim()

template<class Buffer >
void mie::VuintT< Buffer >::trim ( )
inline

Definition at line 894 of file zm.h.

895 {
896 // remove leading zero
897 assert(Buffer::size());
898 int i = (int)Buffer::size() - 1;
899 for (; i > 0; i--) {
900 if ((*this)[i]) break;
901 }
902 Buffer::alloc(i ? i + 1: 1);
903 }
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<<

template<class Buffer >
std::ostream & operator<< ( std::ostream & os,
const VuintT< Buffer > & x )
friend

Definition at line 728 of file zm.h.

729 {
730 return os << x.toString(os.flags() & std::ios_base::hex ? 16 : 10);
731 }

◆ operator>>

template<class Buffer >
std::istream & operator>> ( std::istream & is,
VuintT< Buffer > & x )
friend

Definition at line 732 of file zm.h.

733 {
734 std::string str;
735 local::getDigits(is, str);
736 x.set(str);
737 return is;
738 }

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