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 / hamming_sep_dist.cpp
Last active December 26, 2025 22:52
and pop count of specific segments of bits for 8 bit dimension vectors
#include <array>
#include <cstdint>
#include <cstddef>
#include <cmath>
#include <cstdio>
#include <climits>
#include <vector>
#include <cassert>
#include <random>
#include <chrono>
@jweinst1
jweinst1 / hamming_centers.cpp
Created December 24, 2025 00:31
sorting bit sets of numbers based on hamming distance
#include <array>
#include <cstdint>
#include <cstddef>
#include <cmath>
#include <cstdio>
#include <climits>
#include <vector>
#include <cassert>
#include <random>
#include <chrono>
@jweinst1
jweinst1 / lzsort.cpp
Last active December 23, 2025 06:19
Automatic Sorting in Rust with bit RZ and LZ instructions
#include <array>
#include <cstdint>
#include <cstddef>
#include <cmath>
#include <cstdio>
#include <climits>
#include <vector>
#include <cassert>
#include <random>
#include <chrono>
@jweinst1
jweinst1 / automeantest.cpp
Created December 9, 2025 08:34
uses optimized popcount of integer series shifted right once to get very fast mean approximation
#include <array>
#include <cstdint>
#include <cstddef>
#include <cmath>
#include <cstdio>
#include <climits>
#include <vector>
#include <random>
#include <cassert>
@jweinst1
jweinst1 / bitsorter.cpp
Last active December 19, 2025 01:39
automatic bit sorting in C++
#include <array>
#include <cstdint>
#include <cstddef>
#include <cmath>
#include <cstdio>
#include <climits>
#include <vector>
#include <cassert>
#include <random>
#include <chrono>
@jweinst1
jweinst1 / murur3.rs
Created November 29, 2025 22:26
murmur3 in rust
pub fn murmur3_x64_64(data: &[u8], seed: u64) -> u64 {
let mut h1 = seed;
let mut h2 = seed;
const C1: u64 = 0x87c37b91114253d5;
const C2: u64 = 0x4cf5ad432745937f;
let mut i = 0;
let len = data.len();
while i + 16 <= len {
@jweinst1
jweinst1 / forward_back_context.py
Created November 16, 2025 00:01
forward and back contexts of a word
class WordContext(object):
def __init__(self, direction, terms):
self.direction = direction
self.terms = terms
def __repr__(self):
return f"{self.direction} - {self.terms}"
def make_context_list(seq, target):
@jweinst1
jweinst1 / hamming_skip_gram.cpp
Created November 3, 2025 00:08
hamming in a skip gram context
#include <vector>
#include <cstdint>
#include <cstdio>
#include <cassert>
#include <iostream>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <string>
@jweinst1
jweinst1 / next_ge_bitset.cpp
Created September 26, 2025 22:02
get the next greatest neighbor in bitset
#include <iostream>
#include <bitset>
int next_ge(uint64_t S, int k) {
uint64_t mask = ~((1ULL << k) - 1);
uint64_t candidates = S & mask;
return __builtin_ctzll(candidates);
}
@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'