Skip to content

Instantly share code, notes, and snippets.

View jweinst1's full-sized avatar
🎯
Focusing

Josh Weinstein jweinst1

🎯
Focusing
View GitHub Profile
@jweinst1
jweinst1 / string_breaker.cpp
Created February 27, 2026 23:39
break strings by regions C++
#include <iostream>
#include <string>
#include <regex>
#include <vector>
#include <chrono>
#include <utility> // For std::pair
int main() {
// Generate approximately 10 MB of in-memory text data
const size_t target_size = 10 * 1024 * 1024; // 10 MB
@jweinst1
jweinst1 / multi-hash-graph.cpp
Last active February 22, 2026 10:35
design of multi map hash map for graph db
#include <iostream>
#include <vector>
#include <unordered_map>
#include <random>
#include <chrono>
#include <cstdint>
#include <limits>
#include <cstring>
#include <cstdlib>
#include <cstdio>
@jweinst1
jweinst1 / hash_byte_arr.cpp
Created February 22, 2026 00:18
C++ hash variable sized byte array
#include <cstdint>
#include <cstring>
#include <cstdio>
#include <random>
#include <limits>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>
#include <map>
@jweinst1
jweinst1 / per_region_quantize.cpp
Last active February 20, 2026 10:02
region specific pattern of quantization for floats
#include <cstdint>
#include <cstring>
#include <cstdio>
#include <random>
#include <limits>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>
#include <map>
@jweinst1
jweinst1 / mean_bit_set.cpp
Created February 16, 2026 21:28
calculates mean via pop count approximation
struct ConstexprBitset64 {
uint64_t block = 0;
constexpr void set(size_t idx) {
block |= uint64_t{1} << idx;
}
constexpr void clear(size_t idx) {
block &= ~(uint64_t{1} << idx);
}
@jweinst1
jweinst1 / CMakeLists.txt
Created February 16, 2026 01:03
PyBind11 Example After brew install
cmake_minimum_required(VERSION 3.14)
project(kvstore_python LANGUAGES CXX)
# ----------------------------
# 1) Find Python
# ----------------------------
find_package(Python COMPONENTS Interpreter Development REQUIRED)
message(STATUS "Python executable: ${Python_EXECUTABLE}")
message(STATUS "Python include dirs: ${Python_INCLUDE_DIRS}")
@jweinst1
jweinst1 / hamming_llm.cpp
Last active February 13, 2026 20:34
Hamming distance based LLM without need for training
#include <iostream>
#include <vector>
#include <string>
#include <random>
#include <unordered_map>
#include <arm_neon.h> // Specialized for your M2 chip
// 1024-bit vector = 128 bytes = 2 Cache Lines
// We use alignas(64) to ensure the CPU doesn't cross cache line boundaries
struct alignas(64) HyperVector {
@jweinst1
jweinst1 / slower_page_part_hash_insert.cpp
Created January 25, 2026 01:02
slower page partitioned hash insert.
static inline bool insertToSpecPage(uint32_t* page, uint32_t hash, const size_t mask) {
size_t spot_i = hash & mask;
for (int i = 0; i <= mask; ++i)
{
if (page[i] == 0) {
page[i] = hash;
return true;
}
spot_i = (spot_i + 1) & mask;
}
@jweinst1
jweinst1 / basic_probe_map.cpp
Created January 23, 2026 22:01
Basic probing map in C++
enum class HashQueryRes {
Empty,
Occupied,
Found
};
class HashOnlyLinearMap {
struct KVPair {
uint32_t _hash = 0;
@jweinst1
jweinst1 / mmap_write_perf_tlb_Test.cpp
Last active January 23, 2026 01:15
Shows performance of TLB mmap writes across 1, 100, and 1024 pages
#include <iostream>
#include <vector>
#include <unordered_map>
#include <random>
#include <chrono>
#include <cstdint>
#include <limits>
#include <cstring>
#include <cstdlib>
#include <filesystem>