#325 closed defect (fixed)
psVectorSortIndex algorithm
| Reported by: | Paul Price | Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | |
| Component: | types | Version: | unspecified |
| Severity: | normal | Keywords: | |
| Cc: |
Description
The algorithm adopted for psVectorSortIndex (sort the vector and then find out
where my data ends up) is by no means optimal. The natural algorithm is:
- Generate a vector of indices (0,1,2,3,4,5,...,N)
- Make a comparison function that, given two indices, compares the
corresponding values of the input vector (e.g., given 2 and 5, it compares
myVector->data.F32[2] and myVector->data.F32[5]).
- Sort the vector of indices (#1) using qsort(), employing the comparison
function (#2)
- Return the sorted vector of indices.
Change History (4)
comment:1 by , 21 years ago
| Status: | new → assigned |
|---|
comment:2 by , 21 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
rewrote the function by sticking the data in an array of structs that holds the
data along with the index then usinf qsort to sort the structs. This ensures
all the indices are included in the output, even in the case of duplicate values.
-rdd
Note:
See TracTickets
for help on using tickets.

It is not as simple as that, as there is no way to pass the vector into the
compare function. One could create a global variable set to the vector
currently being sorted, but there is thread-safety problems associated with that
approach.
Let me think about a better way to skin this one for awhile.