This file contains 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
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>( |
This file contains 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
// 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)] |
This file contains 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
// 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; |