Binary Module: `bin:count-ones` for counting bits (population)
EnhancementPR PendingEXPath
The Binary Module comes with helpful bitwise operators like `bin:and`, but no way to count set bits (`bin:length` counts octets). A population count, as offered by Java’s `Long.bitCount` or SQL’s `BIT_COUNT`, seems like a simple addition to me. For example, it is needed to compute the Hamming distance(`bin:count-ones(bin:xor($bin1, $bin2))`).
Proposed signature:
```xquery
bin:count-ones(
$value as (xs:hexBinary | xs:base64Binary)
) as xs:integer
```
An equivalent XPath solution is doomed to be slow and more verbose. – I’ll be happy to do the PR.
0 条评论