diff options
| author | Tyge Løvset <[email protected]> | 2021-01-19 16:16:47 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-01-19 16:16:47 +0100 |
| commit | 8d6e2cd876af87e7f035c0e103b818fcd5b12bc9 (patch) | |
| tree | 4fe099c90c74805235603f4b9422d08f3f7312ab | |
| parent | b16aa1db5d453f19a1851b411e7ec67a653782ff (diff) | |
| download | STC-modified-8d6e2cd876af87e7f035c0e103b818fcd5b12bc9.tar.gz STC-modified-8d6e2cd876af87e7f035c0e103b818fcd5b12bc9.zip | |
Update csmap_api.md
| -rw-r--r-- | docs/csmap_api.md | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/docs/csmap_api.md b/docs/csmap_api.md index f4cfcf48..27fd22c6 100644 --- a/docs/csmap_api.md +++ b/docs/csmap_api.md @@ -182,14 +182,13 @@ Demonstrate csmap with plain-old-data key type Vec3i and int as mapped type: csm typedef struct { int x, y, z; } Vec3i; static int Vec3i_compare(const Vec3i* a, const Vec3i* b) { + // optimal way to return -1, 0, 1: if (a->x != b->x) return 1 - ((a->x < b->x)<<1); if (a->y != b->y) return 1 - ((a->y < b->y)<<1); - return c_default_compare(&a->z, &b->z); + return (a->z > b->z) - (a->z < b->z); } -using_csmap(v3, Vec3i, int, c_default_del, // mapped: empty int destroy func - c_default_clone, // mapped: clone int by "memcpy" - Vec3i_compare); // key: compare Vec3i +using_csmap(v3, Vec3i, int, Vec3i_compare); int main() { |
