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
#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); |
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
#ifndef FSM_h | |
#define FSM_h | |
#include <iostream> | |
#include <unordered_map> | |
#include <unordered_set> | |
#include <vector> | |
class Machine { | |
public: |
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
a | b | c | ||
---|---|---|---|---|
1 | 2 | 1 | 1 | |
2 | 2 | 3 | 1 | |
3 | 2 | 1 | 4 | |
4 | 4 | 4 | 4 |
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
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 |
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
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; | |
} |
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
_Z8doubleItt: # @_Z8doubleItt | |
lea eax, [rdi + rdi] | |
ret | |
_Z9doubleIt2Rt: # @_Z9doubleIt2Rt | |
movzx eax, word ptr [rdi] | |
add eax, eax | |
ret |
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
int doubleIt(int num) { | |
return num + num; | |
} | |
int doubleItRef(int &num) { | |
return num + num; | |
} |
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
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); |
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
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 |
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
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 |
NewerOlder