C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Any interest in having Fenwick trees in the standard?

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Thu, 15 Oct 2026 11:17:57 -0400
On Thu, Oct 15, 2026 at 10:26 AM Brian Bi via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> A Fenwick tree <https://en.wikipedia.org/wiki/Fenwick_tree> is a table of
> size N that encodes an array of N values and can be used to support the
> following operations in O(log N) time:
>
> - Return the sum of any given contiguous subsequence of the array,
> - Change the value of a given array element to a given new value,
> - If all array elements are nonnegative, determine the shortest prefix
> of the array whose sum is at least a given value.
>
> Have you used Fenwick trees for real applications (i.e. not online coding
> challenges and the like)? Would you be interested in seeing them added to
> the standard library?
>

No, and 100% definitely not, respectively.
It does sound like an interesting data structure, which would be fun to
implement in an STL-style way and make available on GitHub or wherever.
Such a library does *not* belong in the International Standard.
I'd be interested in seeing such an implementation. At a quick glance it
sounds like one of those "not-really-STL-style" *data structures*, like a
suffix tree or sg14::slot_map
<https://github.com/Quuxplusone/SG14/blob/master/include/sg14/slot_map.h>,
that has some interesting questions re: how much it should, or can, really
resemble an STL *container*.

Compare for example my implementation of the Fishspear
<https://github.com/Quuxplusone/Fishspear> priority queue, or Howard
Hinnant's combinations.h <https://howardhinnant.github.io/combinations.html>,
or, cough cough, std::hive (née Matt Bentley's plf::colony
<https://github.com/mattreecebentley/plf_colony>).

–Arthur

Received on 2026-10-15 15:18:17