25 inline bool is_integer(
float x) {
return std::floor(x) == x; }
38 std::memcpy(&word, &val,
sizeof(val));
53 std::memcpy(&val, &word,
sizeof(word));
66 inline int wordToInt(uint32_t word) {
return static_cast<int>(word); }
75 if (word & 0x80000000) {
78 return static_cast<int>(word);
88 inline bool wordToBool(uint32_t word) {
return word != 0; }
96 inline uint32_t
boolToWord(
bool value) {
return value ? 1 : 0; }
112 inline bool isNegative(uint32_t word) {
return (word & 0x80000000) != 0; }
120 inline std::string
valName(
int i) {
return "val_" + std::to_string(i); }
130 template <
typename T>
155 template <
typename T>
176 while (tmp != NULL) {
199 tail->next = newNode;
211 fprintf(stderr,
"Warning... tail of linked-list is null\n");
213 return &(
tail->data);
221 fprintf(stderr,
"Warning... tail is NULL when trying to pop\n");
231 if (current_tail ==
head) {
236 ghost = current_tail;
238 ghost->next = current_tail;
257 const std::vector<std::vector<int>> &vectors) {
258 std::vector<std::vector<int>> result;
260 if (vectors.size() == 0) {
264 for (
int v : vectors[0]) {
265 std::vector<int> tmp = {v};
266 result.emplace_back(tmp);
269 for (
int i = 1; i < vectors.size(); ++i) {
270 std::vector<std::vector<int>> tempResult;
271 for (
const auto &element1 : result) {
272 for (
const auto &element2 : vectors[i]) {
273 std::vector<int> tempElement = element1;
274 tempElement.push_back(element2);
275 tempResult.push_back(tempElement);
Node for a Doubly Linked List.
Definition: utils.h:131
LLNode * next
Pointer to the next node in the linked list.
Definition: utils.h:134
LLNode * prev
Pointer to the previous node in the linked list.
Definition: utils.h:135
T data
The data stored in the node.
Definition: utils.h:133
LLNode(T data)
Default constructor for LLNode.
Definition: utils.h:142
Doubly Linked List Implementation.
Definition: utils.h:156
void push(T data)
Pushes a new element onto the back of the linked list.
Definition: utils.h:188
Linkedlist()
Default constructor for Linkedlist.
Definition: utils.h:166
LLNode< T > * ghost
Ghost node for maintaining previous tails during pops.
Definition: utils.h:159
T * back()
Returns the element at the back of the linked list.
Definition: utils.h:209
LLNode< T > * head
Pointer to the head of the linked list.
Definition: utils.h:160
LLNode< T > * tail
Pointer to the tail of the linked list.
Definition: utils.h:161
void pop()
Pops the element at the back of the linked list.
Definition: utils.h:219
uint32_t len()
Get the length of the linked list.
Definition: utils.h:173
Definition: compiler.h:11
float wordToFloat(uint32_t word)
Converts a 32-bit word representation to a float value.
Definition: utils.h:51
std::string valName(int i)
Generates a name for a variable based on its index.
Definition: utils.h:120
int wordToInt(uint32_t word)
Converts a 32-bit word representation to an integer value.
Definition: utils.h:66
int wordToSignedInt(uint32_t word)
Converts a uint32_t word to a signed int.
Definition: utils.h:74
uint32_t twosComplement(uint32_t i)
Returns the twos complement of a uint32_t word.
Definition: utils.h:104
bool is_integer(float x)
Checks if a float is an integer.
Definition: utils.h:25
bool isNegative(uint32_t word)
Checks if a uint32_t word is negative.
Definition: utils.h:112
uint32_t FloatToWord(float val)
Converts a float value to a 32-bit word representation.
Definition: utils.h:36
std::vector< std::vector< int > > cartesianProduct(const std::vector< std::vector< int >> &vectors)
Compute the Cartesian product of a vector of vectors of integers.
Definition: utils.h:256
bool wordToBool(uint32_t word)
Converts a uint32_t word to a bool.
Definition: utils.h:88
uint32_t boolToWord(bool value)
Converts a bool to a uint32_t word.
Definition: utils.h:96