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
/***************************************************************************** | |
* QuantCup 1: Price-Time Matching Engine | |
* | |
* Submitted by: voyager | |
* | |
* Design Overview: | |
* In this implementation, the limit order book is represented using | |
* a flat linear array (pricePoints), indexed by the numeric price value. | |
* Each entry in this array corresponds to a specific price point and holds | |
* an instance of struct pricePoint. This data structure maintains a list |
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
// double 12345.67 -> int 1234567 | |
struct Trie { | |
std::array<int, (size_t) 1.1e7> cnt, sum; | |
void update(int price, int qty) { | |
int cnt_delta = qty ? (cnt[price] ? 0 : +1) : (cnt[price] ? -1 : 0); | |
int sum_delta = qty - sum[price]; | |
for (int node = 0, tmp = price, p10 = 1e7; p10; tmp %= p10, p10 /= 10) { | |
node = 10 * node + tmp / p10; |
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 <sys/mman.h> | |
#include <fcntl.h> | |
unsigned char* shared(const char* path) { | |
int fd = open(path, O_RDWR | O_CREAT, (mode_t) 0600); | |
posix_fallocate(fd, 0, 65536); | |
return (unsigned char*) mmap(0, 65536, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | |
} |
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
# ----------------------------------------------------------------------------- | |
# AI-powered Git Commit Function | |
# Copy paste this gist into your ~/.bashrc or ~/.zshrc to gain the `gcm` command. It: | |
# 1) gets the current staged changed diff | |
# 2) sends them to an LLM to write the git commit message | |
# 3) allows you to easily accept, edit, regenerate, cancel | |
# But - just read and edit the code however you like | |
# the `llm` CLI util is awesome, can get it here: https://llm.datasette.io/en/stable/ | |
gcm() { |