What is most efficient way to do immutable byte arrays in Scala? -


I have to get an array of bytes (array [byte]) from somewhere (read from file, socket, etc.) And then provide an effective way of pulling bits out of it (like providing the function to extract the 32-bit integer from the array in Oreset N) I then want to wrap the byte array (hide it) so that the bits from the array Can be done to pull out (possibly taking each bit Using lazy val gram).

I have to imagine having a wrapping class, to prove the array content, an irreversible byte array type in the constructor is never modified. Indexed Sick [byte] seemed relevant, but I could not work to go from Array [Bite] to Indexesac [Byte].

Part 2 of the question, if I use indexed sick [byte] then the result code may be slow? I need a code to run as soon as possible, so stay with Array [Bite] if the compiler can work better with it.

I can write an envelope around the array, but this slow down point is an indication of an additional level of access to the bytes in the array. Performance is important because the number of array access will be required which is necessary. I need a quick code, but at the same time would like to code well thanks!

PS: I am a scala novice.

treatment array [t] like a indexed sike [t ] can be very easy:

  Array (1: byte): indexed sick [byte] / trigger view wrap wrapbite array (array (1: byte)) // clear Calling  

Unblocking will kill you for a long time before an additional layer of interception.

  C: \ & Gt; Scala -Xprint: erasure -e "{val a = array (1: byte); well b1: byte = a (0); well b2 = (a: indexed sike [byte]) (0)}" [[ Syntax tree at end of break]] // scala source: scalacmid 5680604016099242427.s cell valo A: array [byte] = scala. Array.Apple ((1: byte), scala.a.pdf. rapbetaure (array [byte] {}); Val B1: Byte = A.Apple (0); Val b2: Byte = Scala.bitt.insbox ((scala.this.Predef.wrapByteArray (A): Indexed SEC). Apely (0));  

To avoid this, the Scala Collection library should be special on the element type, as is the case with Tuple1 and Tuple2 . I have been told that this plan has been made, but it is more than just slapping @specialized , so I do not know how long it will take.

Update

Yes, wrappedArray is shaky, though archive. There is no way to make changes to indexx [byte] so that you do not just trust customers who do not have to be put in a temporary interface. Scalaz will be involved in the next release which prevents it.

attribute SeqLike [+ A, + Repr] IterableLike [A, Repr] { Self = & gt; DFF application (IDX: IT): A}

At the JVM level, this signature has been deleted:

  def applied (idx: int) If your archive includes the primitives, that is, the subtype of  AnyVal , they should be boxed in the related cover to return from this method. For some applications, this is a major performance concern. To avoid this, the entire libraries have been written in Java, especially. 

was added to Scala 2.8 so that the compiler could be directed that different versions of the method can be produced according to the classic or the old type permutations. It has already been implemented in some places in the standard library, e.g. Tuvaln , ProductN , function {0, 1, 2} . If this collection was also applied to the collection, then the cost of this display could be reduced.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -