From patchwork Fri Feb 2 15:58:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 195926 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp526934dyc; Fri, 2 Feb 2024 08:05:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpVo74TMlVOljBWIv9O6rz2/hwXxfLDEq/6DxgxBjzVs4sFlUSAJQAJG+0ZFU1fYEq7Z1v X-Received: by 2002:a17:906:80cd:b0:a36:c327:e60d with SMTP id a13-20020a17090680cd00b00a36c327e60dmr1786255ejx.48.1706889920991; Fri, 02 Feb 2024 08:05:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706889920; cv=pass; d=google.com; s=arc-20160816; b=lRyyw8boKwzsuZqRLbgNa3c1TleKyznWYETSiaw22Xbj+2Yl1LrqrNps2TUvKjmjhw W+UNe0EMrBAzvteHDRSnkQRpUAxxDq+brq/kFVcjP5cup/D3ec+U4dg2+KKiBak/2K+/ 80+6P+0PErR4a2N3kv9Ovd+uRhorx9ppCS7kmzLctH5DJfYGm3Tb59GwwLVptXcSJoM9 BRRBGx6W2F/4CzPpjc3j3PO3DJz19kYgij754O5ybBpZgrzAVBQdEuFAAwZIwamNYIcK Vz+WQOR3m1uwl4w9SWRoDxtrJzAD98IyjEJLUG1wvq0t80piIFmeqOMJYjKz0a8WjJcx ITNA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zEpA+n7tBnfdGTW91LeK8gqMnIGkW7qPWmvAaghg1Vs=; fh=9KLThC6YtJFpDQkQ7Z4YZC4A/B3D4UwC7swEWmjlkrk=; b=DJUukAQIRb+mXfdluysSuPkvFWviP0tDbnTnYAy+T6uErQaH5X5ZMZ32sjocBdaqqj iTMH196dG92UV8xHlmHdgvXzsg1Fc5YdYHnsVdkFkjpJA2/dp/IEQil5aWahVpwjt4ma iwOXfIIjRjoDSNXd5WLQRZMpOXPxrsKgNaZCkrqqs8UxG6zGjqTs5tb7+uiz4ONgnGfw qwmox4S+VsydYpx1ZHUVSKmpOmBmA6uN7y3p8eosiTPC0iThuKC/2eb3+UVo0A8gJiMY AWOaz7cD5aMkbRKid304eFtZcs0TZB3pm7rHj3VaxDofFNKMI0WJDuCHXMIM2YuZSlVB i84Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EBF3HzlA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50082-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50082-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCXqeqeHpMt7HoqjWFwG9bvqK3BGw04gkB8Gdrm5jnMH6XzxF44RNrM50ZG7Ps2FI5XMGCoaCcuGHPk1vzaDLc+9Uxq99A== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id kj19-20020a170907765300b00a35990c2b5csi890575ejc.407.2024.02.02.08.05.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 08:05:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50082-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EBF3HzlA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50082-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50082-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 986291F25C84 for ; Fri, 2 Feb 2024 16:05:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 50F95151CF9; Fri, 2 Feb 2024 15:58:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EBF3HzlA" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F57415145C; Fri, 2 Feb 2024 15:58:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889535; cv=none; b=SMDrsfJQnlR7I1E+QClkzpZGyN/ubYzKjosspx3jy8FuBS5jXaWy4nokCBwjnVe/bflcciiMw9NbYZ3aYb5Ywm9XvosvnFHpJkxJi+K2gNOPmZ/arlbvwALPb4qIeMagTy1HYjiTQVSieZznRrxBPYeWp1DabBuiwgjdIfq/fC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889535; c=relaxed/simple; bh=D8GL5EXe9NsGs57qE1qR40Cel+KA+fOzcvMaeqYSUEw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P0m0N8myx7OS7i9ICujsQ26zdhLHNmrS9MySJRHTZCVrg5s3pr/jiAwrgdHFKFxh2qSMZrpKYDygMqrXvA6u6/l8yYGBDJaplIZR0CFsJhVOl3eE06W0nmZ65lLi5MITKAMwR7lWHmgPRE0jxV+wS24I8cFlniv0lD/Ny+czE/A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EBF3HzlA; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42F38C43390; Fri, 2 Feb 2024 15:58:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889534; bh=D8GL5EXe9NsGs57qE1qR40Cel+KA+fOzcvMaeqYSUEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EBF3HzlAFciTdheF83e/1eXRxiduLLwv7xiG/VW0468UcO70fbmYmNr88vjefwNE/ SMaRjSDnRn/8dmgujdNwDVC87ZzyK0IgHEPPoOt9vl/zu/WKNWprM/nnTaqQ+DzQdC 6r4xE1FWm720uABImbWFlj94W0NKEPyvaCp9bhVEL2Fvz52Cuumv+7vq7+4wZo7mI3 Q4ltRD9xYxwqYw+ej/rSXoc9kfgTQE24MArka8C/bYrJvbNy0B41v0B/6V1WnSvrTb FTHSo268/7veL8X3gOHnCl7KOzJeEIzUmq9YkYSm5/mBmsIOczTbcgbV9/xUm8WIWM prX8q2XzQWUPw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 22/27] kconfig: add macros useful for hashtable Date: Sat, 3 Feb 2024 00:58:20 +0900 Message-Id: <20240202155825.314567-23-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240202155825.314567-1-masahiroy@kernel.org> References: <20240202155825.314567-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789803805337010726 X-GMAIL-MSGID: 1789803805337010726 This is similar to include/linux/hashtable.h, but the implementation has been simplified. Signed-off-by: Masahiro Yamada --- scripts/kconfig/hashtable.h | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 scripts/kconfig/hashtable.h diff --git a/scripts/kconfig/hashtable.h b/scripts/kconfig/hashtable.h new file mode 100644 index 000000000000..71724800d178 --- /dev/null +++ b/scripts/kconfig/hashtable.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef HASHTABLE_H +#define HASHTABLE_H + +#include "array_size.h" +#include "list.h" + +#define HASH_SIZE(name) (ARRAY_SIZE(name)) + +#define HASHTABLE_DECLARE(name, size) struct hlist_head name[size] + +#define HASHTABLE_DEFINE(name, size) \ + HASHTABLE_DECLARE(name, size) = \ + { [0 ... ((size) - 1)] = HLIST_HEAD_INIT } + +#define hash_head(table, key) (&(table)[(key) % HASH_SIZE(table)]) + +/** + * hash_add - add an object to a hashtable + * @table: hashtable to add to + * @node: the &struct hlist_node of the object to be added + * @key: the key of the object to be added + */ +#define hash_add(table, node, key) \ + hlist_add_head(node, hash_head(table, key)) + +/** + * hash_for_each - iterate over a hashtable + * @table: hashtable to iterate + * @obj: the type * to use as a loop cursor for each entry + * @member: the name of the hlist_node within the struct + */ +#define hash_for_each(table, obj, member) \ + for (int bkt = 0; bkt < HASH_SIZE(table); bkt++) \ + hlist_for_each_entry(obj, &table[bkt], member) + +/** + * hash_for_each_possible - iterate over all possible objects hashing to the + * same bucket + * @table: hashtable to iterate + * @obj: the type * to use as a loop cursor for each entry + * @member: the name of the hlist_node within the struct + * @key: the key of the objects to iterate over + */ +#define hash_for_each_possible(table, obj, member, key) \ + hlist_for_each_entry(obj, hash_head(table, key), member) + +#endif /* HASHTABLE_H */