tstromberg
(Tyler Stromberg)
May 10, 2021, 5:34pm
1
I am currently implementing a min-max heap (to back a priority queue), and this function would be useful in determining if a given index falls into a min layer or max layer. Yes, I could copy the implementation of FixedWidthInteger._binaryLogarithm() into my code (and I have basically already implemented the same thing), but maybe it's time to have a discussion about removing the prefix on this function and making it public API instead.
There is one, but it's not public :) It's spelled _binaryLogarithm() + 1 and it's available on BinaryInteger.
(For reasons beyond the scope of our discussion here, _binaryLogarithm() is generally more useful than _binaryLogarithm() + 1.)
The method is probably useful enough that it could pass the bar for becoming a public API, but I dread the bikeshedding and haven't proposed it. For end users, though, it's not really more convenient than bitWidth - leadingZeroBitCount.
Thoughts?
4 Likes
Seems it can be exposed as part of public API.
"Yes, I could copy the implementation of FixedWidthInteger._binaryLogarithm() into my code" – why should you copy it? The following code is valid:
let binaryLogarithm = Int(0)._binaryLogarithm()
The problem is that currently it is marked with underscore and therefore unofficial.
So, lets make it official.
tstromberg
(Tyler Stromberg)
May 17, 2021, 8:38pm
3
why should you copy it? The following code is valid:
Yeah, fair. I mostly wanted to insulate myself from the change if it gets promoted to official public API.
There hasn't been much engagement on this; I think I'm going to work on putting together an official evolution proposal.
2 Likes
vanvoorden
(Rick van Voorden)
December 29, 2025, 8:07pm
4
I just found this pitch and I have not seen much new activity on this. Were there any more blockers left you can share?