This file contains hidden or 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
| " ============================================================================= | |
| " Vim config file -- Sander Mathijs van Veen <smvv@kompiler.org> -- since 2011 | |
| " ============================================================================= | |
| set nocompatible " Be iMproved! | |
| " Terminal configuration | |
| " ----------------------------------------------------------------------------- | |
| set background=dark |
This file contains hidden or 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
| /* | |
| The errors below are fixed by adding additional curly braces to the macro body. | |
| This is a bug in the macro system. | |
| btree.rs:508:20: 508:24 error: unresolved name `list`. Did you mean `t`? | |
| btree.rs:508 assert!(list.len() >= values.len()); | |
| ^~~~ | |
| <core-macros>:52:4: 69:5 note: in expansion of assert! | |
| btree.rs:508:12: 508:48 note: expansion site | |
| btree.rs:505:4: 525:5 note: in expansion of check_values! |
This file contains hidden or 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
| use std::io; | |
| use std::util; | |
| enum List { | |
| Cons(uint,~List), | |
| Nil() | |
| } | |
| fn cons(x : uint, l : ~List) -> ~List{ | |
| return ~Cons(x,l); |
This file contains hidden or 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
| /* | |
| rustc -O -L. --test -o btree btree.rs | |
| btree.rs:68:24: 79:7 error: mismatched types: expected `~[~str]` but found `std::iterator::MapIterator<,&std::option::Option<TreeItem<T,U>>,~(),std::vec::VecIterator<,std::option::Option<TreeItem<T,U>>>>` (expected vector but found struct std::iterator::MapIterator) | |
| btree.rs:68 let buf : ~[~str] = tree.nodes.iter().transform(|x| { | |
| btree.rs:69 ~"\t".repeat(indent).push_str(match *x { | |
| btree.rs:70 Some(TreeNode { key: k, value: tree }) => { | |
| btree.rs:71 let buf = ~"Node(key=...)\n"; | |
| btree.rs:72 buf //buf.push_str(tree.to_str()) | |
| btree.rs:73 } | |
| ... |
This file contains hidden or 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
| use std::io; | |
| struct Tree<K, V> { | |
| used: uint, | |
| nodes: [Option<TreeItem<K, V>>, ..3], | |
| } | |
| enum TreeItem<K, V> { | |
| TreeNode { key: K, value: ~Tree<K, V> }, | |
| TreeLeaf { key: K, value: V }, |
This file contains hidden or 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 insert_node<K: Eq + Ord, V>(tree: &mut BTree<K, V>, key: K, | |
| value: V) -> bool { | |
| debug!("insert key-value pair: %? -> %?", key, value); | |
| if tree.is_empty() { | |
| insert_leaf(tree, 0, key, value); | |
| return true; | |
| } | |
| let capacity = tree.nodes.len(); |
This file contains hidden or 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
| //! A B-tree is a tree data structure that keeps data sorted and allows | |
| //! searches, sequential access, insertions, deletions in logarithmic time. | |
| //! B-trees are different from binary search trees because a b-tree node can | |
| //! have more than two children (also known as the *degree* of a b-tree). | |
| //! | |
| //! Basic example: | |
| //! | |
| //! ~~~ rust | |
| //! let mut s = BTree::new(); | |
| //! |
This file contains hidden or 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
| use std::vec; | |
| struct Message; | |
| impl Message { | |
| pub fn with_ptr<T>(&self, f: &fn(*u8, uint) -> T) -> T { | |
| unsafe { | |
| let data = vec::raw::to_ptr([1 as u8]); | |
| let len = 1 as uint; |
This file contains hidden or 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
| // The number of keys is chosen to vary between d and 2d, where d is the | |
| // minimum number of keys and d+1 is the minimum degree (branching factor) of | |
| // the tree. In this case, d = 2 which results in degree = 5. | |
| static BTreeDegree : uint = 5; | |
| pub struct BTree<K, V> { | |
| priv pairs: [NodeContent<K, V>, ..BTreeDegree], | |
| } | |
| enum NodeContent<K, V> { |
This file contains hidden or 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
| struct Env { | |
| out: ~str, | |
| } | |
| impl Env { | |
| fn write(&self, msg: ~str) { | |
| self.out += msg; | |
| } | |
| } |
NewerOlder