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
val n = 1e7.toInt | |
val (rawArray, rawBB, rawFloatBuf) = initArrays(n) | |
println("result = " + th.pbench({ | |
var idx = 0 | |
var sum = 0f | |
while(idx < n) { | |
sum += rawArray(idx) | |
idx += 1 | |
} | |
sum |
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
trait ArrayLike[@specialized T] { | |
def apply(idx: Int) : T | |
def update(idx: Int, value: T) | |
def length: Int | |
def size: Int = length | |
} | |
def sumArrayLike(arr: ArrayLike[Float]): Float = { | |
var idx = 0 | |
var sum = 0f |
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
trait ArraySummer[-T] { | |
def sum(t: T): Float | |
} | |
/** one TypeClass per concrete implementation */ | |
object SpecificSummers { | |
implicit object SimpleWrappedFloatArraySummer extends ArraySummer[SimpleWrappedFloatArray] { | |
def sum(arr: SimpleWrappedFloatArray): Float = { | |
... | |
} |
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
scala> trait A | |
defined trait A | |
scala> | |
scala> class B extends A | |
defined class B | |
scala> class C extends A | |
defined class C |
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
scala> def classExpandMacroImpl(c: Context)(s: c.Expr[Any]) : c.Expr[Any] = { | |
| import c.universe._ | |
| | |
| val cdef = s.tree match { | |
| case Block(List(x:ClassDef), _) => x | |
| case _ => c.abort(c.enclosingPosition, "Was expecting a block w/ a ClassDef") | |
| } | |
| | |
| val q"class $name { ..$body }" = cdef | |
| val newdefs = List[c.universe.Tree](q"def x: Int = z + 7", q"def y: Float = z + 3.2f") |
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
val addedTrait = Select(Select(Select( | |
Select(Ident(newTermName("com")), newTermName("imranrashid")), | |
newTermName("oleander")),newTermName("macros")), | |
newTypeName("SimpleTrait")) |
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
def getValMacro(c: Context)(s: c.Expr[Any]) : c.Expr[Any] = { | |
import c.universe._ | |
val q"val $name = $value" = s.tree | |
c.Expr(value) | |
} | |
def getVal(s: Any) = macro getValMacro | |
getVal{val x = 17} | |
error: exception during macro expansion: |
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
val data = (1 to 10).toSeq.map{i => (0 to i).map{_.toString}.toSeq} | |
val iters = for { | |
sub <- data.iterator | |
d <- sub.iterator | |
} yield d | |
val r = iters.find{x => | |
println(s"checking $x") | |
x == "6" |
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
import kafka.consumer.SimpleConsumer | |
import kafka.common.TopicAndPartition | |
import kafka.api._ | |
import scala.annotation.tailrec | |
import scala.util._ | |
object KafkaSimpleConsumerUtils { | |
def getLastOffset(consumer: SimpleConsumer, topic: String, partition: Int, whichTime: Long, clientName: String): Try[Long] = { | |
val tap = new TopicAndPartition(topic, partition) |
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
// for 20.seconds, etc. | |
import scala.concurrent.duration._ | |
// this is twitters version, only use if you need it to work w/ another API, otherwise prefer the scala version | |
import com.twitter.conversions.time._ | |
//for 6.megabytes.bytes | |
import com.twitter.conversions.storage._ | |
//===QF implicits=== |
OlderNewer