Skip to content

Instantly share code, notes, and snippets.

// Linear-scan mark-compact collector for causal data structures, i.e. the reference graph is acyclic and the objects
// are ordered by age in the heap (which happens if you use a linear allocator) so they are automatically topologically sorted.
// This algorithm has very high memory-level parallelism which can be exploited by modern out-of-order processors, and should
// be memory throughput limited.
void collect(void) {
// Initialize marks from roots.
memset(marks, 0, num_nodes * sizeof(uint32_t));
int newest = 0, oldest = num_nodes;
for (int i = 0; i < num_roots; i++) {
marks[roots[i]] = 1;
// https://godbolt.org/z/KoMfsEszq
// https://godbolt.org/z/18PKTE6Ej
// https://godbolt.org/z/vGs9Eeoo5
// Base on Hacker's Delight section 2.3 THE 16 BINARY LOGICAL OPERATIONS
#![feature(portable_simd)]
extern crate core;
#[repr(u8)]
@interacsion
interacsion / group_by.rs
Created February 17, 2024 18:28
Rust `group_by` (Reader discretion is advised)
use core::cell::RefCell;
use std::collections::{BTreeMap, VecDeque};
use std::rc::Rc;
pub trait GroupBy<Item> {
fn group(self) -> impl Iterator<Item = (Item, impl Iterator<Item = Item>)>
where
Item: PartialEq + Copy;
fn group_by<Key, KeyFn>(