all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Joakim Jalap <joakim.jalap@fastmail.com>
To: Andreas Politz <politza@hochschule-trier.de>
Cc: emacs-devel@gnu.org
Subject: Re: Overlays as an AA-tree
Date: Fri, 03 Feb 2017 12:33:27 +0100	[thread overview]
Message-ID: <87fujvpkzc.fsf@fastmail.com> (raw)
In-Reply-To: <87fujv64mn.fsf@hochschule-trier.de> (Andreas Politz's message of "Fri, 03 Feb 2017 09:49:20 +0100")

Andreas Politz <politza@hochschule-trier.de> writes:

> Hi, I'm interested in this problem as well.

Great!

I thought I might chime in since I've been bashing my head againt this
for a while now :)

> I want to clarify something:
>
> Overlays have begin B and end E positions each with a flag (front-advance
> resp. rear-advance).  These positions may change in one of 3 ways:
>
> 1. move-overlay is called
> 2. Text of length L is inserted at position P.
>    Here the flags decide whether begin B resp. end E will move or not
>    in the literal border-cases P = B resp. P = E .
> 3. Text of length L is deleted beginning at position P.

There is also the case of a replace, conceptually I guess it's similar
to a delete or an insert, but in the code it is handled separately.
Interestingly, in the case of a replace, we don't look at the insertion type.

> Is this the correct model ?  Someone mentioned in a different thread,
> that occasionally we may have B > E.  How does this happen ?

I think it happens in case 2 above, when B = E = P, and we have
front-advance = t and read-advance = nil. Then B will move but E will
not, so we end up with a negative size overlay. See also the comments at
adjust_markers_for_insert in insdel.c and fix_start_end_in_overlays in
buffer.c.

> ---
>
> I think if a tree is sorted by begin only and the front-advance of
> every node is either true or false, the tree can't possibly become
> disordered by insertion/deletion operations.  Further the disorder
> exists at most for nodes having the same begin but different
> front-advances after an insert at begin was performed.

But if the tree is sorted by begin only we can have multiple overlays in
the same position, how does that work? A linked list of all overlays
starting at that position? I toyed with the idea, but I haven't actually
tried it.

For reference, the last case I got stuck on was byte compiling
lisp/semantic/cpp.el, where there are a bunch overlays (26 I believe) at
different positions, but then almost all the buffer text is deleted so
that every overlay ends up being from 6 to 6! 

> This suggests using two trees or at least limits the amount of nodes
> having to be reinserted after a change.

Hm I don't understand this. How would we use two trees?
>
> Anyway, my attempt is to use the RB-tree from alloc.c and add some
> node-attributes:
>
> 1. max_end :: Holds the maximum E value of this node's sub-tree and
> bounds the complexity of queries in terms of their result, i.e. number
> of intervals. (The so called ,,Augmented Tree'' approach to Interval
> Trees (which is actually just an example for how to augment a tree in
> the book).)
>
> 2. offset :: The amount of shift of this node's sub-tree relative to
> its parent and applying to all position values (begin,end,max_end).
> This should limit the time it takes to modify the tree after an
> insertion/deletion in terms of intersecting intervals.

I was going to do this too (but left that for later as I have bigger
problems right now :)). The problem here is that you have to take the
insertion_type into account, so an overlay may or may not change as the
result of an insertion. Actually maybe that isn't a problem since it
only affects those overlays with an endpoint exactly at the point of
insertion... This whole thing makes me dizzy...

> 3. modified_tick :: Essentially just a flag, indicating that all
> parent offsets have been applied to this node.  This would allow for
> constant time access on B/E for repeated accesses.
>
> I'm essentially building an overlay model and if it works, will try to
> plug it into the Editor.

Sounds like a good idea. Let's hope you have better luck (or skill) than
me :)

> -ap

