@ireneista this reminds me that there's a data structure I love that I think is underappreciated, because the only place I've ever seen it used is in the Java Swing package: https://docs.oracle.com/en/java/javase/23/docs/api/java.desktop/javax/swing/SizeSequence.html
you could store the byte offset of the start of each line in an array and use that to find the line number for a byte offset in log time, or the byte offset of a line in constant time. but if you then change the length of a line, you have to update the byte offsets of all the lines after it, which takes linear time.
by contrast, this data structure uses exactly the same amount of space but takes log time for all of the above operations, and I think that's a lovely option to have in the toolbox.
I'm sure it's been described elsewhere but I can never figure out what to search for, so sometimes I go dig up the Java SDK source again just to read this one class