-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from lucky9-cyou/master
feat: add clifford simulator(#1)
- Loading branch information
Showing
22 changed files
with
3,611 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef BIT_H_ | ||
#define BIT_H_ | ||
|
||
#include <cstddef> | ||
#include <cstdint> | ||
|
||
// bit in byte | ||
struct bit { | ||
uint8_t* byte; | ||
uint8_t byte_index; | ||
|
||
bit(void* ptr, size_t offset) | ||
: byte(((uint8_t*)ptr + (offset / 8))), byte_index(offset & 7) {} | ||
|
||
// copy assignment for bit in byte | ||
inline bit& operator=(bool value) { | ||
// make bit be 0 | ||
*byte &= ~((uint8_t)1 << byte_index); | ||
// assignment | ||
*byte |= uint8_t(value) << byte_index; | ||
return *this; | ||
} | ||
|
||
inline bit& operator=(const bit& other) { | ||
*this = bool(other); | ||
return *this; | ||
} | ||
|
||
// bit operator | ||
inline bit& operator^=(bool value) { | ||
*byte ^= uint8_t(value) << byte_index; | ||
return *this; | ||
} | ||
|
||
inline bit& operator&=(bool value) { | ||
*byte &= (uint8_t(value) << byte_index) | ~(uint8_t(1) << byte_index); | ||
return *this; | ||
} | ||
|
||
inline bit& operator|=(bool value) { | ||
*byte |= uint8_t(value) << byte_index; | ||
return *this; | ||
} | ||
|
||
// conversion operator | ||
inline operator bool() const { return (*byte >> byte_index) & 1; } | ||
|
||
void swap(bit other) { | ||
bool b = bool(other); | ||
other = bool(*this); | ||
*this = b; | ||
} | ||
}; | ||
|
||
#endif |
Oops, something went wrong.