Ilya Zakharevich on Mon, 08 Jul 2024 22:31:37 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

vecsort() shortcomings


At least the docs are not clear in the “lexicographical” case:

  “Inverting” the lexicographic order is tricky.

I would

  • make the “0x4” bit-of-flag reverse the order of the RESULTING vector;
  • make negative entries in the “cmpf” array mean “reverse the
    result of “comparison w.r.t. this coordinate”;
  • Make a 0-entry in this array mean “remove the duplicates up to
    this point” — in the sense of keeping only the first entry with
    given components up to this point.

    (Maybe with the entry like -0.001 meaning “keep only the last entry
     with ‘this prefix’” — instead of the “first entry with this
     prefix”.  Or maybe a doubled 0 entry can do this better?  Or use
     strings "1" and "-1"?)

(Currently, I write:
    neg = vecsort(vecsort(neg,2,4),1,8);  \\ sort lexicographically in order [“1”,-“2”] and keep the first entry
    pos = vecsort(vecsort(pos,2),  1,8);  \\ sort lexicographically in order [“1”, “2”] and keep the first entry
 This would become
    neg = vecsort(neg, [1, "1", -2]);     \\ or [1, "-1", 2]
    pos = vecsort(pos, [1, "1",  2]);
)

Another warning: I noticed that in a lot of CS documentation, when
they mention “bit 4” (or “binary digit 4”) they actually mean 0b10000
(or maybe 0b1000 ?!).  In my docs, to avoid this ambiguity I decided
to use 0x04 in such cases.

Hope this helps,
Ilya