sorta icon indicating copy to clipboard operation
sorta copied to clipboard

Optional Rank Augmentation; Cursor-oriented Design

Open c-blake opened this issue 4 years ago • 3 comments

B-Trees can cheaply support seek-by-rank. With internal code factoring along "cursor" = seq[tuple[ptr,index]] lines, this can even be done both easily and optionally. See my comments here as well https://forum.nim-lang.org/t/5473

c-blake avatar Nov 07 '19 14:11 c-blake

Incidentally, what I mean by cursor-oriented design would look like https://forum.nim-lang.org/t/5697#35810 where a cursor is a tree Path.

c-blake avatar Jan 06 '20 22:01 c-blake

Something I don't think I have ever mentioned yet though also relevant here is that separation of seek & edit (add or del) is also a good way to provide well-defined "sub orders" when duplicate keys exist via a "sided seek". For example, if you clone https://github.com/c-blake/adix and

$ cd adix/tests
$ nim c ppss
$ nim c -d:btTall btshell
$ ./ppss|./btshell
+1 5 1
+1 5 2
p
-0 5

The tree will still contain the (key=5,val=2) pair because we +1 was like "append" while "-0" was like "de-prepend" (or maybe pop_front in C++ STL-ese).

c-blake avatar May 26 '20 20:05 c-blake

Of course, these (seek,edit) things could be the "expert" interface and considered an "implementation detail" and pairs could be bundled up into the "all-in-one" operators like []= and friends which people seem pulled toward. While I see the notational appeal of that, it's also true that in practice it can create issues like https://github.com/nim-lang/RFCs/issues/200 and also that one almost always wants two slightly different branches when (seek,edit) is involved..either update-or-init or update-or-release and so on. Often those slightly different branches are handled with in/contains first and then some secondary operation which is also less than ideal both for the duplicated work and for the in-ordered-sets duplicated interfaces. It could be, ultimately, that the expert interface is actually the end-to-end simpler interface hiding behind less simple notation. Just a note. I'm not sure what the best answer is.

c-blake avatar May 26 '20 21:05 c-blake