Guest User

Untitled

a guest
Mar 13th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.05 KB | None | 0 0
  1. import scala.scalanative.native._
  2.  
  3. object Massiv extends App {
  4.   type BoolMassiv = Ptr[CBool]
  5.   type BoolMatrix = Ptr[BoolMassiv]
  6.  
  7.   object BoolMatrix {
  8.     def alloc(outerSize: CSize, innerSize: CSize): BoolMatrix = {
  9.       val massiv = stdlib.malloc(sizeof[BoolMassiv] * outerSize).cast[BoolMatrix]
  10.       for (outerIndex ← 0L until outerSize) {
  11.         massiv(outerIndex) = stdlib.malloc(sizeof[CBool] * innerSize).cast[BoolMassiv]
  12.         val innerMassiv = massiv(outerIndex)
  13.         for (innerIndex ← 0L until innerSize) {
  14.           innerMassiv(innerIndex) = ((outerIndex + outerIndex) % 2) == 0
  15.         }
  16.       }
  17.       massiv
  18.     }
  19.  
  20.     def print(massiv: BoolMatrix, outerSize: CSize, innerSize: CSize): Unit = {
  21.       for (outerIndex ← 0L until outerSize; innerIndex ← 0L until innerSize) {
  22.         val innerMassiv = massiv(outerIndex)
  23.         val boolValue = innerMassiv(innerIndex)
  24.         println(s"$boolValue $outerIndex/$innerIndex")
  25.       }
  26.     }
  27.   }
  28.  
  29.   val massiv = BoolMatrix.alloc(1000, 4)
  30.   BoolMatrix.print(massiv, 1000, 4)
  31. }
Add Comment
Please, Sign In to add comment