[boost] Potential order statistic tree?

162 views
Skip to first unread message

Soronel Haetir via Boost

unread,
Dec 27, 2020, 6:59:59 PM12/27/20
to bo...@lists.boost.org, Soronel Haetir
Boost developers,

Would there be interest in adding an order statistic tree to the boost
library? That is, a tree that instead of being sorted simply keeps
nodes in whatever order is specified, along with a (potentially
multi-index) per-node value and a total of per-node values of each
node and its left-descent tree.

I currently have two such types, a very capable intrusive version (not
based on boost::intrusive though using some of the same ideas) and a
less capable non-intrusive form that uses the mechanics of the
intrusive form as an implementation detail. The reason for not being
based on Boost.Intrusive is that the tree algorithms that
Boost.Intrusive provides are all for search trees and this very
definitely is not, plus the need to alter node weights during insert,
delete and rotations and the Boost.Intrusive algorithm providers not
having a good place to add that behavior.

I have personally found this type very useful while implementing a
rope container and also while implementing tracking for various parts
of a text editor (that is, paragraph, line and run positions) (in
terms of characters, graphemes and screen height).

Perhaps the major drawback to what I have is that I have not been
careful to isolate c++-version dependent code. Although I know it does
compile with the latest msvc 2019 as well as the clang 10.0 that MS
ships.

I am simply not sure whether such a type has a broad enough appeal to
make the work of adding it to boost worthwhile.

--
Soronel Haetir
soronel...@gmail.com

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

René Ferdinand Rivera Morell via Boost

unread,
Dec 27, 2020, 9:51:54 PM12/27/20
to Boost Developers List, René Ferdinand Rivera Morell
On Sun, Dec 27, 2020 at 6:00 PM Soronel Haetir via Boost <
bo...@lists.boost.org> wrote:

> Would there be interest in adding an order statistic tree to the boost
> library?
>

I had to search my Boost dev email history to recall how many times that
data structure has been suggested... It's at least half a dozen times :-)
It's been suggested enough that Boost Multiindex already supports it <
https://www.boost.org/doc/libs/1_75_0/libs/multi_index/doc/tutorial/indices.html#rnk_indices>.
Hence you'll need to point out a comparison between what you did and what
exists (and possibly what has been suggested in the past) to better inform
why your version of this should be adopted. As, clearly, there's historical
interest.


--
-- René Ferdinand Rivera Morell
-- Don't Assume Anything -- No Supone Nada
-- Robot Dreams - http://robot-dreams.net

Paul A Bristow via Boost

unread,
Dec 28, 2020, 1:16:23 PM12/28/20
to bo...@lists.boost.org, pbri...@hetp.u-net.com

> -----Original Message-----
> From: Boost <boost-...@lists.boost.org> On Behalf Of Soronel Haetir via Boost
> Sent: 27 December 2020 23:50
> To: bo...@lists.boost.org
> Cc: Soronel Haetir <soronel...@gmail.com>
> Subject: [boost] Potential order statistic tree?
>
> Boost developers,
>
> Would there be interest in adding an order statistic tree to the boost library? That is, a tree that
> instead of being sorted simply keeps nodes in whatever order is specified, along with a (potentially
> multi-index) per-node value and a total of per-node values of each node and its left-descent tree.
>
> I currently have two such types, a very capable intrusive version (not based on boost::intrusive though
> using some of the same ideas) and a less capable non-intrusive form that uses the mechanics of the
> intrusive form as an implementation detail. The reason for not being based on Boost.Intrusive is that
> the tree algorithms that Boost.Intrusive provides are all for search trees and this very definitely is not,
> plus the need to alter node weights during insert, delete and rotations and the Boost.Intrusive
> algorithm providers not having a good place to add that behavior.
>
> I have personally found this type very useful while implementing a rope container and also while
> implementing tracking for various parts of a text editor (that is, paragraph, line and run positions) (in
> terms of characters, graphemes and screen height).
>
> Perhaps the major drawback to what I have is that I have not been careful to isolate c++-version
> dependent code. Although I know it does compile with the latest msvc 2019 as well as the clang 10.0
> that MS ships.

You need not be *too* concerned about previous C++ versions. For a new library, you can simply specify the platform and compiler versions (and minimum C++ standard version) required. It is highly desirable that it works with recent MS, Clang and GCC versions (and you have ticked two those boxes).

(You may be able to get it working with older tools by requiring certain features whose availability is defined by macros).

Of course, we would hope that you would do the necessary maintenance for future C++ versions - (perhaps you should worry more about that 😉 )

(I am entirely unqualified to speak about the usefulness etc of your library).

Paul

Ion Gaztañaga via Boost

unread,
Dec 29, 2020, 4:06:53 AM12/29/20
to René Ferdinand Rivera Morell via Boost, Ion Gaztañaga
On 28/12/2020 3:51, René Ferdinand Rivera Morell via Boost wrote:
> On Sun, Dec 27, 2020 at 6:00 PM Soronel Haetir via Boost <
> bo...@lists.boost.org> wrote:
>
>> Would there be interest in adding an order statistic tree to the boost
>> library?
>>
>
> I had to search my Boost dev email history to recall how many times that
> data structure has been suggested... It's at least half a dozen times :-)
> It's been suggested enough that Boost Multiindex already supports it <
> https://www.boost.org/doc/libs/1_75_0/libs/multi_index/doc/tutorial/indices.html#rnk_indices>.
> Hence you'll need to point out a comparison between what you did and what
> exists (and possibly what has been suggested in the past) to better inform
> why your version of this should be adopted. As, clearly, there's historical
> interest.

There was a pull request to Boost.Intrusive adding Augmented binary
search trees. At that time there was not much interest from other users,
but it seems a good starting point, it does not seem a very big patch:

https://github.com/boostorg/intrusive/pull/3

We'd need to add tests to this feature to make sure it is not broken in
newer versions.

Best,

Ion

Reply all
Reply to author
Forward
0 new messages