Go to the documentation of this file.
23 #ifndef COM_DAFER45_TBTK_EXTENSIVE_BIT_REGISTER
24 #define COM_DAFER45_TBTK_EXTENSIVE_BIT_REGISTER
122 void setBit(
unsigned int position,
bool values);
125 bool getBit(
unsigned int position)
const;
172 std::ostream &stream,
180 unsigned int *values;
183 static constexpr
unsigned int MOST_SIGNIFICANT_BIT_MASK
184 = (
unsigned int)0x1 << (8*
sizeof(
unsigned int) - 1);
192 "ExtensiveBitRegister::operator|()",
193 "Incompatible register sizes.",
198 for(
unsigned int n = 0; n < size; n++)
199 result.values[n] = values[n] | rhs.values[n];
209 "ExtensiveBitRegister::operator|()",
210 "Incompatible register sizes.",
215 for(
unsigned int n = 0; n < size; n++)
216 result.values[n] = values[n] & rhs.values[n];
226 "ExtensiveBitRegister::operator|()",
227 "Incompatible register sizes.",
232 for(
unsigned int n = 0; n < size; n++)
233 result.values[n] = values[n] ^ rhs.values[n];
243 "ExtensiveBitRegister::operator+()",
244 "Incompatible register sizes.",
249 unsigned int carry = 0;
250 for(
unsigned int n = 0; n < size; n++){
251 result.values[n] = values[n] + rhs.values[n];
252 unsigned int newCarry = (result.values[n] < values[n]);
253 result.values[n] += carry;
254 carry = newCarry | (result.values[n] < values[n]);
265 "ExtensiveBitRegister::operator+()",
266 "Incompatible register sizes.",
271 unsigned int carry = 0;
272 for(
unsigned int n = 0; n < size; n++){
273 result.values[n] = values[n] - rhs.values[n];
274 unsigned int newCarry = (result.values[n] > values[n]);
275 result.values[n] -= carry;
276 carry = newCarry | (result.values[n] > values[n]);
285 for(
int n = size-1; n >= 0; n--){
286 if(values[n] < rhs.values[n])
288 if(values[n] > rhs.values[n])
298 for(
int n = size-1; n >= 0; n--){
299 if(values[n] > rhs.values[n])
301 if(values[n] < rhs.values[n])
311 for(
unsigned int n = 0; n < size; n++){
312 if(values[n] != rhs.values[n])
322 "ExtensiveBitRegister::operator+=()",
323 "Incompatible register sizes.",
327 unsigned int carry = 0;
328 for(
unsigned int n = 0; n < size; n++){
329 unsigned int temp = values[n];
330 values[n] = temp + rhs.values[n];
331 unsigned int newCarry = (values[n] < temp);
333 carry = newCarry | (values[n] < temp);
340 "ExtensiveBitRegister::operator-=()",
341 "Incompatible register sizes.",
345 unsigned int carry = 0;
346 for(
unsigned int n = 0; n < size; n++){
347 unsigned int temp = values[n];
348 values[n] = temp - rhs.values[n];
349 unsigned int newCarry = (values[n] > temp);
351 carry = newCarry | (values[n] > temp);
356 for(
unsigned int n = 0; n < size; n++){
357 if(values[n] == UINT_MAX){
377 for(
unsigned int n = 0; n < size; n++){
399 if(values ==
nullptr){
401 values =
new unsigned int[size];
402 for(
unsigned int n = 0; n < size; n++)
403 values[n] = rhs.values[n];
408 "ExtensiveBitRegister::operator=()",
409 "Incompatible register sizes.",
413 for(
unsigned int n = 0; n < size; n++)
414 values[n] = rhs.values[n];
421 for(
unsigned int n = 1; n < size; n++)
427 if(rhs > 8*
sizeof(
unsigned int)){
428 result = result << (rhs - 8*
sizeof(
unsigned int));
430 for(
int n = size-1; n > 0; n--)
431 result.values[n] = result.values[n-1];
432 result.values[0] = 0;
434 else if(rhs == 8*
sizeof(
unsigned int)){
435 for(
int n = size-1; n > 0; n--)
436 result.values[n] = result.values[n-1];
437 result.values[0] = 0;
440 for(
int n = size-1; n >= 0; n--){
441 result.values[n] = result.values[n] << rhs;
443 result.values[n] |= result.values[n-1] >> (8*
sizeof(
unsigned int) - rhs);
452 if(rhs > 8*
sizeof(
unsigned int)){
453 result = result >> (rhs - 8*
sizeof(
unsigned int));
455 for(
unsigned int n = 0; n < size-1; n++)
456 result.values[n] = result.values[n+1];
457 result.values[size-1] = 0;
460 for(
unsigned int n = 0; n < size; n++){
461 result.values[n] = result.values[n] >> rhs;
463 result.values[n] |= result.values[n+1] << (8*
sizeof(
unsigned int) - rhs);
471 for(
unsigned int n = size; n > 0; n--){
472 for(
int c = 8*
sizeof(
unsigned int)-1; c >= 0; c--)
480 values[position/(8*
sizeof(
unsigned int))] &= ~(1 << (position%(8*
sizeof(
unsigned int))));
481 values[position/(8*
sizeof(
unsigned int))] ^= (value << (position%(8*
sizeof(
unsigned int))));
485 return (0x1 & (values[position/(8*
sizeof(
unsigned int))] >> (position%(8*
sizeof(
unsigned int)))));
489 for(
unsigned int n = 0; n < size; n++)
501 for(
unsigned int n = 0; n < size; n++)
506 return size*8*
sizeof(
unsigned int);
510 unsigned int numOnes = 0;
511 for(
unsigned int n = 0; n < size; n++){
512 unsigned int x = values[n];
513 x = x - ((x >> 1) & 0x55555555);
514 x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
515 x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F);
518 numOnes += (x & 0x0000003F);
525 return values[size-1] & MOST_SIGNIFICANT_BIT_MASK;
529 values[size-1] |= MOST_SIGNIFICANT_BIT_MASK;
533 values[size-1] &= !MOST_SIGNIFICANT_BIT_MASK;
541 std::stringstream stream;
542 for(
unsigned int n =
getNumBits(); n > 0; n--)
549 std::ostream &stream,
552 stream << extensiveBitRegister.
toString();
bool operator>(const ExtensiveBitRegister &rhs) const
Definition: ExtensiveBitRegister.h:295
void operator-=(const ExtensiveBitRegister &rhs)
Definition: ExtensiveBitRegister.h:337
void clear()
Definition: ExtensiveBitRegister.h:500
unsigned int getNumBits() const
Definition: ExtensiveBitRegister.h:505
const ExtensiveBitRegister operator^(const ExtensiveBitRegister &rhs) const
Definition: ExtensiveBitRegister.h:221
bool operator==(const ExtensiveBitRegister &rhs) const
Definition: ExtensiveBitRegister.h:308
ExtensiveBitRegister operator>>(unsigned int rhs) const
Definition: ExtensiveBitRegister.h:450
void operator=(const ExtensiveBitRegister &rhs)
Definition: ExtensiveBitRegister.h:397
unsigned int getNumOneBits() const
Definition: ExtensiveBitRegister.h:509
void clearMostSignificantBit()
Definition: ExtensiveBitRegister.h:532
const ExtensiveBitRegister & operator--()
Definition: ExtensiveBitRegister.h:376
const ExtensiveBitRegister operator|(const ExtensiveBitRegister &rhs) const
Definition: ExtensiveBitRegister.h:187
const ExtensiveBitRegister operator&(const ExtensiveBitRegister &rhs) const
Definition: ExtensiveBitRegister.h:204
unsigned int toUnsignedInt() const
Definition: ExtensiveBitRegister.h:496
const ExtensiveBitRegister & operator++()
Definition: ExtensiveBitRegister.h:355
void setMostSignificantBit()
Definition: ExtensiveBitRegister.h:528
void print() const
Definition: ExtensiveBitRegister.h:470
void setBit(unsigned int position, bool values)
Definition: ExtensiveBitRegister.h:479
const ExtensiveBitRegister operator+(const ExtensiveBitRegister &rhs) const
Definition: ExtensiveBitRegister.h:238
bool operator<(const ExtensiveBitRegister &rhs) const
Definition: ExtensiveBitRegister.h:282
Register of bits.
Definition: ExtensiveBitRegister.h:43
std::string toString() const
Definition: ExtensiveBitRegister.h:540
ExtensiveBitRegister operator<<(unsigned int rhs) const
Definition: ExtensiveBitRegister.h:425
bool toBool() const
Definition: ExtensiveBitRegister.h:488
static std::ostream out
Definition: Streams.h:70
ExtensiveBitRegister cloneStructure() const
Definition: ExtensiveBitRegister.h:536
void operator+=(const ExtensiveBitRegister &rhs)
Definition: ExtensiveBitRegister.h:319
bool getMostSignificantBit() const
Definition: ExtensiveBitRegister.h:524
std::ostream & operator<<(std::ostream &stream, const HoppingAmplitude &hoppingAmplitude)
Definition: HoppingAmplitude.h:315
const ExtensiveBitRegister operator-(const ExtensiveBitRegister &rhs) const
Definition: ExtensiveBitRegister.h:260
bool getBit(unsigned int position) const
Definition: ExtensiveBitRegister.h:484