Skip to content

Instantly share code, notes, and snippets.

@bexp
bexp / cons.cc
Last active July 11, 2018 18:37
consumer_producer
// Compiled with: g++ -Wall -std=c++14 -pthread
#include <iostream>
#include <mutex>
#include <thread>
#include <condition_variable>
#include <queue>
#include <thread>
#include <vector>
using namespace std;
/*
* Simple lockfree implementation of single producer/consumer circular FIFO buffer
*/
#ifndef RINGBUFFER_H
#define RINGBUFFER_H
#include <algorithm>
#include <memory.h>
#include <atomic>
@bexp
bexp / merge.cc
Last active May 14, 2018 20:24
merge sort
#include <iostream>
#include <map>
using namespace std;
void print(int *a, int num) {
for (int i = 0; i < num; i++) {
cout << " " << a[i];
}
// Compiled with: g++ -Wall -std=c++14 -pthread
#include <iostream>
#include <vector>
#include <map>
using namespace std;
//print array
void print(int* arr, int n) {
#include <iostream>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <sstream>
#include <climits>
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <bitset>
#include <math.h>
#include <climits>
using namespace std;
/*
static string ToBinaryString(float value) {
#include <iostream>
#include <list>
#include <stdlib.h>
#include <climits>
#include <bits/stdc++.h>
using namespace std;
class graph {
@bexp
bexp / bst.cc
Created October 17, 2017 04:14
#include <iostream>
using namespace std;
typedef struct node {
int data;
node() : data(0), left(NULL), right(NULL) {}
node(int d) {
data = d;
#include <iostream>
#include <vector>
using namespace std;
// Max Heap impl
struct PriorityQueue {
private:
vector<int> A;
@bexp
bexp / latency.txt
Created November 20, 2017 21:51 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD