Skip to content

Instantly share code, notes, and snippets.

View z0z0r4's full-sized avatar
💭
My response may be slow.

z0z0r4 z0z0r4

💭
My response may be slow.
View GitHub Profile
@z0z0r4
z0z0r4 / main.cpp
Created June 13, 2026 18:56
String Matching
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <random>
#include <chrono>
auto NaiveMatch(const std::string &pattern, const std::string &text) -> int {
auto pattern_length = pattern.size();
@z0z0r4
z0z0r4 / cuckoo_filter.cpp
Created June 8, 2026 12:39
Cuckoo Filter
#include <iostream>
#include <vector>
#include <string>
#include <random>
#include <chrono>
using hash_t = std::size_t;
using TagType = uint16_t;
size_t UpperPower2(size_t x) {
@z0z0r4
z0z0r4 / hyperloglog.cpp
Created June 7, 2026 19:20
HyperLogLog
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using hash_t = std::size_t;
template <typename T>
class HyperLogLog {
public:
@z0z0r4
z0z0r4 / count_min_sketch.cpp
Created June 7, 2026 18:39
Count-min sketch
#include "count_min_sketch.h"
#include <algorithm>
#include <atomic>
#include <stdexcept>
#include <string>
/**
* Constructor for the count-min sketch.
*
@z0z0r4
z0z0r4 / bloom_filter.cpp
Last active June 7, 2026 18:02
Bloom Filter
#include <iostream>
#include <vector>
#include <string>
#include <type_traits>
using hash_t = std::size_t;
inline auto HashBytes(const char *bytes, size_t length, hash_t seed = 0) -> hash_t {
hash_t hash = length + seed;
for (size_t i = 0; i < length; ++i) {
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include "btree.h"
auto Node::FindExactKeyIdx(KeyType key, int *idx) -> bool {
int i = 0;
while (i < num_keys_) {
@z0z0r4
z0z0r4 / draw_pic.py
Created April 21, 2026 04:50
Disjoint-Set Performance Test
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
# 准备数据
data = [
# N, M, Speedup
[25, 10, 3.45], [25, 100, 1.38], [25, 1000, 0.98], [25, 100000, 2.11], [25, 1000000, 2.09], [25, 10000000, 2.14],
[50, 10, 4.71], [50, 100, 1.36], [50, 1000, 2.25], [50, 100000, 2.30], [50, 1000000, 2.30], [50, 10000000, 1.97],
[100, 10, 4.62], [100, 100, 1.22], [100, 1000, 2.05], [100, 100000, 2.59], [100, 1000000, 2.96], [100, 10000000, 2.72],
@z0z0r4
z0z0r4 / bomb.s
Last active March 3, 2026 23:48
CSAPP Bomb Lab 的汇编注释
bomb: 文件格式 elf64-x86-64
Disassembly of section .init:
0000000000400ac0 <_init>:
400ac0: 48 83 ec 08 sub $0x8,%rsp
400ac4: e8 f3 01 00 00 call 400cbc <call_gmon_start>
400ac9: 48 83 c4 08 add $0x8,%rsp
@z0z0r4
z0z0r4 / dat.py
Last active February 23, 2026 08:16
Double-Array Tire
import random
class DAT:
default_size: int = 4096
data_set_size = 126
base: list[int]
check: list[int]
def __init__(self):
self.base = [0] * self.default_size
@z0z0r4
z0z0r4 / rbtree.py
Created February 21, 2026 07:01
RBTree
from enum import Enum
import random
class Color(Enum):
RED = "red"
BLACK = "black"
class RBNode: