Add permutation table computation in sortsegments

Computes a permutation-table for a couple of fields, but doesn't
actually reorder anything.
Also changed the initial chunk_t allocation to calloc, so we don't get
any uninitialized pointers.