This file contains hidden or 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
typedef string::size_type ssize; | |
typedef pair<ssize, ssize> valLenPair; | |
ssize get(uint64_t x) { | |
double v = (sqrt((8. * x) + 1.) - 1)/2; | |
double c = ceil(v); | |
double dummy; | |
double frac = modf(v, &dummy); | |
double res = floor((c+1) * frac); | |
return (ssize)res; |
This file contains hidden or 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
// Red-black tree with subtree sizes for O(log(N)) calculation of order within the set | |
template <typename T> | |
class RedBlackTree { | |
public: | |
RedBlackTree() { | |
root = NIL = new Node(); | |
NIL->parent = NIL->left = NIL->right = NIL; | |
} | |
~RedBlackTree() { |
This file contains hidden or 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 <iostream> | |
#include <vector> | |
int getAt(long i, int n, int m) { | |
long long tmpI = i; | |
for (int tmpN = n; tmpN > 0; tmpN--) { | |
long long half = m * /*pow(2, tmpN - 1)*/ (1LL << (tmpN - 1)); | |
long long quarter = (half + 1) / 2; | |
long long adjustedI = tmpI % half; |
This file contains hidden or 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 compareMats(const Mat& a, const Mat& b) { | |
Mat diff = abs(a - b); | |
double maxVal; | |
Point maxLoc; | |
minMaxLoc( diff, nullptr, &maxVal, nullptr, &maxLoc ); | |
if (maxVal > DBL_EPSILON) { | |
std::cout << "Max " << maxVal; | |
} | |
} |
This file contains hidden or 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
// refer to dumpMat gist regarding how to generate a file readable by this function | |
void readMatFromFile(std::string fileName, Mat& m) { | |
std::ifstream file(fileName, std::ios::binary | std::ios::ate); | |
std::streamsize size = file.tellg(); | |
if (size == 0) { | |
std::cout << "File is empty or does not exist\n"; | |
} | |
file.seekg(0, std::ios::beg); | |
file.read((char*)m.data, MIN(size, m.total()*m.elemSize())); | |
file.close(); |
This file contains hidden or 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
static std::string type2str(int type) { | |
std::string r; | |
uchar depth = type & CV_MAT_DEPTH_MASK; | |
uchar chans = 1 + (type >> CV_CN_SHIFT); | |
switch ( depth ) { | |
case CV_8U: r = "8U"; break; | |
case CV_8S: r = "8S"; break; | |
case CV_16U: r = "16U"; break; |
This file contains hidden or 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
// | |
// MatDataExt.h | |
// | |
// Created by Giles Payne on 2020/10/05. | |
// | |
#pragma once | |
#ifdef __cplusplus | |
#import <opencv2/opencv2.h> |