changes in v3: 1. fix bug to detect duplicate items when mode is set to 0. Therefore, `k->mode` is deleted from the hash calculation. More information on the https://lore.kernel.org/selinux/a236c473-4f18-c882-2197-f49195d84051@xxxxxxxxxx/ 2. add new macro definition SHRINK_MULTIS. This macro is used to control the `hashtab_len`. 3. modify the algorithm complexity in the commit message. 4. fix `hash_table` leak in failed malloc. v2: https://lore.kernel.org/selinux/20230217084458.40597-1-wanghuizhao1@xxxxxxxxxx/ v1: https://lore.kernel.org/selinux/20230209114253.120485-1-wanghuizhao1@xxxxxxxxxx/ wanghuizhao (3): libselinux: migrating hashtab from policycoreutils libselinux: adapting hashtab to libselinux libselinux: performance optimization for duplicate detection libselinux/src/hashtab.c | 234 ++++++++++++++++++++++++++++++++++++++++++++ libselinux/src/hashtab.h | 117 ++++++++++++++++++++++ libselinux/src/label_file.c | 120 ++++++++++++++++++----- 3 files changed, 447 insertions(+), 24 deletions(-) create mode 100644 libselinux/src/hashtab.c create mode 100644 libselinux/src/hashtab.h -- 2.12.3