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
fun<T> reShape(list: List<T>, vararg dims: Int): List<Any> { | |
fun groupBy(list: List<Any>, by: Int): List<Any> { | |
assert(list.size % by == 0) | |
val ret: MutableList<List<T>> = mutableListOf() | |
var j = 0 | |
for (i in list.size downTo 1 step by) { | |
val o = mutableListOf<T>() | |
for (k in 1..by) { | |
o.add(list[j++] as T) | |
} |
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
template <typename T> | |
struct UniqueIDGenerator { | |
std::atomic<T> _id; | |
std::function<const T(const T&)> _nexter; | |
template <typename NEXT> | |
UniqueIDGenerator(const T& init, const NEXT& nexter) { | |
_id.store(init, std::memory_order::memory_order_release); | |
_nexter = nexter; | |
} |
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
struct FileAppender { | |
std::ofstream _file; | |
std::mutex _lock; | |
explicit FileAppend(const std::string& filename) { | |
_file.open(filename.c_str(), std::ios_base::app); | |
} | |
virtual ~FileAppend() { | |
_file.flush(); |
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 <iostream> | |
#include <vector> | |
using namespace std; | |
template <class PT, class Iterable, class xGetter, class yGetter, class LAMBDA> | |
static void scalePoints(Iterable& points, PT& center, float x, float y, xGetter gx, yGetter gy, LAMBDA cb) { | |
int i = 0; | |
for (auto& p : points) { | |
float px = gx(p) - gx(center); |
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
// Example program | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using std::vector; | |
template<typename P, typename Iterator, typename Mapper> | |
void map(Iterator current, Iterator end, Mapper mapper, vector<P>& ret) { | |
if (current == end) return; |