Skip to content

Instantly share code, notes, and snippets.

View nybble41's full-sized avatar

Jesse McDonald nybble41

  • Marion, Iowa, USA
View GitHub Profile
#![feature(unboxed_closures)]
#![feature(fn_traits)]
pub mod hlist {
mod private {
pub trait Sealed {}
}
pub trait HList: private::Sealed {}
@nybble41
nybble41 / avltree-iterator.rs
Created April 10, 2020 03:12
In-place destructive AVL tree iteration in Rust
pub struct IntoIter<T> {
current: AVLTree<T>,
}
impl<T> IntoIter<T> {
pub fn new(tree: AVLTree<T>) -> Self {
let mut into_iter = IntoIter { current: Empty };
into_iter.traverse_left(tree);
into_iter
}
# Haskell-inspired functional skew heap in Python employing Scott-encoded sum types
# Inspired by <https://doisinkidney.com/posts/2019-10-02-what-is-good-about-haskell.html>
# data Maybe a = Nothing | Just a
nothing = lambda f_nothing, f_just: f_nothing()
just = lambda x: lambda f_nothing, f_just: f_just(x)
# data List a = Nil | Cons a (List a)
nil = lambda f_nil, f_cons: f_nil()
cons = lambda x, xs: lambda f_nil, f_cons: f_cons(x, xs)
import System.Environment
quickIndex :: [a] -> Int -> a
quickIndex xs = \n -> if n < blockSize then xs !! n else (nextLevel (n `div` blockSize)) !! (n `mod` blockSize)
where
blockSize = 32
skipList ys = ys : skipList (drop blockSize ys)
nextLevel = quickIndex $ skipList xs
example :: Integer -> Integer