-- Joakim



  parent reply	other threads:[~2017-02-03 11:33 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-20 10:32 Overlays as an AA-tree Joakim Jalap
2016-09-20 12:14 ` Clément Pit--Claudel
2016-09-20 12:43 ` Lars Ingebrigtsen
2016-09-20 16:19   ` Joakim Jalap
2016-09-20 23:19   ` Richard Stallman
2016-09-20 14:40 ` Eli Zaretskii
2016-09-20 17:13   ` Joakim Jalap
2016-09-21 16:14     ` Eli Zaretskii
2016-09-22 10:35       ` Joakim Jalap
2016-09-22 12:24         ` Stefan Monnier
2016-09-21 14:52 ` Stefan Monnier
2016-09-21 15:58   ` Eli Zaretskii
2016-09-21 16:24     ` Stefan Monnier
2016-09-21 16:43       ` Eli Zaretskii
2016-09-21 18:41         ` Stefan Monnier
2016-09-21 19:28           ` Eli Zaretskii
2016-09-22 10:35   ` Joakim Jalap
2016-09-22 12:17     ` Stefan Monnier
2016-09-22 20:11       ` Joakim Jalap
2016-09-23  1:29         ` Stefan Monnier
2016-09-27  6:26           ` Joakim Jalap
2016-09-27 11:50             ` Stefan Monnier
2016-09-27 14:38             ` Eli Zaretskii
2016-09-27 16:07               ` Joakim Jalap
2016-11-21 17:32                 ` Clément Pit--Claudel
2016-11-22  8:09                   ` Joakim Jalap
2016-11-22 13:44                     ` Stefan Monnier
2016-11-23  6:58                       ` Joakim Jalap
2016-11-22 13:44                     ` Clément Pit--Claudel
2016-11-22 13:55                       ` Evgeny Roubinchtein
2016-11-23  7:16                         ` Joakim Jalap
2016-11-23 15:42                           ` Eli Zaretskii
2016-11-23 16:06                             ` Stefan Monnier
2016-11-24 18:33                               ` Evgeny Roubinchtein
2016-11-23  7:13                       ` Joakim Jalap
2017-02-03  8:49 ` Andreas Politz
2017-02-03  9:13   ` Eli Zaretskii
2017-02-03 10:24     ` Andreas Politz
2017-02-03 11:33   ` Joakim Jalap [this message]
2017-02-03 12:44     ` Andreas Politz
2017-02-03 14:11       ` Joakim Jalap
2017-02-03 15:02         ` Andreas Politz
2017-02-03 15:23           ` Joakim Jalap
2017-02-03 15:54             ` Andreas Politz
2017-02-04 21:22       ` Stefan Monnier
2017-02-04 23:10         ` Andreas Politz
2017-02-06  9:56           ` Joakim Jalap
2017-02-06 11:33             ` Andreas Politz
2017-02-06 15:33               ` Joakim Jalap
2017-02-06 15:46                 ` Stefan Monnier
2017-02-06 16:52                   ` Joakim Jalap
2017-02-06 17:34                     ` Stefan Monnier
2017-02-06 17:32                 ` Andreas Politz
2017-02-07 12:35               ` Andreas Politz
2017-02-07 14:46                 ` Joakim Jalap
2017-02-07 22:00                 ` Andreas Politz
2017-02-08  0:36                   ` Andreas Politz
2017-02-08  6:53                     ` Joakim Jalap
2017-02-08  7:34                       ` Andreas Politz
2017-02-08  8:18                         ` Joakim Jalap
2017-02-08  8:44                           ` Andreas Politz
2017-02-08 16:34                           ` Andreas Politz
2017-02-08 17:38                         ` Eli Zaretskii
2017-02-08 13:04                   ` Stefan Monnier
2017-02-08 22:27                     ` Andreas Politz
2017-02-08 22:34                       ` Stefan Monnier
2017-02-09  9:34                         ` Andreas Politz
2017-02-09 10:05                           ` Joakim Jalap
2017-02-09 10:19                             ` Andreas Politz
2017-02-13  3:44                             ` Andreas Politz
2017-02-13  6:11                               ` Eli Zaretskii
2017-02-13  9:04                                 ` Andreas Politz
2017-02-13 14:36                                   ` Eli Zaretskii
2017-02-14 10:07                                     ` Andreas Politz
2017-02-17  4:58                                 ` Andreas Politz
2017-02-17  7:12                                   ` Eli Zaretskii
2017-02-19 22:39                                     ` Andreas Politz
2017-02-19 23:10                                       ` Stefan Monnier
2017-02-19 23:44                                         ` Andreas Politz
2017-02-20 15:34                                       ` Eli Zaretskii
2017-02-21  6:56                                         ` Andreas Politz
2017-02-21 15:11                                           ` Stefan Monnier
2017-02-21 18:26                                             ` Andreas Politz
2017-02-21 19:18                                               ` Stefan Monnier
2017-02-21 23:36                                                 ` Andreas Politz
2017-02-24  8:43                                                 ` Andreas Politz
2017-04-08 13:28                                                   ` Clément Pit-Claudel
2017-05-03 19:20                                                     ` Andreas Politz
2017-05-03 19:40                                                       ` Stefan Monnier
2017-05-05 20:39                                                         ` Andreas Politz
2017-05-04  0:54                                                       ` Clément Pit-Claudel
2017-05-05 20:10                                                         ` Andreas Politz
2017-05-05 22:22                                                           ` Clément Pit-Claudel
2017-05-06  8:05                                                             ` Andreas Politz
2017-05-04 14:21                                                       ` Eli Zaretskii
2017-05-05 20:08                                                         ` Andreas Politz
2017-05-05 21:41                                                           ` Eli Zaretskii
2017-09-24 13:09                                                         ` Clément Pit-Claudel
2017-10-04  8:17                                                           ` Andreas Politz
2017-10-04  9:22                                                             ` Eli Zaretskii
2017-10-04 20:36                                                               ` Andreas Politz
2017-02-14  0:45                               ` Richard Stallman
2017-02-14  8:32                                 ` Andreas Politz
2017-02-06 13:51             ` Stefan Monnier
2017-02-06 14:26               ` Andreas Politz
2017-02-06 15:06                 ` Stefan Monnier
2017-02-06 15:40               ` Joakim Jalap
2017-02-06 16:24                 ` Clément Pit-Claudel
2017-02-03 13:55   ` Stefan Monnier
2017-02-03 15:14     ` Andreas Politz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fujvpkzc.fsf@fastmail.com \
    --to=joakim.jalap@fastmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=politza@hochschule-trier.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.