@@ -57,10 +57,12 @@ template <uint16_t size> struct stackvec {
5757 FASTFLOAT_DEBUG_ASSERT (index < length);
5858 return data[index];
5959 }
60+
6061 FASTFLOAT_CONSTEXPR14 const limb &operator [](size_t index) const noexcept {
6162 FASTFLOAT_DEBUG_ASSERT (index < length);
6263 return data[index];
6364 }
65+
6466 // index from the end of the container
6567 FASTFLOAT_CONSTEXPR14 const limb &rindex (size_t index) const noexcept {
6668 FASTFLOAT_DEBUG_ASSERT (index < length);
@@ -72,14 +74,19 @@ template <uint16_t size> struct stackvec {
7274 FASTFLOAT_CONSTEXPR14 void set_len (size_t len) noexcept {
7375 length = uint16_t (len);
7476 }
77+
7578 constexpr size_t len () const noexcept { return length; }
79+
7680 constexpr bool is_empty () const noexcept { return length == 0 ; }
81+
7782 constexpr size_t capacity () const noexcept { return size; }
83+
7884 // append item to vector, without bounds checking
7985 FASTFLOAT_CONSTEXPR14 void push_unchecked (limb value) noexcept {
8086 data[length] = value;
8187 length++;
8288 }
89+
8390 // append item to vector, returning if item was added
8491 FASTFLOAT_CONSTEXPR14 bool try_push (limb value) noexcept {
8592 if (len () < capacity ()) {
@@ -89,12 +96,14 @@ template <uint16_t size> struct stackvec {
8996 return false ;
9097 }
9198 }
99+
92100 // add items to the vector, from a span, without bounds checking
93101 FASTFLOAT_CONSTEXPR20 void extend_unchecked (limb_span s) noexcept {
94102 limb *ptr = data + length;
95103 std::copy_n (s.ptr , s.len (), ptr);
96104 set_len (len () + s.len ());
97105 }
106+
98107 // try to add items to the vector, returning if items were added
99108 FASTFLOAT_CONSTEXPR20 bool try_extend (limb_span s) noexcept {
100109 if (len () + s.len () <= capacity ()) {
@@ -104,6 +113,7 @@ template <uint16_t size> struct stackvec {
104113 return false ;
105114 }
106115 }
116+
107117 // resize the vector, without bounds checking
108118 // if the new size is longer than the vector, assign value to each
109119 // appended item.
@@ -119,6 +129,7 @@ template <uint16_t size> struct stackvec {
119129 set_len (new_len);
120130 }
121131 }
132+
122133 // try to resize the vector, returning if the vector was resized.
123134 FASTFLOAT_CONSTEXPR20 bool try_resize (size_t new_len, limb value) noexcept {
124135 if (new_len > capacity ()) {
@@ -128,6 +139,7 @@ template <uint16_t size> struct stackvec {
128139 return true ;
129140 }
130141 }
142+
131143 // check if any limbs are non-zero after the given index.
132144 // this needs to be done in reverse order, since the index
133145 // is relative to the most significant limbs.
@@ -140,6 +152,7 @@ template <uint16_t size> struct stackvec {
140152 }
141153 return false ;
142154 }
155+
143156 // normalize the big integer, so most-significant zero limbs are removed.
144157 FASTFLOAT_CONSTEXPR14 void normalize () noexcept {
145158 while (len () > 0 && rindex (0 ) == 0 ) {
@@ -423,6 +436,7 @@ struct bigint : pow5_tables<> {
423436 stackvec<bigint_limbs> vec;
424437
425438 FASTFLOAT_CONSTEXPR20 bigint () : vec() {}
439+
426440 bigint (bigint const &) = delete ;
427441 bigint &operator =(bigint const &) = delete ;
428442 bigint (bigint &&) = delete ;
0 commit comments