map: rewrite to use sorted key array, add optional C++ API