MCPcopy Create free account
hub / github.com/ElementsProject/elements / simplicity_rsort

Function simplicity_rsort

src/simplicity/rsort.c:249–255  ·  view source on GitHub ↗

Sorts an array of pointers to 'sha256_midstate's in place in memcmp order. * If malloc fails, returns false. * Otherwise, returns true. * * The time complexity of rsort is O('len'). * * We are sorting in memcmp order, which is the lexicographical order of the object representation, i.e. the order that one * gets when casting 'sha256_midstate' to a 'unsigned char[]'. This representation is i

Source from the content-addressed store, hash-verified

247 * Precondition: For all 0 <= i < len, NULL != a[i];
248 */
249bool simplicity_rsort(const sha256_midstate** a, uint_fast32_t len) {
250 uint32_t *stack = simplicity_malloc(((CHAR_COUNT - 1)*(sizeof((*a)->s)) + 1) * sizeof(uint32_t));
251 if (!stack) return false;
252 rsort_ex(a, len, NULL, stack);
253 simplicity_free(stack);
254 return true;
255}
256
257/* Searches for duplicates in an array of 'sha256_midstate's.
258 * If malloc fails, returns -1.

Callers 1

Calls 1

rsort_exFunction · 0.85

Tested by

no test coverage detected