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 <errno.h> | |
#include <fcntl.h> | |
#include <getopt.h> | |
#include <limits.h> | |
#include <signal.h> | |
#include <stdarg.h> | |
#include <stdbool.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> |
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
/* My result: | |
* $ c++ --std=c++20 -O3 map_benchmark.cpp 2>&1 && ./a.out | |
* tiny map, a lot of queries | |
* omap) hits: 27271969, setup: 0ms, query: 916ms | |
* umap) hits: 27271969, setup: 0ms, query: 637ms | |
* small map, a lot of queries | |
* omap) hits: 4004139, setup: 0ms, query: 378ms | |
* umap) hits: 4004139, setup: 0ms, query: 167ms | |
* big map, a few queries | |
* omap) hits: 63229, setup: 577ms, query: 60ms |
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 <stdlib.h> | |
#include <stdio.h> | |
#ifndef PREFIX | |
#define PREFIX st_ | |
#endif | |
#ifndef TYPE | |
#error "Define TYPE for which segment tree should be created. You may also want " | |
"to define PREFIX for function names which defaults to 'st_'" |
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
-- Convert number to list of digits | |
tods n = if n < 10 then [n] else reverse $ unfoldr (\i -> if i == 0 then Nothing else Just (i `mod` 10, i `div` 10)) n | |
-- Convert list of digits to number | |
ton = foldl' (\a b -> a * 10 + b) 0 | |
-- Make list of numbers from digits | |
numbers ns = concat $ iterate (\xs -> concatMap (\n -> map (\xs' -> n : xs') xs) ns) (map (\c -> [c]) ns) | |
-- Primality test |
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
\G((@)|(\\)|(case\b)|(class\b)|(,)|(data\b)|(default\b)|(deriving\b)|(do\b)|(else\b)|(foreign\b)|(`)|(if\b)|(import\b)|(infixl\b)|(infixr\b)|(infix\b)|(instance\b)|(in\b)|(<-)|((?&NCOMMENT))|(\{)|(\[)|(\()|(let\b)|(module\b)|(newtype\b)|(of\b)|(->)|(\})|(\])|(=>)|(=)|(\))|(;)|(then\b)|(~)|(::)|(\.\.)|(type\b)|(_)|(\|)|(where\b)|((?&WHITECHAR))|((?&CHAR))|((?&STRING))|((?&VARID))|((?&CONID))|((?&COMMENT))|((?&VARSYM))|((?&CONSYM))|(:)|((?&FLOAT))|((?&INTEGER))|$) | |
(?(DEFINE) | |
(?<UNI_SMALL>\p{Ll}) | |
(?<ASC_SMALL>[a-z]) | |
(?<SMALL>((?&ASC_SMALL)|(?&UNI_SMALL)|_)) | |
(?<UNI_LARGE>\p{Lu}) | |
(?<ASC_LARGE>[A-Z]) | |
(?<LARGE>((?&ASC_LARGE)|(?&UNI_LARGE))) | |
(?<UNI_DIGIT>\p{Nd}) | |
(?<ASC_DIGIT>[0-9]) |
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 <stdio.h> | |
#include <errno.h> | |
#include <string.h> | |
#include <ctype.h> | |
#include <stdlib.h> | |
#include <stdbool.h> | |
#define MAX_NAME_LEN 128 | |
#define MAX_FILE_LEN 1024 |
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
#if 0 | |
/* Usage: */ | |
int avg(int a, int b) { return (a + b) / 2; } | |
struct OInt * a; | |
struct OInt * b; | |
struct OInt * c; | |
void show_updates(void * extra) { | |
struct OInt * oint; |