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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> | |
<script src="http://d3js.org/d3.v2.js"></script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
/** | |
* A convenient function for taking a transformation (with rotation) on |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> | |
<script src="http://d3js.org/d3.v3.js"></script> | |
<style> | |
path {stroke-width: 4px; fill:none; stroke:#000} | |
circle {fill:#000} | |
</style> | |
</head> |
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
pub unsafe fn alloc_mega_group(mblocks: nat) -> ~Block { | |
let n = MBLOCK_GROUP_BLOCKS(mblocks); | |
let mut prev_link = &mut free_mblock_list.p; | |
let mut best: Option<(&mut BlockData, &mut BlockMeta)> = None; | |
loop { | |
match prev_link { | |
&None => break, | |
// NB: need to match it out, so we don't take out a | |
// reference on prev_link that will interfere with the | |
// take() |
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
pub fn new(n: nat) -> MBlock { | |
let ptr = unsafe { aligned_alloc_raw(MBLOCK_SIZE as size_t, (MBLOCK_SIZE * n) as size_t) }; | |
assert!(!ptr::is_null(ptr)); | |
let mb = MBlock{ptr: ptr}; | |
// XXX should this really be here? | |
unsafe { | |
let mut block = mb.first_block_ptr(); | |
let mut bd = mb.first_bdescr_ptr(); | |
while (block <= mb.last_block_ptr()) { | |
(*bd).data.start = cast_ptr(block); |
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
pub fn alloc_mega_group(mblocks: nat) -> ~Block { | |
let n = MBLOCK_GROUP_BLOCKS(mblocks); | |
enum SearchResult<'a> { | |
PerfectMatch(~Block), | |
BestMatch(&'a mut BlockData, &'a mut BlockMeta), | |
NoMatch | |
} | |
// tail-recursive style makes the borrow-checker *a lot* | |
// happier, since some of the aliasing effects that occur when | |
// local mutable variables are reused go away (fresh lexical |
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
#[allow(dead_code)]; | |
use std::util; | |
enum List<T> { | |
Cons(T, ~List<T>), | |
Nil | |
} | |
fn pop<T>(prev: &mut ~List<T>) -> Option<~List<T>> { |
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
pub fn freplace<T>(mut src: T, dest: &mut T) -> T { | |
util::swap(dest, &mut src); | |
src | |
} | |
fn pop<T>(prev: &mut ~List<T>) -> Option<~List<T>> { | |
Some(freplace(util::replace(match prev { | |
&~Cons(_, ref mut rs) => rs, | |
&~Nil => return None |
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
fn pop<T>(prev: &mut ~List<T>) -> Option<~List<T>> { | |
let xs = util::replace(match prev { | |
&~Cons(_, ref mut rs) => rs, | |
&~Nil => return None | |
}, ~Nil); | |
Some(util::replace(prev, xs)) | |
} |
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
Less => { | |
let inserted = find_or_insert(&mut save.left, key, value); | |
skew(save); | |
split(save); | |
inserted | |
} |
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
enum Bar { | |
Z(int), | |
S(~Bar) | |
} | |
fn foo<'a>(x: &'a mut Bar) -> &'a int { | |
match x { | |
&Z(_) => { | |
fail!() | |
}, |
OlderNewer