def word_desc
import bend-collections@1.0.0.0/src/containers/bitset.bend as Bitsetimport Base
283# Indices of set bits, ascending. Walks the words from the last to the first
284# so the list is built in ascending order without an append.
285# The members of one word, by two TAIL loops: the set offsets are pushed in
286# DESCENDING order onto a scratch list (low bit first), which is then
287# reversed onto rest -- the same list word_members builds, without its
288# non-tail recursion.
289def word_desc(m: Nat, +w: U32, +off: Nat, acc: List<&2, Nat>) -> List<&2, Nat>:
290 match m:
291 case 0n:
292 acc
293 case 1n+p:
294 word_desc(p, U32.shr(w), 1n+off, member_pick(low(w), off, acc))