Skip to content

Instantly share code, notes, and snippets.

View thomcc's full-sized avatar
🦀

Thom Chiovoloni thomcc

🦀
View GitHub Profile
//! initial version courtesy of @danielhenrymantilla.
//!
//! extended to support fns with args/return types,
//! visibility, #[attributes], unsafe, const, async,
//! extern "abi" ...
//!
//! left as an exercise for later (cuz it sux):
//! - generics?
//! - where clauses?
//! - probably other shit im missing
/// Something like a `flat_map` over a fallible iterator.
///
/// Note that the `map` itself is not fallible.
///
/// See test at end of file for usage.
//
// TODO this should probably take `impl IntoIterator<IntoIter = I>` but the
// generics here are already so fucking complicated, and i'm worried that
// will cause inference errors
/// Wrapper around an `impl std::error::Error` that makes it "mostly" clonable.
pub struct ClonableError<E> {
error: Option<E>,
// tbh these are all anybody cares about for Errors anyway.
display: Box<str>,
debug: Box<str>,
}
impl<E> Clone for ClonableError<E> {
#include <string>
#include <vector>
#include <cstddef>
#include <memory>
#include <iostream>
#include <cassert>
#include <stdexcept>
struct XmlNode {
struct Attribute {
// Coord is a way of storing a 2d integer vector (e.g. vec2i or similar) as a
// value type by packing it into a number. It will do what you want in a Map or
// Set, you can compare them for equality, and it should be free of alloctions
// (at least in Spidermonkey and V8, but probably anywhere else too).
//
// The downside is that it's a pain to debug, use, and it has ugly syntax. It's
// type safe (in typescript) tho.
//
// Each component is stored as a 15 bit (signed, 2's complement) integer. These
#![feature(test)]
#![recursion_limit = "1024"]
#![allow(dead_code)]
#![feature(stdsimd)]
extern crate test;
extern crate rand;
// Defines a little benchmarking DSL macro. If you've been linked here, it's safe to ignore.
#[macro_use]
#[derive(Debug, Clone, Default)]
pub struct Shape {
pub vertices: Vec<V3>,
pub tris: Vec<[u16; 3]>,
}
impl Shape {
// ...
pub fn new_sphere(radius: f32, bands: (usize, usize)) -> Self {
use std::{f32, u16};
/// ```
/// # #[allow(dead_code)] fn code_requiring_fma_and_avx() {}
/// # #[allow(dead_code)] fn code_requiring_sse41() {}
/// # #[allow(dead_code)] fn code_requiring_sse2() {}
/// # #[allow(dead_code)] fn fallback_code() {}
/// # fn main() {
/// let thing = t3m::simd_match! {
/// // Comma separate required target features to require both.
/// "fma", "avx" => code_requiring_fma_and_avx(),
/// "sse4.1" => code_requiring_sse41(),
#[derive(Default, Debug, Clone)]
pub struct RadixSorter {
// TODO: only need one buffer.
unsorted_buf: Vec<(usize, u32)>,
pub sorted_buf: Vec<(usize, u32)>,
}
impl RadixSorter {
#[inline]