thys2/zre8.sc
changeset 403 6291181fad07
parent 395 5bffeacdf17e
equal deleted inserted replaced
396:cc8e231529fb 403:6291181fad07
    60         //start pos, original regex --> result entry
    60         //start pos, original regex --> result entry
    61 
    61 
    62 
    62 
    63 var pos : Int = 0
    63 var pos : Int = 0
    64 
    64 
       
    65   //size: of a Aregx for testing purposes 
       
    66   def size(r: Rexp) : Int = r match {
       
    67     case ZERO => 1
       
    68     case ONE => 1
       
    69     case CHAR(_) => 1
       
    70     case SEQ(r1, r2) => 1 + size(r1) + size(r2)
       
    71     case ALT(r1, r2) => 1 + List(r1, r2).map(size).sum
       
    72     case STAR(r) => 1 + size(r)
       
    73   }
       
    74 
    65 
    75 
    66 
    76 
    67 //input ..................
    77 //input ..................
    68 //          ^       ^
    78 //          ^       ^
    69 //          p       q
    79 //          p       q
    80     mems.get((pos, r)) match {
    90     mems.get((pos, r)) match {
    81         case Some(m) => 
    91         case Some(m) => 
    82             // c match {
    92             // c match {
    83             //     case StarC(m, vs, inside) => vs.length
    93             //     case StarC(m, vs, inside) => vs.length
    84             // }
    94             // }
    85             val idx = m.parents.lastIndexWhere(c0 => c0.starIters < c.starIters)
    95             val idx = m.parents.lastIndexWhere(c0 => c0.starIters <= c.starIters)
    86             if(m.parents.size == 2){
    96             // if(m.parents.size == 1){
    87                 println("third parent added")
    97             //     println("third parent added")
    88                 println(simpleCtxDisplay(c))
    98             //     println(simpleCtxDisplay(c))
    89                 println("the other parents")
    99             //     println("the other parents")
    90                 m.parents.foreach(c00 => println(c00.starIters))
   100             //     m.parents.foreach(c00 => println(c00.starIters))
    91                 println(idx + 1)
   101             //     println(idx + 1)
    92                 println("c's star iters: "+ c.starIters)
   102             //     println("c's star iters: "+ c.starIters)
    93                 println(s"the others' star iters: ${m.parents(0).starIters}")
   103             //     println(s"the others' star iters: ${m.parents(0).starIters}")
    94             }
   104             // }
    95             m.parents.insert(idx + 1, c)
   105             m.parents.insert(idx + 1, c)
    96             //m.parents = m.parents:::List(c)
   106             //m.parents = m.parents:::List(c)
    97             m.result.find(endPos_value => endPos_value._1 == pos) match {
   107             m.result.find(endPos_value => endPos_value._1 == pos) match {
    98                 // case Some((i, v)) => 
   108                 // case Some((i, v)) => 
    99                 //   original_up(v, c, starIters)
   109                 //   original_up(v, c, starIters)
   459 //def crystalizeZipper
   469 //def crystalizeZipper
   460 
   470 
   461 for(i <- 1 to 2) {
   471 for(i <- 1 to 2) {
   462     mems.clear()
   472     mems.clear()
   463 println(s"there are $i number of a's")
   473 println(s"there are $i number of a's")
   464 val re1 = ("a" | "aa" | "ab").%//(("a" | "b") ~ "c" | ("b" | "e") ~ "c" ) ~ "f"
   474 val re1 = ("a" | "ab" ) ~ ("c" | "bc")//(("a" | "b") ~ "c" | ("b" | "e") ~ "c" ) ~ "f"
   465 val re1Lexed = lex(re1, "a"*i)
   475 val re1Lexed = lex(re1, "abc")
   466 
   476 
   467 //drawZippers(re1Lexed)
   477 //drawZippers(re1Lexed)
   468 println("size of actual zipper (including memoized contexts")
   478 println("size of actual zipper (including memoized contexts")
   469 println(actualZipperSize(re1Lexed))
   479 println(actualZipperSize(re1Lexed))
   470 //println(re1Lexed)
   480 //println(re1Lexed)
   478         val Sequ(Empty, vp) = v
   488         val Sequ(Empty, vp) = v
   479         println(vp)
   489         println(vp)
   480 }
   490 }
   481 )
   491 )
   482 
   492 
   483   val mb = 1024*1024
       
   484 val runtime = Runtime.getRuntime
       
   485 println("ALL RESULTS IN MB")
       
   486 println("** Used Memory:  " + (runtime.totalMemory - runtime.freeMemory) / mb)
       
   487 println("** Free Memory:  " + runtime.freeMemory / mb)
       
   488 println("** Total Memory: " + runtime.totalMemory / mb)
       
   489 println("** Max Memory:   " + runtime.maxMemory / mb)
       
   490 
   493 
   491 }
   494 }
   492 
   495 
   493 mems.clear()
   496 mems.clear()
   494 val re2 = SEQ(ONE, "a")
   497 val re2 = SEQ(ONE, "a")