Should be an easy one.
I'm working on Scala trying to handle long sequences of binary data. That is long lists of 0's and 1's. What is the 'best' way to store/access this kind of data.
The important point here is memory optimisation, so I would like to avoid using an entire byte to store a boolean. Also access is somwhat important, so ...
I'm working on Scala with VERY larg lists of Int (maybe large) and I need to compress them and to hold it in memory.
The only requirement is that I can pull (and decompress) the first number on the list to work with, whithout touching the rest of the list.
I have many good ideas but most of them translate the numbers to bits.
Example:
...
I would like to know what is the memory usage of BitSet in Scala.For example, if I do:
var bitArray:BitSet=new BitSet(10)
bitArray.add(0)
bitArray.add(2)
bitArray.add(4)
bitArray.add(6)
bitArray.add(8)
How does that compare with and array containing the even numbers 0,2,4,6,8?
What about writing a number in binary:
var...
I have the following class:
class Step(kind:TipoStep.Value,
message:String = "",
study:List[Formula] = List(),
lastAdd:Set[Formula] = Set(),
lastDel:Set[Formula] = Set(),
add:List[Formula] = List(),
del:List[Formula] = List()
) {
def this(step:Step,
...
I am using SBT as my build tool for building a Scala project.
My problem is, I can't let SBT download its dependencies to my user home directory. Therefore I am looking for a per-user or even better a system-wide setting to tell SBT to put the Ivy cache directory somewhere else.
With maven there is the per-user settings.xml that can be...
I am trying to create a layout that will looking like:
+---+--------+---+
| | | |
| | | |
+---+ +---+
| | | |
| | | |
+---+--------+---+
Central cell should be twice as wide as other. I am trying achieve this with such code:
val panel = new JPanel(new MigLayout("debug", "grow","g...
Hi, I'm taking a look at how Menu.Builder is pulled together using Boot.scala and there's one thing that confuses me. I do see the option to login/register however it doesn't show up as one of the items on the sitemap. Where does that actually come from...my confusion may come from not much java experience at all...lift I'm starting to...
I've tried to run this code under scala 2.7.3 and 2.7.7 and everytime i get this error. What is wrong?
import scala.io._
def toInt(in: String): Option[Int] =
try {
Some(Integer.parseInt(in.trim))
} catch {
case e: NumberFormatException => None
}
def sum(in: Seq[String]) = {
val ints = in.flatMap(s => toInt(s))
ints...
If I create a Set in Scala using Set(1, 2, 3) I get an immutable.Set.
scala> val s = Set(1, 2, 3)
s: scala.collection.immutable.Set[Int] = Set(1, 2, 3)
Q1: What kind of Set is this actually? Is it some hash-set? What is the complexity of look-ups for instance?
Q2: Where can I read up on this "set-creating" method? I thought that it w...
Using scala, 2.8:
import scala.collection.mutable
import mutable.MultiMap
val m = new mutable.HashMap[String, mutable.Set[String]] with MultiMap[String, String]
m.addBinding("key", null)
m exists { _._2 contains null }
prints false
m exists { _._2 isEmpty }
prints false
m("key").size
prints 1
How do I find the first key (or any...
I'm looking for open source applications written for the Lift Web framework. I want to read their code, and learn the best Lift-ish coding style from those.
Anyone knows good open source Lift web applications?
...
Im currently working with two actors in scala. One, the producer, produces some data and sends it to a parcer. The producer sends a HashMap[String,HashMap[Object,List[Int]]] through a message (along with this to mark the sender):
parcer ! (this,data)
The parser is constantly waiting for messages like so:
def act(){
loop{
re...
scala> def foo[U](t: Any) = t.asInstanceOf[U]
foo: [U](t: Any)U
scala> val s: String = foo("hi")
scala> val n = foo("hi")
java.lang.ClassCastException: java.lang.String cannot be cast to scala.runtime.Nothing$
at .<init>(<console>:6)
at .<clinit>(<console>)
at RequestResult$.<init>(<console>:9)
at RequestResult$.<clinit...
I want to implement a prototype-based system in Scala. At the root of the type hierarchy is the ROOT node, which has a prototype that refers to itself.
The following code demonstrates what I'm trying to do:
class Node(val prototype: Node) {
private def this() = this(this)
}
object Node {
val ROOT = new Node
}
Unfortunately, ...
I'm pretty sure this is very simple to do in Scala, but I can't seem to figure out what hints the type system needs to make this work.
I want to have an abstract Printable class and then implicitly convert other classes to it. More specifically I want to implicitly convert Byte to Printable and Array[Byte] to Printable.
So I've done th...
In Ruby I can write this:
case n
when 0...5 then "less than five"
when 5...10 then "less than ten"
else "a lot"
end
How do I do this in Scala?
Edit: preferably I'd like to do it more elegantly than using if.
...
I wanted to compare the cardinality of two sets in Scala. Since stuff sometimes "just work" in Scala, I tried using < between the sets. It seems to go through, but I can't make any sense out of the result.
Example:
scala> Set(1,2,3) < Set(1,4)
res20: Boolean = true
What does it return?
Where can I read about this method in the API?
...
Hi,
I had the idea to start investigating in creating and using media components in Java but I didn't find any convincing framework. The two that I found were
Java Media Framework (JMF) : it seems so powerful, not so fast but the last update was in 2003.
Java Media Components (JMC) : from what I found, it's easier to use than JMF but i...
What is the difference between following two?
1#
trait B extends A {
}
2#
trait B { self: A =>
}
where A is an abstract class.
>> EDIT:
Please explain with respect to the following example of Ducks with pluggable flying and quacking behaviors:
abstract class Duck {
def fly(): Unit
def quack(): Unit
def swim() {
pri...
hi,
There has been a lot of movement in the Scala based web framework community of late. Coming from Rails, Rake, ActiveRecord and migrations - which is a good Scala framework to build production sites in ?
A small hit in performance is acceptable if it gives a much better maintainable code. It would also be nice if collaboration fea...