Skip to content

Instantly share code, notes, and snippets.

View LucianoPAlmeida's full-sized avatar
💭
Daniel 11:32

Luciano Almeida LucianoPAlmeida

💭
Daniel 11:32
View GitHub Profile
#include "FSM.h"
// A finite state machine that contains either ..abc..
static std::unique_ptr<Machine> makeContainsAbc() {
Machine::state_set finalStates = {4};
Machine::state_set q = {1, 2, 3, 4};
auto machine = std::make_unique<Machine>(q, /*startState=*/1, finalStates);
machine->addTransition(1, 'a', 2);
#ifndef FSM_h
#define FSM_h
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
class Machine {
public:
a b c
1 2 1 1
2 2 3 1
3 2 1 4
4 4 4 4
sumBy(int*, int): # @sumBy(int*, int)
movd xmm0, esi
pshufd xmm1, xmm0, 0 # xmm1 = xmm0[0,0,0,0]
movdqu xmm2, xmmword ptr [rdi]
movdqu xmm3, xmmword ptr [rdi + 16]
paddd xmm2, xmm1
movdqu xmmword ptr [rdi], xmm2
paddd xmm3, xmm1
movdqu xmmword ptr [rdi + 16], xmm3
movq xmm1, qword ptr [rdi + 32] # xmm1 = mem[0],zero
void sumBy(int *p, const int value) {
for(int i = 0; i < 10; ++i) {
p[i] += value;
}
}
void sumByRef(int *p, const int &value) {
for(int i = 0; i < 10; ++i) {
p[i] += value;
}
_Z8doubleItt: # @_Z8doubleItt
lea eax, [rdi + rdi]
ret
_Z9doubleIt2Rt: # @_Z9doubleIt2Rt
movzx eax, word ptr [rdi]
add eax, eax
ret
int doubleIt(int num) {
return num + num;
}
int doubleItRef(int &num) {
return num + num;
}
void printI(int &i) {
std::cout << "s" << i << std::endl; // Use of deallocated memory crash or maybe just garbage.
}
int main(int argc, const char * argv[]) {
int *i = new int();
// Pretend this was deleted by mistake in a non-obvious way.
delete i;
printI(*i);
class A {
std::vector<std::string> _values;
public:
void addValue(const std::string &val) {
// some logic
_values.emplace_back(val);
}
void addValue(std::string &&val) { // r-value ref overload
// some logic
class A {
std::vector<std::string> _values;
public:
void addValue(const std::string &val) {
// some logic
_values.emplace_back(val);
}
void addValue(std::string &&val) { // r-value ref overload
// some logic