Refactor {str,digest}map into a common implementation; add digest256map

Needed for #13399.
Merge branch 'digest256map'