{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreiezezbnm24q4cdqfuouxyxpnjalveusrmevw3uk37zje6hvddj2u4",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mjn7ikdqmbg2"
  },
  "path": "/t/t-sort-by-index-and-t-sort-by-key-and-index/24172#post_14",
  "publishedAt": "2026-04-16T18:14:21.000Z",
  "site": "https://internals.rust-lang.org",
  "textContent": "scottmcm:\n\n> I don't know a great (non-allocating) way to check that something _is_ a permutation, though, for a safe API...\n\nAn array of integers of length N defines a permutation if and only if each of the integers `0..N` appears in the array exactly once. It's obviously easy to check for integers outside the valid range. The pigeonhole principle says that if all the array entries are in the range, and there are no missing values, then there cannot be any duplicates either. I feel like there ought to be a way to detect missing values (or, equivalently, duplicates) in O(1) space but I can't think of one off the top of my head ... can we use the sum and/or product of the values somehow?",
  "title": "`<[T]>::sort_by_index` and `<[T]>::sort_by_key_and_index`"
}