The function event_strcmp_events was previously returning int values
(-1, 0, 1) to indicate ordering. While this may resemble strcmp-like
semantics, it is invalid when used as a comparator with std::sort.
According to the C++ standard, the comparator used in standard
algorithms must be a function object returning a value contextually
convertible to bool, where comp(a, b) returns true if and only if a is
considered less than b.
Returning -1, 0, or 1 violates these rules. In particular, std::sort()
only expects the comparator to return a boolean value, and it uses that
value to infer ordering. Returning an int may lead to incorrect sorting
behavior and undefined behavior, including segmentation faults.
Replace the int-style comparator with a strict boolean comparison to
comply with the standard and ensure sorting correctness.
- The pointer-based nature of write entries, changes invalidate previous data
- Instead of managing scratch, just push to the descriptors built-in management which is quite optimal
- Frees up callers from managing descriptors themselves (ewww)
- Makes descriptor reuse possible
- Opens up the door to techniques like descriptor_buffer by abstracting away management to an implementation detail
According to the C++ standard, comparison functions used in sorting
algorithms such as std::sort must establish a strict weak ordering.
Specifically, the comparator must be irreflexive: for all values x,
comp(x, x) must be false.
The original comparator used >= for descending order, which violates
this requirement in the case of equal values (i.e., when a == b, both
comp(a, b) and comp(b, a) would return true). This can result in
undefined behavior in sorting algorithms, including potential
segmentation faults due to invalid iterator manipulation.
This change replaces >= with > to ensure irreflexivity and compliance
with the standard's requirement for a strict weak ordering.