This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile with clang or MSVC (WINDOWS ONLY RN) | |
// | |
// Implementing a POC green threads system using safepoints to show how cheap and simple it can | |
// be done, all you need to do is call SAFEPOINT_POLL in your own language at the top of every | |
// loop and function body (you can loosen up on this depending on the latency of pausing you're | |
// willing to pay). Safepoint polling is made cheap because it's a load without a use site | |
// which means it doesn't introduce a stall and pays a sub-cycle cost because of it (wastes resources | |
// sure but doesn't block up the rest of execution). | |
// | |
// # safepoint poll |
#!/usr/bin/env sed -re s|^|\x20\x20\x20\x20| -e s|^\x20{4}\x23\x23{(.*)$|<details><summary>\1</summary>\n| -e s|^\x20{4}\x23\x23}$|\n</details>| -e s|^\x20{4}\x23\x23\x20?|| -e s|\x0c|\x20|
license, imports
# Yannakakis.py by Paul Khuong
#
# To the extent possible under law, the person who associated CC0 with
# Yannakakis.py has waived all copyright and related or neighboring rights
# to Yannakakis.py.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I happened to be looking at some of Cranelift's code, and I noticed that their constant-time dominates() | |
# check was using a somewhat more ad-hoc version of a hidden gem from the data structures literature called the | |
# parenthesis representation for trees. As far as I know, this was invented by Jacobson in his 1989 paper | |
# Space-Efficient Static Trees and Graphs. I first learned about it from the slightly later paper by Munro and Raman | |
# called Succinct Representations of Balanced Parentheses and Static Trees. I figured I'd give it an extremely | |
# quick intro and then show how it leads to a (slightly better) version of Cranelift's algorithm. | |
# | |
# This parenthesis representation of trees is surprisingly versatile, but its most striking feature is that | |
# it lets us query the ancestor relationship between two nodes in a tree in constant time, with a few instructions. | |
# And the idea is extremely simple and intuitive if you just draw the right kind of picture. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This can grow a Robin Hood linear probing hash table near word-at-a-time memcpy speeds. If you're confused why I use 'keys' | |
// to describe the hash values, it's because my favorite perspective on Robin Hood (which I learned from Paul Khuong) | |
// is that it's just a sorted gap array which is MSB bucketed and insertion sorted per chain: | |
// https://pvk.ca/Blog/2019/09/29/a-couple-of-probabilistic-worst-case-bounds-for-robin-hood-linear-probing/ | |
// The more widely known "max displacement" picture of Robin Hood hashing also has strengths since the max displacement | |
// can be stored very compactly. You can see a micro-optimized example of that here for small tables where the max displacement | |
// can fit in 4 bits: Sub-nanosecond Searches Using Vector Instructions, https://www.youtube.com/watch?v=paxIkKBzqBU | |
void grow(Table *table) { | |
u64 exp = 64 - table->shift; | |
// We grow the table downward in place by a factor of 2 (not counting the overflow area at table->end). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Blog post: https://creativcoder.dev/merge-k-sorted-arrays-rust | |
// Merge 2 sorted arrays | |
fn merge_2(a: &[i32], b: &[i32]) -> Vec<i32> { | |
let (mut i, mut j) = (0, 0); | |
let mut sorted = vec![]; | |
let remaining; | |
let remaining_idx; | |
loop { | |
if a[i] < b[j] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fish_greeting | |
echo "! COMPUTER_NAME" | |
end | |
set -x EDITOR vim | |
set -x LESS -asrRix8 | |
set -x LANG en_US.UTF-8 | |
set -x LC_ALL en_US.UTF-8 | |
set -x LANGUAGE en_US.UTF-8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import struct | |
import unittest | |
import hypothesis.strategies as st | |
from hypothesis.stateful import Bundle, RuleBasedStateMachine, consumes, invariant, multiple, precondition, rule | |
class VarianceStack: | |
def __init__(self): | |
self.n = 0 |
As tested on Linux:
- An SCM_RIGHTS ancillary message is "attached" to the range of data bytes sent in the same sendmsg() call.
- However, as always, recvmsg() calls on the receiving end don't necessarily map 1:1 to sendmsg() calls. Messages can be coalesced or split.
- The recvmsg() call that receives the first byte of the ancillary message's byte range also receives the ancillary message itself.
- To prevent multiple ancillary messages being delivered
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
#include <sys/mman.h> | |
#include <unistd.h> | |
#include <err.h> | |
#include <sysexits.h> | |
typedef int32_t (*fptr)(int32_t); |
NewerOlder