From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Overlays as an AA-tree Date: Thu, 22 Sep 2016 08:17:40 -0400 Message-ID: References: <87d1jylv43.fsf@fastmail.com> <87a8f0p69w.fsf@fastmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1474548045 1654 195.159.176.226 (22 Sep 2016 12:40:45 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 22 Sep 2016 12:40:45 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Joakim Jalap Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 22 14:40:41 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bn3IS-0005WX-6I for ged-emacs-devel@m.gmane.org; Thu, 22 Sep 2016 14:40:12 +0200 Original-Received: from localhost ([::1]:43162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn3IQ-00078N-8r for ged-emacs-devel@m.gmane.org; Thu, 22 Sep 2016 08:40:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn2wk-0002LA-MV for emacs-devel@gnu.org; Thu, 22 Sep 2016 08:17:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bn2wg-0007iD-L2 for emacs-devel@gnu.org; Thu, 22 Sep 2016 08:17:46 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:35497) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn2wg-0007i0-EU for emacs-devel@gnu.org; Thu, 22 Sep 2016 08:17:42 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AFBQALW9BX/63kr2xdGgEBAQECAQEBAYMtAQEBAQEehE2FULF5hhYEAgKBaTwRAQIBAQEBAQEBXieEYgEBAwFWIwULCzQSFBgNJIhVCLxVAQEBBwIliXqBA4QQhgwFhhONeYVNjB+FDIRegwSGC4ZziBqBPjQggmgbgWkgg1yCLgEBAQ X-IPAS-Result: A0AFBQALW9BX/63kr2xdGgEBAQECAQEBAYMtAQEBAQEehE2FULF5hhYEAgKBaTwRAQIBAQEBAQEBXieEYgEBAwFWIwULCzQSFBgNJIhVCLxVAQEBBwIliXqBA4QQhgwFhhONeYVNjB+FDIRegwSGC4ZziBqBPjQggmgbgWkgg1yCLgEBAQ X-IronPort-AV: E=Sophos;i="5.30,296,1470715200"; d="scan'208";a="273243692" Original-Received: from 108-175-228-173.dsl.teksavvy.com (HELO ceviche.home) ([108.175.228.173]) by smtp.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 22 Sep 2016 08:17:41 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 9EC5A6621B; Thu, 22 Sep 2016 08:17:40 -0400 (EDT) In-Reply-To: <87a8f0p69w.fsf@fastmail.com> (Joakim Jalap's message of "Thu, 22 Sep 2016 12:35:29 +0200") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:207689 Archived-At: >> which makes me suspect your design might not be quite right. > Well, I didn't think *too* hard about it. I didn't really think about > what to do when the intervals of two overlays are the same. Does it even > matter? Not much, no. Do note that in compare_overlays, we do need a total ordering (this is used for sort_overlays). Your sorting and that of compare_overlays can't be identical (compare_overlays has to obey the `priority` property, whereas yours shouldn't pay attention to it), but you can still use the same idea: i.e. when start and end are equal, just use the overlays's memory addresses to decide which comes first. >> This said, reading overlay_tree_insert_internal, I have the impression >> that you're implementing what wikipedia describes as an "Augmented tree" >> where the basic tree is your AA-tree, indexed by the left position of >> the overlays, with the `max` field being the "augmented" data, which >> sounds just fine. >> Is that right? > That is exactly right. Great. >> The only places you absolutely need to replace are all the places that >> need to modify the tree. There shouldn't be that many of them >> (basically, make-overlay, move-overlay, delete-overlay, plus text >> insertion/deletion). >> Then the rest can be modified little by little. > I think I ran into some other subtle things. For example an overlay can > be in "no buffer" if both it's markers were detached from their buffer, > I think. The user doesn't have direct access to the markers, so IIUC this situation happens through delete-overlay or move-overlay. > So in the case of the overlay tree, I need to detect this and > remove the overlay from the buffers tree. Similarly, move-overlay can necessitate moving the overlay from one tree to another. >> Some tricky parts: >> - because of the insertion_type, two overlays may start with end1> and finish with end1>end2 without any call to move-overlay. > Hm, ok. I will have to look into this further. I think a more important aspect is that insertion/deletion of text has to update all char-positions of overlays after the point of insertion/deletion. I.e. it's an O(n) operation. In the intervals tree used for text-properties we avoid this by keeping track of distances rather than positions. and then positions get (re)computed when needed. >> - the overlay tree needs to be "weak" (i.e. we'll need to add special >> code in the GC). > I don't really understand what this means. Could you please elaborate? > I was hoping it would work with the current marking and sweeping. Hmm... forget it, I was confused. >> I wouldn't worry about merging (better yet: merge from master right away >> and then keep doing that on a regular basis, which should be easy since >> I don't think we've touched (nor will touch) this code very much). > I tried to do that yesterday. There were some conflicts in insdel.c > (which I think I fixed) but now I can't commit, because 'git commit' > complains about trailing whitespace in some regex test files. How do I > get around this? Just remove the trailing whitespace. Stefan