Skip to content

Instantly share code, notes, and snippets.

<= 1kB: 1.33% by size, 6.7% by count
<= 2kB: 17.83% by size, 40.26% by count
<= 3kB: 42.19% by size, 75.27% by count
<= 4kB: 52.84% by size, 85.88% by count
<= 5kB: 58.42% by size, 90.21% by count
<= 6kB: 61.36% by size, 92.04% by count
<= 7kB: 63.78% by size, 93.31% by count
<= 8kB: 65.64% by size, 94.16% by count
<= 9kB: 67.32% by size, 94.84% by count
<= 10kB: 68.98% by size, 95.44% by count
abstract class Foo(val tag : Int){
}
class Bar() extends Foo(0){
}
class Baz() extends Foo(1){
}
class Bif() extends Foo(2){
}
require "java"
a = Object.new
CS = Java::JavaLang::CharSequence
class <<a
include Java::JavaLang::CharSequence
end
let sum = List.fold_left (fun s x -> s + x) 0
let split = Str.split (Str.regexp_string " ")
let each_line f =
let rec go () =
let _ = f (input_line stdin) in go ()
in try go() with End_of_file -> ()
let words = Hashtbl.create 8
let count x = try Hashtbl.find words x with Not_found -> 0
abstract class MyList{
def toList : List[Int] = this match {
case Nope => Nil
case Cons(x, y) => x :: y.toList
}
override def equals(that : Any) = that match {
case (that : MyList) => this.toList == that.toList;
case _ => false;
}
@DRMacIver
DRMacIver / splaytree.scala
Created March 7, 2009 16:08
splaytree.scala
package splaytree;
private final class BinaryNode[K, V](
var key : K,
var value : V){
var left : BinaryNode[K, V] = null
var right : BinaryNode[K, V] = null
final def minKey : K = if (left != null) left.minKey else key
package scala.collection.immutable;
private[immutable] object VectorUtils{
val delta = 5;
val ratio = 2;
def rotateL[T](x : Vector[T], t : T, y : VectorBin[T]) =
if (y.left.size < ratio * y.right.size) singleL(x, t, y)
else doubleL(x, t, y);
def rotateR[T](x : VectorBin[T], t : T, y : Vector[T]) =
object timeout{
private val _doomsday = new scala.util.DynamicVariable[Long](Long.MaxValue);
def doomsday = _doomsday.value;
def timeRemaining = doomsday - System.currentTimeMillis;
def checkpoint = if (System.currentTimeMillis > _doomsday.value) throw DieNow;
def timeout[T](time : Long)(t : =>T) : Option[T] = _doomsday.withValue(System.currentTimeMillis + time){
try { Some(t) } catch { case DieNow => None }
}
object Loops{
def loop(cond : =>Boolean)(action : =>Unit){
try {
while(cond){
try { action } catch { case Continue => }
}
} catch { case Break => }
}
def foreach[T](its : Iterable[T])(action : T=>Unit){
object builders {
trait Builder[From, To, Elem1] {
def += (elem: Elem1)
def result: To
}
implicit def listBuilder[A, B] = new Builder[List[A], List[B], B] {
private val buf = new scala.collection.mutable.ListBuffer[B]
def += (elem: B) { buf += elem }