Skip to content

VecSort

Description

Sort the vector in place using a quicksort over the comparator. The comparator must return a GenericCompare integer (negative when lhs < rhs, zero when equal, positive when lhs > rhs).

Parameters

Name Direction Description
v in,out Vector handle.
compare in Comparator with GenericCompare-style return.

Success

Returns to the caller. Elements are now in non-decreasing order according to compare. The vector length is unchanged.

Failure

Function cannot fail. A NULL comparator or invalid vector is a caller bug and aborts via LOG_FATAL.

Usage example (Cross-references)

Usage examples (Cross-references)
            // Sort by low_pc to enable binary-search lookup.
            if (ok && VecLen(&out->entries) > 1) {
                VecSort(&out->entries, cmp_dwarf_function);
            }
        } else {
    
        // Sort by RVA.
        VecSort(&pending, cmp_pending);
    
        // Re-anchor PendingPub.name_offset_in_pool to pointers into the
            // Advanced functions
            case VEC_INT_SORT : {
                VecSort(vec, compare_ints);
                break;
            }
    // Test VecSort function
    bool test_vec_sort(void) {
        WriteFmt("Testing VecSort\n");
    
        // Create a vector of integers
    
        // Sort the vector in ascending order
        VecSort(&vec, compare_ints_asc);
    
        // Check that the elements are sorted
    
        // Sort the vector in descending order
        VecSort(&vec, compare_ints_desc);
    
        // Check that the elements are sorted in descending order
    /// TAGS: Str, Ops, Sort
    ///
    #define StrSort(str, compare) VecSort((str), (compare))
    
    #ifdef __cplusplus
Last updated on