Skip to content

Instantly share code, notes, and snippets.

View cgiosy's full-sized avatar

cgiosy cgiosy

View GitHub Profile
@cgiosy
cgiosy / dlas.hpp
Last active December 23, 2023 05:33
Diversified Late Acceptance Search
#ifndef DLAS_HPP
#include "intdef.hpp"
#include <array>
#include <algorithm>
#include <functional>
#include <utility>
template<class T, class U>
T incMod(T x, U mod) {
@cgiosy
cgiosy / bench.cpp
Last active January 17, 2024 20:06
#define LOAD_FACTOR 0.5
#include "robin-hood.hpp"
#define ERASE_TECHNIQUE USE_SHIFTING
#include "robin-hood.hpp"
#include "random.hpp"
#include "lib/bytell_hash_map.hpp"
#define LOOKUP_ZIPF true
#include <cmath>
#include <cstdint>
@cgiosy
cgiosy / xxh32.js
Last active June 29, 2022 23:16
XXHash32 JS Implementation
const getUint32 = (arr: Uint8Array, i: number) => (
arr[i] | arr[i + 1 | 0] << 8 | arr[i + 2 | 0] << 16 | arr[i + 3 | 0] << 24
);
const rotl32 = (x: number, r: number) => (x << r) | (x >>> 32 - r);
const xxh32 = (buf: Uint8Array, seed = 0) => {
seed |= 0;
const len = buf.length | 0;
let i = 0;
@cgiosy
cgiosy / gen.js
Last active March 14, 2023 18:09
const fs = require('fs');
const filenum = 30; // or 100
const lines = 2000000; // or 1000000
const errors = 100000;
const ratio = lines / errors | 0;
const count = lines / ratio | 0;
for (let i = 1; i <= filenum; i += 1) {
@cgiosy
cgiosy / build.cpp
Last active February 23, 2022 15:39
Simple Treap
function<void(shared_ptr<node>&&)> dfs=[&](shared_ptr<node>&& p) {
if(p->l) p->push(p->l), dfs(move(p->l));
A[M++]=p->x;
if(p->r) p->push(p->r), dfs(move(p->r));
};
function<shared_ptr<node>(int, int)> build=[&](int l, int r) {
int m=(l+r)>>1;
auto p=node::New(A[m]);
if(l<m) p->l=build(l, m-1);
@cgiosy
cgiosy / HTTP Proxy Server Benchmarks.md
Last active February 21, 2022 16:13
HTTP Proxy Server Benchmarks

HTTP Proxy Server Benchmarks

h2load를 사용해 리버스 프록시 서버로서의 H2ONginx를 벤치마크 및 비교해 보았다. HTTP/2와 HTTP/3 각각에 대해 테스트하였고, 벤치마크 명령어를 다섯 번 실행하여 시간이 가장 적게 소모된 경우를 뽑았다.

Configurations

H2O

2022년 1월 8일 기준 최신 커밋을 빌드하였으며, ECDH Curves 관련 PR을 적용했다.

@cgiosy
cgiosy / concurrent.js
Last active June 1, 2022 03:18
Asynchronous Function Concurrent Executor
const concurrent = async(limit, fns) => {
const result = [];
const runningTasks = [];
for (const fn of fns) {
const promise = fn();
result.push(promise);
const emptyIndex = runningTasks.length === limit ? await Promise.race(runningTasks) : runningTasks.length;
const currentIndex = emptyIndex;
runningTasks[emptyIndex] = promise.then(() => currentIndex);
}
// #define DONT_USE_SIMD
// #pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <iostream>
#include <x86intrin.h>
#define INDEX_BIT_SIZE 14
using i16 = short;
using i32 = int;
using u32 = unsigned int;
@cgiosy
cgiosy / kd_tree.cpp
Last active September 12, 2021 22:30
K-D Tree
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
struct point {
int x, y;
point operator-(point v) const { return { x - v.x, y - v.y }; }
ll operator~() const { return ll(x) * x + ll(y) * y; }
};
@cgiosy
cgiosy / cheat.js
Last active November 24, 2021 14:32
const replaceSetMap = (object) => {
if (object) {
if (object.constructor === Set) return [...object];
if (object.constructor === Map) return Object.fromEntries(object);
}
return object;
};
const firstScan = ($, needle, { replacer = replaceSetMap, seen = new WeakMap() } = {}) => {
const found = [];