Skip to content

Instantly share code, notes, and snippets.

View huonw's full-sized avatar

Huon Wilson huonw

View GitHub Profile
Compiling with --cfg idx_reverse --opt-level=3
Samples: 27K of event 'cycles', Event count (approx.): 18709445305
39.57% fannkuchredux fannkuchredux [.] fannkuch::h3c886b0c9fd4152cYda
37.13% fannkuchredux fannkuchredux [.] reverse::h8a92c2595b4c13ffaca
11.71% fannkuchredux fannkuchredux [.] next_permutation::h0b3a5cb57aef64bcdba
7.96% fannkuchredux fannkuchredux [.] rotate::ha766464a328f18a5Kaa
3.40% fannkuchredux fannkuchredux [.] vec::Vec$LT$T$GT$::push_all::h9473677268961327811
0.01% fannkuchredux [kernel.kallsyms] [k] native_write_msr_safe
// from http://www.reddit.com/r/rust/comments/27s7ei/comparing_knn_in_rust/ci43euj
use std::kinds::marker;
use std::cmp;
use std::mem;
use std::mem::transmute;
// cribbed from both core::iter and core::slice
struct SliceZipIterator<'lt, A, B> {
use std::any::{Any,AnyRefExt};
trait Object {
fn as_any<'a>(&'a self) -> &'a Any {
self as &Any
}
}
impl Object for uint {}
impl Object for &'static str {}
#![no_std]
extern crate rlibc;
pub fn foo(x: *mut u8, y: *u8) {
unsafe {rlibc::memcpy(x, y, 1);}
}
@huonw
huonw / main.rs
Last active August 29, 2015 13:58 — forked from jsancio/main.rs
extern crate collections;
use collections::TrieMap;
fn main() {
let workers = vec!(
("Jack", vec!((0000, 200), (500, 1200))),
("Jackie", vec!((0000, 600), (800, 1300))),
("Marty", vec!((400, 600), (1100, 1600), (1700, 2359))),
("Ronald", vec!((600, 1200), (1300, 1800), (1900, 2359))),
@huonw
huonw / gist:9759348
Last active August 29, 2015 13:57 — forked from bvssvni/gist:9674632
//! Chain macro in Rust
//!
//! A typical usage is to avoid nested match expressions.
//!
//! Supports:
//! - Pattern matching
//! - Or expressions (A | B => ...)
//! - Guarded statements (x if <cond> => ...)
//! - Implicit else (requires all arms to return same type)
@huonw
huonw / recursive.rs
Last active August 29, 2015 13:57 — forked from jroweboy/error
extern crate collections;
use collections::hashmap::HashMap;
struct Node {
data : ~str,
children : ~HashMap<~str, Node>,
}
impl Node {
fn new(data: ~str) -> Node {
//! Monad macro in Rust
//!
//! A typical usage is to avoid nested match expressions.
//!
//! Supports:
//! - Pattern matching
//! - Or expressions (A | B => ...)
//! - Guarded statements (x if <cond> => ...)
#[feature(macro_rules)];
@huonw
huonw / test.rs
Last active August 29, 2015 13:56 — forked from thehydroimpulse/test.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.