From 7d4435f081779e4fe6a184b0e2bda8ad6b25d5d5 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Wed, 24 Sep 2025 14:38:46 +0200 Subject: [PATCH] descriptor table: hash the fd rather than the identity function Use a trivial Knuth's multiplicative hash, that works perfectly for sequential file descriptors. --- libc-bottom-half/sources/descriptor_table.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libc-bottom-half/sources/descriptor_table.c b/libc-bottom-half/sources/descriptor_table.c index e124c2f0..8bcd1fb7 100644 --- a/libc-bottom-half/sources/descriptor_table.c +++ b/libc-bottom-half/sources/descriptor_table.c @@ -55,8 +55,7 @@ static int next_fd = 3; static size_t keyhash(int key) { - // TODO: use a hash function here - return key; + return (size_t)key * 2654435769U; } static int resize(size_t nel, descriptor_table_t *table)