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 / add_not_bits.txt
Last active September 26, 2025 00:26
closest sub mask in a mash set
>>> bin(0b10100 & ~0b1111)
'0b10000'
>>> bin(0b11000 & 0b1111)
'0b1000'
>>> bin(0b11000 & ~0b1111)
'0b10000'
>>> bin(0b01000 & ~0b1111)
'0b0'
>>> bin(0b11000 & ~0b1111)
'0b10000'
@jweinst1
jweinst1 / iter_by_trail_zeros.txt
Last active September 20, 2025 19:22
a way to check for nearest neighbor with bit ops and xor sets with mash
>>> bin(8)
'0b1000'
>>> bin(12)
'0b1100'
>>> bin(16)
'0b10000'
>>> bin(16 + 0b100)
'0b10100'
>>> bin(16 + 0b100 + 0b100)
'0b11000'
@jweinst1
jweinst1 / bit_maybe_set.rs
Last active September 15, 2025 22:10
Bit set in rust that stores vectors for membership
fn sub_distance<const S: usize>(v1:&[u64;S], v2:&[u64;S]) -> u64 {
let mut total = 0;
for i in 0..S {
total += v1[i] - v2[i];
}
return total;
}
@jweinst1
jweinst1 / absolute_dist_therm.cpp
Last active September 13, 2025 20:48
transform raw floats into thermometer encoding
#include <array>
#include <vector>
#include <cstdint>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <numeric>
@jweinst1
jweinst1 / bitset1024_existence_check.cpp
Last active September 4, 2025 00:39
Runtime calculation of hamming neighbor benchmark
#include <array>
#include <cstdint>
#include <iostream>
#include <random>
#include <chrono>
class RegisterBitset1024 {
public:
static constexpr size_t NUM_BITS = 1024;
static constexpr size_t NUM_REGS = NUM_BITS / 64;
@jweinst1
jweinst1 / 1vs2bitvs4_quantize_test.cpp
Last active September 3, 2025 00:03
compares quantization of means vs 1-2 dim per bit quantize
// bucket_stats.cpp
#include <array>
#include <vector>
#include <unordered_map>
#include <random>
#include <iostream>
#include <algorithm>
#include <chrono>
#include <cstdint>
#include <numeric>
@jweinst1
jweinst1 / benchmark10m.cpp
Last active September 1, 2025 07:53
quantizer into a hash bucket test
#include <array>
#include <vector>
#include <unordered_map>
#include <random>
#include <iostream>
#include <limits>
#include <cstdint>
#include <chrono>
constexpr size_t DIM = 128;
@jweinst1
jweinst1 / 64bitpopcount.cpp
Last active September 3, 2025 00:23
an important benchmark of pop count vs jungle precomp
#include <array>
#include <cstdint>
#include <iostream>
#include <vector>
#include <random>
#include <chrono>
constexpr size_t NUM_BYTES = 1024;
constexpr int N = 10'000'000;
@jweinst1
jweinst1 / hamming_jungle.cpp
Last active August 30, 2025 06:51
Using hamming ladders as an iterator for numbers in a bitset
#include <array>
#include <chrono>
#include <iostream>
#include <cstdint>
// --------------------------------------
// Byte-based 256-bit bitset
// --------------------------------------
struct ConstexprBitset256 {
std::array<uint8_t, 32> blocks{};
@jweinst1
jweinst1 / bits_needed_to_not_collide.cpp
Last active August 27, 2025 23:35
Determines bits needed to not collide
#include <array>
#include <cmath>
#include <cstddef>
#include <algorithm>
#include <iostream>
// helper to compute ceiling of log2 at runtime
constexpr int ceil_log2(float x) {
return static_cast<int>(std::ceil(-std::log2(x)));
}