Skip to content

Instantly share code, notes, and snippets.

@Mivik
Mivik / Cargo.toml
Created March 8, 2024 09:33
so78124765
[package]
name = "so78124765"
version = "0.1.0"
edition = "2021"
[dependencies]
reqwest = { version = "0.11.24", features = ["json"] }
serde_json = "1.0.114"
tokio = { version = "1.36.0", features = ["net", "io-util", "rt-multi-thread", "macros"] }
@Mivik
Mivik / benchmark.rs
Last active March 30, 2023 08:23
SQLx vs tokio-postgres benchmark
use criterion::{criterion_group, criterion_main, Criterion};
use sqlx::{
postgres::{PgConnectOptions, PgPoolOptions},
ConnectOptions,
};
use tokio::runtime::Runtime;
use tokio_postgres::NoTls;
pub fn rand_token() -> String {
use rand::{distributions::Alphanumeric, Rng};
@Mivik
Mivik / benchmark.cpp
Created June 26, 2021 13:51
std::set and std::priority_queue
// Mivik 2021.6.18
#include <chrono>
#include <iostream>
#include <queue>
#include <random>
#include <set>
#include <vector>
const int QUERY_NUM = 2000000;
const int INSERT_NUM = 2000000;
@Mivik
Mivik / find_root.cpp
Created March 5, 2021 15:44
Finding the roots of a special kind of polynomial
// Mivik 2021.3.1
#include <mivik.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <random>
#include <vector>
@Mivik
Mivik / mod_solver_ntt.cpp
Last active March 1, 2021 11:46
mod_solver
// Mivik 2021.3.1
#include <algorithm>
#include <cassert>
#include <cctype>
#include <random>
#include <vector>
typedef long long qe;
const int mod = 998244353;
@Mivik
Mivik / calc_poly.cpp
Created February 19, 2021 06:56
C++ program that computes subword complexity polynomial. See https://mivik.gitee.io/2021/research/expected-subword-complexity-en/.
// Requires: libgmp-dev
// Recommended compiler options: -std=c++11 -Ofast -lgmp -lgmpxx
// Mivik 2021.1.25
#include <cassert>
#include <cstdint>
#include <iostream>
#include <vector>
const int N = 60; // maximum length of the string
@Mivik
Mivik / enum.cpp
Created January 27, 2021 07:10
Enumeration of autocorrelations, along with their populations.
// Mivik 2021.1.24
// Inspired by the predicate given in "Periods in Strings" by Guibas and Odlyzko
// See Leo J. Guibas and Andrew M. Odlyzko. Periods in strings. J. of Combinatorial Theory series A, 30:19–42, 1981.
// Enumerated all autocorrelations for n = 400 in less than 30 seconds on my computer (without writing it to file)
// It DOES REQUIRE A LOT OF TIME AND DISK SPACE to save these autocorrelations, please notice
// For example, for n = 200, it could produce a file up to 200MB
#include <algorithm>
#include <cassert>
#include <cstdint>
@Mivik
Mivik / calc.cpp
Created January 25, 2021 14:18
C++ program that computes sum of subword complexity of all binary strings of length n.
// Requires: libgmp-dev
// Recommended compiler options: -Ofast -lgmp -lgmpxx
// Mivik 2021.1.25
#include <cstdint>
#include <iostream>
#include <vector>
#include <gmpxx.h>
@Mivik
Mivik / enum.cpp
Last active January 24, 2021 07:09
Enumeration of autocorrelations of length n
// Mivik 2021.1.24
// Inspired by the predicate given in "Periods in Strings" by Guibas and Odlyzko
// See Leo J. Guibas and Andrew M. Odlyzko. Periods in strings. J. of Combinatorial Theory series A, 30:19–42, 1981.
// Enumerated all autocorrelations for n = 400 in less than 30 seconds on my computer (without writing it to file)
// It DOES REQUIRE A LOT OF TIME AND DISK SPACE to save these autocorrelations, please notice
// For example, for n = 200, it could produce a file up to 200MB
#include <algorithm>
#include <bitset>
#include <iostream>