@@ -20,13 +20,13 @@ computes the `key` value for each object which is the metric used to sort the
20
20
objects. `Func` needs to have the following signature:
21
21
22
22
```cpp
23
- [] (T obj) -> type_t { type_t key; /* compute key for obj */ return key; }
23
+ [] (T obj) -> key_t { key_t key; /* compute key for obj */ return key; }
24
24
```
25
25
26
- Note that the return type of the key ` type_t ` needs to be one of the following
26
+ Note that the return type of the key ` key_t ` needs to be one of the following
27
27
: ` [float, uint32_t, int32_t, double, uint64_t, int64_t] ` . ` object_qsort ` has a
28
28
space complexity of ` O(N) ` . Specifically, it requires `arrsize *
29
- sizeof(type_t )` bytes to store a vector with all the keys and an additional
29
+ sizeof(key_t )` bytes to store a vector with all the keys and an additional
30
30
` arrsize * sizeof(uint32_t) ` bytes to store the indexes of the object array.
31
31
For performance reasons, we support ` object_qsort ` only when the array size is
32
32
less than or equal to ` UINT32_MAX ` . An example usage of ` object_qsort ` is
@@ -148,14 +148,14 @@ of the custom class and we highly recommend benchmarking before using it. For
148
148
the sake of illustration, we provide a few examples in
149
149
[./benchmarks/bench-objsort.hpp](./benchmarks/bench-objsort.hpp) which measures
150
150
performance of `object_qsort` relative to `std::sort` when sorting an array of
151
- points in the cartesian coordinates represented by the class: `struct Point
152
- {double x, y, z;}` and ` struct Point {float x, y, x;}`. We sort these points
153
- based on several different metrics:
151
+ 3D points represented by the class: `struct Point {double x, y, z;}` and
152
+ ` struct Point {float x, y, x;}`. We sort these points based on several
153
+ different metrics:
154
154
155
155
+ sort by coordinate `x`
156
156
+ sort by manhanttan distance (relative to origin): `abs(x) + abx(y) + abs(z)`
157
157
+ sort by Euclidean distance (relative to origin): `sqrt(x*x + y*y + z*z)`
158
- + sort by Chebyshev distance (relative to origin): `max(x, y, z )`
158
+ + sort by Chebyshev distance (relative to origin): `max(abs(x), abs(y), abs(z) )`
159
159
160
160
The performance data (shown in the plot below) can be collected by building the
161
161
benchmarks suite and running `./builddir/benchexe --benchmark_filter==*obj*`.
0 commit comments