Skip to content

Instantly share code, notes, and snippets.

@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>(
// 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)]