Skip to content

How to add pointers to indices into array #20

@pathikrit

Description

@pathikrit

I have the following image generated:
arraydeque

This is the code I am using:

implicit def `ArrayDeque RefTree`: ToRefTree[mutable.ArrayDeque[Char]] = ToRefTree {ds =>
    val array = ds.privateField[Array[AnyRef]]("array").map(c => Option(c).getOrElse('␀').asInstanceOf[Char])
    val start = ds.privateField[Int]("start")
    val end = ds.privateField[Int]("end")

    val arrayRef = {
      val arrayFields = array.zipWithIndex map { case (a, i) =>
        val name = i match {
          case `start` if start == end => s"start=end=$i"
          case `start` => s"start=$i"
          case `end` => s"end=$i"
          case _ => i.toString
        }
        a.refTree.withHighlight(i == start || i == end).toField.withName(name)
      }
      RefTree.Ref(array, arrayFields).rename(s"char[${array.length}]")
    }

    RefTree.Ref(ds, Seq(
      start.refTree.withHighlight(true).toField.withName("start"),
      end.refTree.withHighlight(true).toField.withName("end"),
      arrayRef.toField.withName("array")
    ) ++ ds.toArray.zipWithIndex.map({case (a, i) => a.refTree.toField.withName(i.toString)}))
  }

But, it would be nice to have start and end have arrows into the array. Is it possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions