Laurent,I am afraid that you misunderstand the issue at hand. Gperf indeed builds a perfect hash from a key set that is fixed at compile time. However, ls doesn't read dircolors.hin. It parses LS_COLORS at runtime (as you can see from src/ls.c:2761), and users can put any entries they like in that variable.
Besides that, gperf would also get many of the semantics wrong: e.g., *.tar.gz match against the end of the filename at any length, matching is typically case-insensitive with the exception of the case being the only difference, and further there is a clear problem of precedence.
A better idea is to use gnulib's built-in hashing functions. -- With Valediction, Kamila Szewczyk (https://iczelia.net) On 9/23/26 9:22 PM, Laurent Lyaudet wrote:
Hello Kamila,I thought of that already, but the LS_COLORS environmental variable needs to be supported anyway (iuic). There could be a gperf fallback, though.Correct me if I'm wrong: - perfect hashing is about hash key not about values associated, - O(1) + O(1) = O(1) - So the perfect hash table (gperf) should not be used as a fallback... but in first intent. gperf should be used during development to obtain a perfect hash function for the keys that are in the file dircolors.hin. And all these keys should be preset in the corresponding hash table to a default "NON-NULL" witness value. Then when you parse LS_COLORS if the key exists with a default "NON-NULL" witness value in PHT (Perfect Hash Table), you set the value in PHT to what you read in LS_COLORS. Other keys in custom LS_COLORS are to be put with their value in either another hash table, with a hash function that is not perfect since we cannot guarantee anything on these keys, or keep the current linked list to store these uncommon values. Then whenever a search for a key is done in this data-structure made of a front PHT and a fallback (either HT or LL), if the result is from the PHT with the witness value, ignore it, otherwise use it. PHT for common keys, something else otherwise. I don't see the reason for your "but the LS_COLORS...". That's simple, not over-engineered common optimizations done for the usual 90 % of use cases in 10 % of the features. Have a nice evening, best regards, Laurent
OpenPGP_0xC868F0B6DE38409D.asc
Description: OpenPGP public key
OpenPGP_signature.asc
Description: OpenPGP digital signature
