<commit_before>package scorex.crypto.authds.avltree.batch

import scorex.crypto.authds.avltree._
import scorex.crypto.authds.legacy.avltree.AVLTree
import scorex.crypto.authds.legacy.avltree.{AVLModifyProof, AVLTree}
import scorex.crypto.hash.Sha256
import scorex.utils.Random


object BatchingPlayground extends App with ToStringHelper {
  def time[R](block: => R): (Float, R) = {
    val t0 = System.nanoTime()
    val result = block // call-by-name
    val t1 = System.nanoTime()
    ((t1 - t0).toFloat / 1000000, result)
  }

  //smallDeleteTest

  lookupTest()
  //batchingSelfTest

  //deleteProofSizeTest

  //memoryTestWithBatching
  //memoryTestNoBatching
  //timeBenchmarksNew
  //timeBenchmarksOld
  //spaceBenchmarks



  def lookupTest() {
    val p = new BatchAVLProver()

    val key1 = Sha256("1")
    val key2 = Sha256("2")
    val key3 = Sha256("3")
    val key4 = Sha256("4")
    val key5 = Sha256("5")
    val key6 = Sha256("6")
    val key7 = Sha256("7")

    println("k1: " + arrayToString(key1))
    println("k2: " + arrayToString(key2))
    println("k3: " + arrayToString(key3))

    val v1 = key1.take(8)
    val v2 = key2.take(8)

    val i1 = Insert(key1, v1)
    val i2 = Insert(key2, v2)

    p.performOneModification(i1)
    p.performOneModification(i2)
    p.generateProof()

    val l1 = Lookup(key1)
    val l2 = Lookup(key2)
    val l3 = Lookup(key3)

    val pr = p.performLookups(l1, l2, l3).get

    val vr = new BatchAVLVerifier(p.digest, pr)
    assert(vr.performOneLookup(l1).get.isDefined)
    assert(vr.performOneLookup(l2).get.isDefined)
    assert(vr.performOneLookup(l3).get.isEmpty)

    val i4 = Insert(key4, v1)
    val i5 = Insert(key5, v2)

    p.performOneModification(i4)
    p.performOneModification(i5)
    p.generateProof()

    val l4 = Lookup(key4)
    val l5 = Lookup(key5)
    val l6 = Lookup(key6)
    val l7 = Lookup(key7)

    val pr2 = p.performLookups(l1, l2, l3, l4, l5, l6).get
    val vr2 = new BatchAVLVerifier(p.digest, pr2)

    val pl2 = vr2.performLookups(Seq(l1, l2, l3, l4, l5, l6)).get
    println(pl2)
  }


  def smallDeleteTest = {
    def intToKey(k: Int): Array[Byte] = {
      val key = new Array[Byte](32)
      key(0) = k.toByte
      key
    }

    val value = Random.randomBytes(8)
    var newProver = new BatchAVLProver()

    def ins(k: Int) = {
      var m = Insert(intToKey(k), value)
      newProver.performOneModification(m)
      print("Inserted ")<commit_msg>custom kl/vl in lookupTest()<commit_after>package scorex.crypto.authds.avltree.batch

import scorex.crypto.authds.avltree._
import scorex.crypto.authds.legacy.avltree.AVLTree
import scorex.crypto.authds.legacy.avltree.{AVLModifyProof, AVLTree}
import scorex.crypto.hash.Sha256
import scorex.utils.Random


object BatchingPlayground extends App with ToStringHelper {
  def time[R](block: => R): (Float, R) = {
    val t0 = System.nanoTime()
    val result = block // call-by-name
    val t1 = System.nanoTime()
    ((t1 - t0).toFloat / 1000000, result)
  }

  //smallDeleteTest

  lookupTest()
  //batchingSelfTest

  //deleteProofSizeTest

  //memoryTestWithBatching
  //memoryTestNoBatching
  //timeBenchmarksNew
  //timeBenchmarksOld
  //spaceBenchmarks



  def lookupTest() {
    val kl = 4
    val vl = 7

    val p = new BatchAVLProver(keyLength = kl, valueLength = vl)

    val key1 = Sha256("1").take(kl)
    val key2 = Sha256("2").take(kl)
    val key3 = Sha256("3").take(kl)
    val key4 = Sha256("4").take(kl)
    val key5 = Sha256("5").take(kl)
    val key6 = Sha256("6").take(kl)
    val key7 = Sha256("7").take(kl)

    println("k1: " + arrayToString(key1))
    println("k2: " + arrayToString(key2))
    println("k3: " + arrayToString(key3))

    val v1 = Sha256("1").take(vl)
    val v2 = Sha256("2").take(vl)

    val i1 = Insert(key1, v1)
    val i2 = Insert(key2, v2)

    p.performOneModification(i1)
    p.performOneModification(i2)
    p.generateProof()

    val l1 = Lookup(key1)
    val l2 = Lookup(key2)
    val l3 = Lookup(key3)

    val pr = p.performLookups(l1, l2, l3).get

    val vr = new BatchAVLVerifier(p.digest, pr, keyLength = kl, valueLength = vl)
    assert(vr.performOneLookup(l1).get.isDefined)
    assert(vr.performOneLookup(l2).get.isDefined)
    assert(vr.performOneLookup(l3).get.isEmpty)

    val i4 = Insert(key4, v1)
    val i5 = Insert(key5, v2)

    p.performOneModification(i4)
    p.performOneModification(i5)
    p.generateProof()

    val l4 = Lookup(key4)
    val l5 = Lookup(key5)
    val l6 = Lookup(key6)
    val l7 = Lookup(key7)

    val pr2 = p.performLookups(l1, l2, l3, l4, l5, l6).get
    val vr2 = new BatchAVLVerifier(p.digest, pr2, keyLength = kl, valueLength = vl)

    val pl2 = vr2.performLookups(Seq(l1, l2, l3, l4, l5, l6)).get
    println(pl2)
  }


  def smallDeleteTest = {
    def intToKey(k: Int): Array[Byte] = {
      val key = new Array[Byte](32)
      key(0) = k.toByte
      key
    }

    val value = Random.randomBytes(8)
    var newProver = new BatchAVLProver()

    def ins(k: Int) = {
      var m = Insert(intToKey(k), value)
      newProver.performOneModification(m)
      print("Inserted ")
{'fraction_non_alphanumeric': 0.13316435952427375, 'fraction_numerical': 0.04757262624293235, 'mean_word_length': 3.0585443037974684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1465989', 'n_tokens_mistral': 2091, 'n_tokens_neox': 1981, 'n_words': 406}