https://github.com/newyaroslav/trit_array_cpp
C++ header-only library of a trit array
https://github.com/newyaroslav/trit_array_cpp
array cpp header-only three-valued-logic trilean trilean-array trinary trit trits
Last synced: 3 months ago
JSON representation
C++ header-only library of a trit array
- Host: GitHub
- URL: https://github.com/newyaroslav/trit_array_cpp
- Owner: NewYaroslav
- License: mit
- Created: 2019-09-09T10:53:50.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-07T09:46:38.000Z (over 5 years ago)
- Last Synced: 2025-01-08T17:52:14.047Z (5 months ago)
- Topics: array, cpp, header-only, three-valued-logic, trilean, trilean-array, trinary, trit, trits
- Language: C++
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# trit_array_cpp
C++ header-only library of a trit array### Description and examples
* trit - ternary digit
* in balanced ternary, each digit has one of 3 values: −1, 0, or +1```C++
#include
#include "trit_array.hpp"int main() {
std::cout << "Hello world!" << std::endl;// Create a two-dimensional array of trits
base3::trit_array_2d array_2d;// Set the size of a two-dimensional array
const int SIZE_X = 1000;
const int SIZE_Y = 100;
//base3::trit_array_2d array_2d(SIZE_X, SIZE_Y); - this option is also possible
array_2d = base3::trit_array_2d(SIZE_X,SIZE_Y);// Set the value of the trit
array_2d.set(55, 34, base3::BASE3_TRUE); // Set +1
array_2d.set(156, 87, base3::BASE3_FALSE); // Set -1
array_2d.set(3, 8, base3::BASE3_NULL); // Set 0// Get the value of trit
int state = array_2d.get(55, 34);
if(state == base3::BASE3_TRUE) std::cout << "true" << std::endl;// size of two-dimensional array of trit
int data_size = array_2d.size();
std::cout << "size: " << data_size << std::endl << std::flush;// pointer to array data
unsigned char *point_data = array_2d.data();// Initialize a new array of trites with an array of bytes
unsigned char *array_data = new unsigned char[data_size];
std::copy(point_data, point_data + data_size, array_data);
base3::trit_array_2d new_array_2d(SIZE_X, SIZE_Y, array_data);return 0;
}
```