add set() and index_to_flat() utility function