From patchwork Thu Jul 25 09:25:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13741675 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D125D198822 for ; Thu, 25 Jul 2024 09:39:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900372; cv=none; b=Jb6r4AZyuolAZNENDJcuTmPr1nUN9b5TlRwTq9tHnMxB7EGlKL1dFWlxRPc1LdvtWYPjggd0bG6ORA46Gt7XkYPelknoxfPxo1x88a9RRLGbb3F/BUKEatXrDWuOauc09R2lSiC9p5j3KI858VbssFkm324qfq+F8STvSeKy1Rs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900372; c=relaxed/simple; bh=hWXgMZ34iw7PGAEbfN9sMooQpaywW4W6Yp/28C6kGHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bgzT9x9ogQo+XYZTr3sZb51w8Q2jfr9K8KrqV+Dplyrq6CdiKR857GQ25QZ2dCzpFPwakgLt0boSJShX1bxmczkKdXk9hlIG/AF9GeQoTtFf6KKyJOct26QTVqFInWMLiRk1JCUZ3oY1n5wZv/baH7Se5ntlo+8kNNC5Tq4NR6A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GYFblSCl; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GYFblSCl" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fc49c0aaffso5467425ad.3 for ; Thu, 25 Jul 2024 02:39:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721900370; x=1722505170; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8NuaX3k1wXTe8+nrMWrHgqNmNsBhzatJwf158k3A+PY=; b=GYFblSClC1S2IhHrlI7T57mFVpZTPbglqUkkZRC1+gra3p6P/6bTFQM9CRj3kT0IAc WkzWPllt9N/MrgSj2KqG8KOSMtqHRN3lTVnabD1zcmb7dNr3XKsjYotPiNbwlp/b74vY z/5lCTNxwxboZIS2lZGLa3sr1NjTHLQEC+gDD7TnrZcuj1HkA07BpMZwJWPhurO2Yt3E bJ21YFoIYypo7Vxf22F92915X5gmAPjBspg2HDkM8ZNReBMgAZ7d0hz0+LnGzsiihiwZ t3OvL0JPj5ms99tqkrZpOEgTgo8Tic23TU+LgXDv78bv3nWoGubD3w25nAfzbj0Gwvtv 17pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721900370; x=1722505170; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8NuaX3k1wXTe8+nrMWrHgqNmNsBhzatJwf158k3A+PY=; b=TP6RStvOxX4VwzfM+cFPzmnU5qM4StiVjr2cKXZmQ+vEVUVGyTho0N5LQvoRGS1/vg ybW4bXEfgN6h1r5ebaeRZ78ZyWSiwmUKkS133mqIA1M0fq6eSYSNIWH1bPuiGNSFjIXp R2WeF76jXUTaJpzq344SB4hSLD+fSZcdq9NsXKB3B6s+ryrxdiIqmQH09YTEq4pMJjEA VqbonP2VrgusclfFld579GRS7SYnzyjoh/y4HwfxAxCr/s37LCiAf2reC9o/OSxKMRL0 6Na2ImcuYZJYOutLpzXrSJCKeQ7F5k6jmLmB5Pb0WQu8HD+HuQfUQcM37+0F3M0SZMrt XGXQ== X-Gm-Message-State: AOJu0YxCP5ttmC439KeJ4iGsrraDGdbLX3JfPvOXyvk6x/JHIYrVPu6x yI61UWKSFKi1/61wV3fp4ebOyRnHsvShAvs8Jb5+wMvApSkwjjGbjeZZeQ== X-Google-Smtp-Source: AGHT+IF4rzB5QDGHGIZ3FFQT2rAWeuvrBg+Frk+P4tOQNb8b4d+Mdtj+YZaD96y8OYtp4xlgslUt0g== X-Received: by 2002:a17:902:e811:b0:1fd:8c25:415d with SMTP id d9443c01a7336-1fed9273b59mr14282005ad.36.1721900369665; Thu, 25 Jul 2024 02:39:29 -0700 (PDT) Received: from Ubuntu.. ([117.96.151.20]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7cf1db4sm9950895ad.87.2024.07.25.02.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 02:39:29 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v6 1/7] reftable: remove unncessary curly braces in reftable/pq.c Date: Thu, 25 Jul 2024 14:55:53 +0530 Message-ID: <20240725093855.4201-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240725093855.4201-1-chandrapratap3519@gmail.com> References: <20240723143032.4261-1-chandrapratap3519@gmail.com> <20240725093855.4201-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 According to Documentation/CodingGuidelines, control-flow statements with a single line as their body must omit curly braces. Make reftable/pq.c conform to this guideline. Besides that, remove unnecessary newlines and variable assignment. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- reftable/pq.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/reftable/pq.c b/reftable/pq.c index 7fb45d8c60..1a180c5fa6 100644 --- a/reftable/pq.c +++ b/reftable/pq.c @@ -27,22 +27,16 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq) pq->heap[0] = pq->heap[pq->len - 1]; pq->len--; - i = 0; while (i < pq->len) { int min = i; int j = 2 * i + 1; int k = 2 * i + 2; - if (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) { + if (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) min = j; - } - if (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) { + if (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) min = k; - } - - if (min == i) { + if (min == i) break; - } - SWAP(pq->heap[i], pq->heap[min]); i = min; } @@ -60,12 +54,9 @@ void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry i = pq->len - 1; while (i > 0) { int j = (i - 1) / 2; - if (pq_less(&pq->heap[j], &pq->heap[i])) { + if (pq_less(&pq->heap[j], &pq->heap[i])) break; - } - SWAP(pq->heap[j], pq->heap[i]); - i = j; } } From patchwork Thu Jul 25 09:25:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13741676 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEAE3198822 for ; Thu, 25 Jul 2024 09:39:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900375; cv=none; b=EZRlESOCkKsgnKTofd1SV6SbUClmC6+bE3a0X5RJSZckDH5xIDFLwchSCRiciUULrcXA18dxOW2k1zjizy8hXxS9sO8XpCSCrPGT+/82GpyjUi7Xh/Rjt5BEUB+MEqK3PPZIbUqvRp+dofpA3VzDXJSg4qE+N0N+Rslm3i1EiNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900375; c=relaxed/simple; bh=7fe8b1Q8Pk/pmk9PSJwbpwxLZnOxvrkFTJnvVqloIGo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lk2DuQzPxZ06M2LImdp/YjECnEJLYWzIoAhgRJiHPC57upmxvmzzG7KyzCCqgnWZImF8T9OlNOU4W7coPgupjW9ocyC/ZmvrwtpJjo6VJity3tn/DKTcUaoMxtsoJ+NHdzcsdn39op0Vr0/cK6dGjyZSq+ArPRFGawxaPReIgh4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ff3UGbNt; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ff3UGbNt" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fd78c165eeso6240315ad.2 for ; Thu, 25 Jul 2024 02:39:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721900373; x=1722505173; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ylQ+xgFjJ2e2nKDrWOjwE4C50vKRhEy7qTSwCzeQ9JE=; b=ff3UGbNtkHwmtASs1DZx9ywHJeNS3/EViS6r21IATpaFEcqDGrOAtVfuGiTZu1WJZH 5cHt5VLLrN0AnSwPwM0ynYWVjsU6fPfj3wYPqnVP4N7Ly31On307AUuq63N4EN+RzmCM YYxK6abt4W6JGKGBIGcrgSUR4kSE1pPXBx2gKoDyRaSr92mFV+ir6T3rzsfqVvOv9j+a GzVL70TW+vu8Qlwg7XBavRounJnQqhBjqr++qbzakITkwQlIDQlr3suKBXbv2thh+IXO eI5mUqlpqIcbuMZOThDOYLkl98IM0l3DNIO39Df6FGjCFBSVYHuwWYYrdZ9aZT0aSxOg KJqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721900373; x=1722505173; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ylQ+xgFjJ2e2nKDrWOjwE4C50vKRhEy7qTSwCzeQ9JE=; b=dRbUOeHFpmVMDsMzfXvQuT66KRQj6yEVJWZUSTvkQ23Y7p/EbNOFwjxYv1ZbdRGmCq MryImNbhuI6ZMzu5AD9BOKNzgFr0GIALoBLNReoj0LkNWm7yerAAd2O5+pL2faQIj2mj 4xzRdtMDWvcH5dHZwdNN0Yskjzr7I3OMsjmp1Yt0modtXM/HjvcmdW5+Bwg0tnJU9qqJ alU7FCUwFPdwrbWxrMdUNv9TRwSBBoUlehNFokc+76WR4H4OVfTXke+rDkdYH/PoXlbY /6o1+0cofn5Ziu6CnCA8Jz0D0iqJFUSbZ4PaP+cPN6iuDQeVVwLYb2QtvFd+UIajdk3e 7EfQ== X-Gm-Message-State: AOJu0YxkEJX0sUalK8/cfSg+mz/awanbTBf7je2eGRuvU2ZR8+4YrUmf sqnpcFF6F8ZoP7G3QZg14DdqcyjbzEZSzCf65mA7iU14nbN2FjkI9pTmzw== X-Google-Smtp-Source: AGHT+IHX4LyDCEtVF1kcRJ+BBvt1+RP+IlbHW59i3pp6nyNLPj4nKscN9YePdquhgdoOP8RsHYBYEA== X-Received: by 2002:a17:902:fb04:b0:1fc:6a81:c590 with SMTP id d9443c01a7336-1fed9225cfemr11203595ad.27.1721900372563; Thu, 25 Jul 2024 02:39:32 -0700 (PDT) Received: from Ubuntu.. ([117.96.151.20]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7cf1db4sm9950895ad.87.2024.07.25.02.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 02:39:32 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v6 2/7] reftable: change the type of array indices to 'size_t' in reftable/pq.c Date: Thu, 25 Jul 2024 14:55:54 +0530 Message-ID: <20240725093855.4201-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240725093855.4201-1-chandrapratap3519@gmail.com> References: <20240723143032.4261-1-chandrapratap3519@gmail.com> <20240725093855.4201-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The variables 'i', 'j', 'k' and 'min' are used as indices for 'pq->heap', which is an array. Additionally, 'pq->len' is of type 'size_t' and is often used to assign values to these variables. Hence, change the type of these variables from 'int' to 'size_t'. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- reftable/pq.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/reftable/pq.c b/reftable/pq.c index 1a180c5fa6..2b5b7d1c0e 100644 --- a/reftable/pq.c +++ b/reftable/pq.c @@ -22,15 +22,15 @@ int pq_less(struct pq_entry *a, struct pq_entry *b) struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq) { - int i = 0; + size_t i = 0; struct pq_entry e = pq->heap[0]; pq->heap[0] = pq->heap[pq->len - 1]; pq->len--; while (i < pq->len) { - int min = i; - int j = 2 * i + 1; - int k = 2 * i + 2; + size_t min = i; + size_t j = 2 * i + 1; + size_t k = 2 * i + 2; if (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) min = j; if (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) @@ -46,14 +46,14 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq) void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e) { - int i = 0; + size_t i = 0; REFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap); pq->heap[pq->len++] = *e; i = pq->len - 1; while (i > 0) { - int j = (i - 1) / 2; + size_t j = (i - 1) / 2; if (pq_less(&pq->heap[j], &pq->heap[i])) break; SWAP(pq->heap[j], pq->heap[i]); From patchwork Thu Jul 25 09:25:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13741677 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 952C9198822 for ; Thu, 25 Jul 2024 09:39:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900378; cv=none; b=SZTYhWrg7rsGau4KcaExjpomDv431oDF7OrlcnmRWZ6P94/motmLWsk7I48hGSHAO/yNQRGOdhQkf2zM9bI7QOkuDyGr1e39tqPNc6Zms++80eCNmw4YAJl1TApJRUfsSGCQCdMOs46edCZyF0K+kv1vTG53n7hSIIlwNHJM/KY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900378; c=relaxed/simple; bh=3maJGZLQFy6uzTGwfimpdYlYH7mPuIRSv6/kGJ2VmP4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tLUPvV2lhBwKLDJKd9pYVY7Hut8sqplYt0T1lAP5bbp/0DSQc1Egkif1xXyX9PYJl+2K2eCyfl3zX0t3owwIC2vDx9wTCStmr4HxvAiMnYTZR6HuwMccaVBzJGxN8crp8Fy/BCvS2GRsDEMVHhSEMR6VSOI+brjZUXsBkuRUOMU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Vk86kS9x; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vk86kS9x" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1fd9e70b592so5357795ad.3 for ; Thu, 25 Jul 2024 02:39:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721900375; x=1722505175; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gWFYUT0nNbkUmcoynWmQbbaLqTcO6uJXhtAvh7Z3QKs=; b=Vk86kS9xRMHpqBlWz6whP951vGOPvUZG0pL4XFxX8aZ/S62MuYNspG6wua7tvDj56v HNyEiO6Kdmp0LJjvx6lyB0SMMGz/WQuBxy8HquCdyldstgeE7zWP0Ou2pppXXF4QltKE TFIf8PGWCgDugntVL4SlVd9cHu2Ulz+dMzskLD2y39pFA8bekKzvTkBQgdIQ7KfC+PIN 0xAkHgc6UTRKNJ7rN1l3FUAzdpXgfl9sipBEj2eK2cACuIL5k0rji3E/AjkC4aFrVGu7 DLbaX5FAMwHVE2VyQX5CCLa9cEJS9miy3KY8h6kwohlMdz2bEqqZZT+tKJDcZQlS/rF5 uZZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721900375; x=1722505175; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gWFYUT0nNbkUmcoynWmQbbaLqTcO6uJXhtAvh7Z3QKs=; b=r6Ygj7/nXribepQlcAdw/QMWSs+Jh8wD3mPr4AQsghZAJ4y2EvoaUb7KbkISX6LTsq VjDNWckSot9OoLXp2aiy5l6UtVyYAamM0bAwc14K2hq80BxmpraASiNqoD6BatklnVm7 p/oofs0vi3i3OprOeKT6WRmgfYXKyOQpQIbLXjmYUMIb+Iz8b3denXEtytO6n43OL+Qk 20vmQN3bG0NXzMhbyWPIAFJQwDgHikqXreFhYBLF9hf7lr9fESRJ+3HXAoiWDSjow4QD zqnLS1xpRQDy51AGnU+JPPIGxwgyUvfLfv6MVBVkuSflY25lOVhIxfMR93ME7xNEGpKh LrZA== X-Gm-Message-State: AOJu0Yy3fk6sSDuqmHtf34xqcCJ5ieEi81Gu2hfy/xoMsfsuIvmX3s9T EKwuL5idxXr5S3lkh0Fit2y7QMBglxCdVl78J9RZTLzBxkNe/IbNXQ1BrQ== X-Google-Smtp-Source: AGHT+IHHuA6hQ1g4T3tjdgh16azTuGZaJq95yDrJYb/v16u7AxHj6nvsmF13vljiJP20GrjZwsAbvQ== X-Received: by 2002:a17:903:22cd:b0:1fc:560b:1456 with SMTP id d9443c01a7336-1fed3860054mr24384235ad.15.1721900375373; Thu, 25 Jul 2024 02:39:35 -0700 (PDT) Received: from Ubuntu.. ([117.96.151.20]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7cf1db4sm9950895ad.87.2024.07.25.02.39.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 02:39:34 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v6 3/7] t: move reftable/pq_test.c to the unit testing framework Date: Thu, 25 Jul 2024 14:55:55 +0530 Message-ID: <20240725093855.4201-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240725093855.4201-1-chandrapratap3519@gmail.com> References: <20240723143032.4261-1-chandrapratap3519@gmail.com> <20240725093855.4201-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable/pq_test.c exercises a priority queue defined by reftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit testing framework. Migration involves refactoring the tests to use the unit testing framework instead of reftable's test framework, and renaming the tests to align with unit-tests' standards. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- Makefile | 2 +- reftable/reftable-tests.h | 1 - t/helper/test-reftable.c | 1 - .../pq_test.c => t/unit-tests/t-reftable-pq.c | 39 ++++++++----------- 4 files changed, 17 insertions(+), 26 deletions(-) rename reftable/pq_test.c => t/unit-tests/t-reftable-pq.c (61%) diff --git a/Makefile b/Makefile index d6479092a0..1ee83e98dc 100644 --- a/Makefile +++ b/Makefile @@ -1340,6 +1340,7 @@ UNIT_TEST_PROGRAMS += t-oidmap UNIT_TEST_PROGRAMS += t-oidtree UNIT_TEST_PROGRAMS += t-prio-queue UNIT_TEST_PROGRAMS += t-reftable-basics +UNIT_TEST_PROGRAMS += t-reftable-pq UNIT_TEST_PROGRAMS += t-reftable-record UNIT_TEST_PROGRAMS += t-strbuf UNIT_TEST_PROGRAMS += t-strcmp-offset @@ -2681,7 +2682,6 @@ REFTABLE_OBJS += reftable/writer.o REFTABLE_TEST_OBJS += reftable/block_test.o REFTABLE_TEST_OBJS += reftable/dump.o REFTABLE_TEST_OBJS += reftable/merged_test.o -REFTABLE_TEST_OBJS += reftable/pq_test.o REFTABLE_TEST_OBJS += reftable/readwrite_test.o REFTABLE_TEST_OBJS += reftable/stack_test.o REFTABLE_TEST_OBJS += reftable/test_framework.o diff --git a/reftable/reftable-tests.h b/reftable/reftable-tests.h index 114cc3d053..67283faf06 100644 --- a/reftable/reftable-tests.h +++ b/reftable/reftable-tests.h @@ -12,7 +12,6 @@ license that can be found in the LICENSE file or at int basics_test_main(int argc, const char **argv); int block_test_main(int argc, const char **argv); int merged_test_main(int argc, const char **argv); -int pq_test_main(int argc, const char **argv); int record_test_main(int argc, const char **argv); int readwrite_test_main(int argc, const char **argv); int stack_test_main(int argc, const char **argv); diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index aa6538a8da..b808ad3e12 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -7,7 +7,6 @@ int cmd__reftable(int argc, const char **argv) /* test from simple to complex. */ block_test_main(argc, argv); tree_test_main(argc, argv); - pq_test_main(argc, argv); readwrite_test_main(argc, argv); merged_test_main(argc, argv); stack_test_main(argc, argv); diff --git a/reftable/pq_test.c b/t/unit-tests/t-reftable-pq.c similarity index 61% rename from reftable/pq_test.c rename to t/unit-tests/t-reftable-pq.c index b7d3c80cc7..a78aba9e71 100644 --- a/reftable/pq_test.c +++ b/t/unit-tests/t-reftable-pq.c @@ -6,35 +6,28 @@ license that can be found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd */ -#include "system.h" - -#include "basics.h" -#include "constants.h" -#include "pq.h" -#include "record.h" -#include "reftable-tests.h" -#include "test_framework.h" +#include "test-lib.h" +#include "reftable/constants.h" +#include "reftable/pq.h" void merged_iter_pqueue_check(struct merged_iter_pqueue pq) { - int i; - for (i = 1; i < pq.len; i++) { - int parent = (i - 1) / 2; - - EXPECT(pq_less(&pq.heap[parent], &pq.heap[i])); + for (size_t i = 1; i < pq.len; i++) { + size_t parent = (i - 1) / 2; + check(pq_less(&pq.heap[parent], &pq.heap[i])); } } -static void test_pq(void) +static void t_pq(void) { - struct merged_iter_pqueue pq = { NULL }; + struct merged_iter_pqueue pq = { 0 }; struct reftable_record recs[54]; - int N = ARRAY_SIZE(recs) - 1, i; + size_t N = ARRAY_SIZE(recs) - 1, i; char *last = NULL; for (i = 0; i < N; i++) { struct strbuf refname = STRBUF_INIT; - strbuf_addf(&refname, "%02d", i); + strbuf_addf(&refname, "%02"PRIuMAX, (uintmax_t)i); reftable_record_init(&recs[i], BLOCK_TYPE_REF); recs[i].u.ref.refname = strbuf_detach(&refname, NULL); @@ -48,7 +41,6 @@ static void test_pq(void) merged_iter_pqueue_add(&pq, &e); merged_iter_pqueue_check(pq); - i = (i * 7) % N; } while (i != 1); @@ -56,9 +48,9 @@ static void test_pq(void) struct pq_entry e = merged_iter_pqueue_remove(&pq); merged_iter_pqueue_check(pq); - EXPECT(reftable_record_type(e.rec) == BLOCK_TYPE_REF); + check(reftable_record_type(e.rec) == BLOCK_TYPE_REF); if (last) - EXPECT(strcmp(last, e.rec->u.ref.refname) < 0); + check_int(strcmp(last, e.rec->u.ref.refname), <, 0); last = e.rec->u.ref.refname; } @@ -67,8 +59,9 @@ static void test_pq(void) merged_iter_pqueue_release(&pq); } -int pq_test_main(int argc, const char *argv[]) +int cmd_main(int argc, const char *argv[]) { - RUN_TEST(test_pq); - return 0; + TEST(t_pq(), "pq works"); + + return test_done(); } From patchwork Thu Jul 25 09:25:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13741678 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 496F1198A03 for ; Thu, 25 Jul 2024 09:39:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900380; cv=none; b=RvBBVR5x7xJOfezYT/Yg1GRTWAeCn31YFeqm63xKSSL6YA0qHnpj62adQYjLj9r4MhA1ihF5CwepbdD1RH1IaYv1aQrBs+hY5XNCr68i6tLn4v6ZH5cDK720ZhiiICPYC7PFzY91wJu66tsfzPYK/kGCK/zsM1bdxBKsv0OFsXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900380; c=relaxed/simple; bh=/4OTsqp7/0XagHHoHG87U3Cq8P4orhehoCjdV+Ws0UE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z/ZVYshIrJdStcUjel4f9EwGzNrat9yVd1FBgOYNW5wa1fMtsTmc9x6y/qJJJYPDEMwSVwmwKDKgy5WcS1KatHuC2T1Ob/gRpdMIunKzKCm/NYExU0HWOiRPVL6r5CBLyPJBy4e4E4GsE58vYav1NmiHOgmi2B8ta6izEuOM7G8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=L3/ohUVf; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="L3/ohUVf" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-7a1be7b7bb5so554261a12.0 for ; Thu, 25 Jul 2024 02:39:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721900378; x=1722505178; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0c6I6L2UI6Z07sVX/I4RZEpVOj4WiiO0O3zVyC+4ckQ=; b=L3/ohUVf9TJCPXkynrhtUjbGu4VvhF1pUrP6uQbzYH+e7cLKx9ctle5UScufcIOnsL oT5t0ah3n9QXn0IGYPOpG0MX6utIY8E111vN/hsJG8xNDE8q4jbGsno0q67gF1Uo4QTV PHQG5UaN5nNa1EjCYvMNG+465Co4iApMtCF532oPZsjJg9wHT7q2B+WTAaZUGBLkw/ur BS09AqjJNw++4MJU9YW26ANIJElLsA0sSRYr3/PbLkQBzFO5BdrPnRQTohPBQG1cE7lT cMxV8tqbWrb24NqXIoc6/H4rAVVD0vAgY0aRl9p8G+5WbclcC+FO7kICzPOegCxASoV2 Ef4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721900378; x=1722505178; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0c6I6L2UI6Z07sVX/I4RZEpVOj4WiiO0O3zVyC+4ckQ=; b=Dn6JDxHU9N6atALQigxLlqBU1g1MAc0CafUyIB7yMMm3JNzzlgWD3bRQBK+TrNnQyn s8c7VRMrw/5D6wQvwUwjDuy8SY5Q3P8o7TlBPVsZC7y/tvF+m1BYlg+N3KEkfwcm0u9O lAC8vHQDfg9V62lXbOoK0BTDwdITOhJiP+ZHfvMpmJHRIAX1vvtf/QakGy/JWgxf+Q8Z BwedxyhsIDqSL7hlJwW/GUPUH65dYo3xyZpMd9oIhcptUY0m0eGU8tKTJvMZs7Gm4XuZ 36R24EOAkiRLG1kB9wV/+kMmMkh0+b8brnLSn+kOVyFUQqReQ9Gv79vdH/OdIcB+PtRV sclg== X-Gm-Message-State: AOJu0YwZ/c6ffGzP/UqvQ/XRl+m4WgHduteb5WAqQu8wwYWyHe0iA+iM NQDg1r2Tl534TtdQVgRrdI6MskezCc3v5kp+iUjKrDV2Ek4yVMhWxxATYQ== X-Google-Smtp-Source: AGHT+IGteQdNImB9K8gkEHEPPI9Y1ERhOT8C8+tgR0cdKmydDG5U5fMUiJW5pBcar8IDPhsWzvIEVA== X-Received: by 2002:a05:6a20:a129:b0:1c0:bf35:ef61 with SMTP id adf61e73a8af0-1c47b1664c2mr1345639637.2.1721900378230; Thu, 25 Jul 2024 02:39:38 -0700 (PDT) Received: from Ubuntu.. ([117.96.151.20]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7cf1db4sm9950895ad.87.2024.07.25.02.39.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 02:39:37 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v6 4/7] t-reftable-pq: make merged_iter_pqueue_check() static Date: Thu, 25 Jul 2024 14:55:56 +0530 Message-ID: <20240725093855.4201-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240725093855.4201-1-chandrapratap3519@gmail.com> References: <20240723143032.4261-1-chandrapratap3519@gmail.com> <20240725093855.4201-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 merged_iter_pqueue_check() is a function previously defined in reftable/pq_test.c (now t/unit-tests/t-reftable-pq.c) and used in the testing of a priority queue as defined by reftable/pq.{c, h}. As such, this function is only called by reftable/pq_test.c and it makes little sense to expose it to non-testing code via reftable/pq.h. Hence, make this function static and remove its prototype from reftable/pq.h. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- reftable/pq.h | 1 - t/unit-tests/t-reftable-pq.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/reftable/pq.h b/reftable/pq.h index f796c23179..707bd26767 100644 --- a/reftable/pq.h +++ b/reftable/pq.h @@ -22,7 +22,6 @@ struct merged_iter_pqueue { size_t cap; }; -void merged_iter_pqueue_check(struct merged_iter_pqueue pq); struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq); void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e); void merged_iter_pqueue_release(struct merged_iter_pqueue *pq); diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c index a78aba9e71..220e82be19 100644 --- a/t/unit-tests/t-reftable-pq.c +++ b/t/unit-tests/t-reftable-pq.c @@ -10,7 +10,7 @@ license that can be found in the LICENSE file or at #include "reftable/constants.h" #include "reftable/pq.h" -void merged_iter_pqueue_check(struct merged_iter_pqueue pq) +static void merged_iter_pqueue_check(struct merged_iter_pqueue pq) { for (size_t i = 1; i < pq.len; i++) { size_t parent = (i - 1) / 2; From patchwork Thu Jul 25 09:25:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13741679 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14A60198832 for ; Thu, 25 Jul 2024 09:39:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900383; cv=none; b=aCH63AZMFi1JW49l6YB1+bE+2LCU1Q1oRXOk/Oas0KGkxKMSgbFk9u5F4ePbCkN7yrty1kE/11B474sEAsKfS6j7TRHgwtHY8ACZBKwLD6pdoH+KL8W8NGUrVFDfT3HgOBUrgMMaRJ/yOdJ9i8ORE1/40fCbB88wn4hGl+lV+Es= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900383; c=relaxed/simple; bh=lJ0cXIohnlHeDOyqRbU1Afyp/eEh9NcQnt1UB/p/M8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P8fCgPXgFHy4ZnWrleBPAUqNHjyMbejgg6Rzr9K66zkz18GtCYEin2XSI2HyYyrY5oaXaC8aOmA+zHAHPQjw6eZkNeWhj3pjCk/2bycDpQwyW3+JpHzDFmjx7EwCZO2LTORNBVrHcLsBcg807KTkpIj25yDCRVspxUVl4UKjk4E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=N5xGy92F; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N5xGy92F" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fb3b7d0d3aso4173375ad.2 for ; Thu, 25 Jul 2024 02:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721900381; x=1722505181; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C5Wp7fD3+IzmQYf4uzeVp+sx/sYc2G2N5WK5mg2pfmo=; b=N5xGy92FSXsauOuNq+Uf9gDLk0ymDGioyHvd0CK9tRewjYeP2mVfvajY3CoeclDJUG mj0zZXvUvU7I33JxSj59Fm5by/qouah9On5ogOq1yWxK/9WQCR1QNn/jMzOVt1Uug+o9 Hk50b2HeKbxIaUkzQMuGAiHqE1Jioo5CLFsZYU9fabW+N3F1Ye9v+mGcMV82bpoZN2Qg M/LNpNTjy+rQdULzWOayKt61arDAvq6jzTV2vKnCjd2m4/v1QhMIV8P9+XKb/92K3IPK NG5utiBtM/DkwrLBRu+aEnohDuUuTDBaMTD8+v9G5oINQqTW56L8TnTiVC1Dz1mJzwfT wa3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721900381; x=1722505181; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C5Wp7fD3+IzmQYf4uzeVp+sx/sYc2G2N5WK5mg2pfmo=; b=XZpsUwcACWVY0gkkpo3Ph/Fje1yWlTGtrhKRSSdY5utqqvdpa8czj2YyodCdycksAw 4aeckXYflAW0oxiom28bPN3GvkP2ONvu6foGi2sP5CGS4WAvgf2rapXrWCz4ds2luei/ rn3EtcWdzW9DhvK18yeutBXS9xEriyovK8TTcdcHBFbG1CrsnQYtrsOqa6CBZPzIJB4V pKBCUihSBOdwM9N1E8rTFGaAzCPBwOsKBkbTg0c3oZr0aMW158NhJaxq15ykFqV+EkRE 1aFnUTu3fIjF4t5RpKgcwoQjGmrT1h1+JyUtH0fmuuARh3mYudcpuCWyGc8Flk0v4Ww4 GABg== X-Gm-Message-State: AOJu0YzOgcHS1uMdSrhDNNP8iLvjoCVt6JOlQaUBCq0PO/tObe1j6Q3l SRa+rO4SC0667pMXRxRM1axaomS48EaZJx4x2m6bJJnPUT1sDiHVAplMsQ== X-Google-Smtp-Source: AGHT+IGSqMLuhrp359PWJnKpRK6vIvjxvJRUvs+NmBveq6LRMAAOgAYfEHGPbntdmy5zI6kbU8hyMg== X-Received: by 2002:a17:902:fb0e:b0:1f7:1b08:dda9 with SMTP id d9443c01a7336-1fed924ff52mr11674615ad.8.1721900381069; Thu, 25 Jul 2024 02:39:41 -0700 (PDT) Received: from Ubuntu.. ([117.96.151.20]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7cf1db4sm9950895ad.87.2024.07.25.02.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 02:39:40 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v6 5/7] t-reftable-pq: make merged_iter_pqueue_check() callable by reference Date: Thu, 25 Jul 2024 14:55:57 +0530 Message-ID: <20240725093855.4201-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240725093855.4201-1-chandrapratap3519@gmail.com> References: <20240723143032.4261-1-chandrapratap3519@gmail.com> <20240725093855.4201-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 merged_iter_pqueue_check() checks the validity of a priority queue represented by a merged_iter_pqueue struct by asserting the parent-child relation in the struct's heap. Explicity passing a struct to this function means a copy of the entire struct is created, which is inefficient. Make the function accept a pointer to the struct instead. This is safe to do since the function doesn't modify the struct in any way. Make the function parameter 'const' to assert immutability. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-pq.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c index 220e82be19..9230dd9b9e 100644 --- a/t/unit-tests/t-reftable-pq.c +++ b/t/unit-tests/t-reftable-pq.c @@ -10,11 +10,11 @@ license that can be found in the LICENSE file or at #include "reftable/constants.h" #include "reftable/pq.h" -static void merged_iter_pqueue_check(struct merged_iter_pqueue pq) +static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq) { - for (size_t i = 1; i < pq.len; i++) { + for (size_t i = 1; i < pq->len; i++) { size_t parent = (i - 1) / 2; - check(pq_less(&pq.heap[parent], &pq.heap[i])); + check(pq_less(&pq->heap[parent], &pq->heap[i])); } } @@ -40,13 +40,13 @@ static void t_pq(void) }; merged_iter_pqueue_add(&pq, &e); - merged_iter_pqueue_check(pq); + merged_iter_pqueue_check(&pq); i = (i * 7) % N; } while (i != 1); while (!merged_iter_pqueue_is_empty(pq)) { struct pq_entry e = merged_iter_pqueue_remove(&pq); - merged_iter_pqueue_check(pq); + merged_iter_pqueue_check(&pq); check(reftable_record_type(e.rec) == BLOCK_TYPE_REF); if (last) From patchwork Thu Jul 25 09:25:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13741680 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45940198832 for ; Thu, 25 Jul 2024 09:39:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900386; cv=none; b=bSsVOx0T6aAzY0fYmJRIDYNbsIg9ewvzbxBQ2Xq270Zq24bCfPpvPWMT5PZ6s++hdetA1JQEhIUTLKavISkktaul9L2eNsjkBsp8jxL2CZXacLUvJ/42bOpIOkSXzQHpoiQYdpO/LmcTrdsuwBjwMhltms4BVbZnh5mo4EwmLj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900386; c=relaxed/simple; bh=ykDHJvOTCiZrkMlDm6D0QFWaClkYj6yKEwzLATURDQk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eijljKxe78vgbYOO6gJ0VcadcrYZKldV6PZ/uBlFMxjfnt/1s//Xof6MSlK+yy4I/avXnRLgzAl4uWBrlQmnTdNI1BiE/ilxFppfLoHv+dPBj++UAYjf9n80328487a4XeISbAY2xW5A6BBu7PGM0yFUziSwTm4VQCGbJnt5Nus= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HCKy7fRw; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HCKy7fRw" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1fc65329979so5741595ad.0 for ; Thu, 25 Jul 2024 02:39:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721900384; x=1722505184; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jfg9mp0L4g3LaRMRZFYSMGJhe53+0XvEwoSveAwgzKg=; b=HCKy7fRwRbGBvAwpRMX6Qb1j0xmk0sDxImk/VSDXELfX267ZA7+LumePVz5mp5zHTE E9OwHha1OmWnwYtwZQ1FPCSLMdHKUe7iweAn1ogRp8sxB48aI8VVhh9Qo0eWBgVk0kHh iYrS10MUodGvV/s2K2aCj36Z2nFRWTJqAo/B931QUlx7gvwslzSilztlh1aBoClOC4JZ 7JzsyyEr4yK4unPZJ0JJYy473ptyCwxdYPw7fhPSFAgwv9PviyP3JZ6kX8MMaUYp4h5q 60swdyW2UVZTq/XtIDYy54Y43VedFmUXY1rgb81xFtTR6EQB/qRtZl+Ze422sWtyTMr8 ivmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721900384; x=1722505184; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jfg9mp0L4g3LaRMRZFYSMGJhe53+0XvEwoSveAwgzKg=; b=YniGIMKLnDv1SmaP0kggJZbhr8j71GYMt+ihuY1Rnr4O2+TvRUcyZE+dEASJPo07sp 1QYLjM7yG74NZaTZ7xFF6RHkygdYfJS4V+XRggVFBHWMCfI2TIRR+EuutLxIF1DJZwFH CIewTps6rEXr7QonhVGgtQvjnU2GEdK7KR+XsPAm0hYQI9MWIu0zIavLUMa84S73zvrV rKBQ+zkb3xgN0dg7YJ7j0oFh2zWGaEjuZ+iBcasV4IyJnO76OLcfaGb4vEcdF8xpZiNU /QDqeIdgAG9VT4Cunt9uVE4smoJ6ajG4E5UuFA0aIl6FCfpx0lYnmY6vzM+R3SNpUwl/ 8Hng== X-Gm-Message-State: AOJu0Yw99waviymW3gWWC7QcxbEWxjll314SFKCZo+lTyBcYh4shgEdm UZuMlaedc1+AzysoZz7xBVPGDFA6wb6gKZjng1KGs9SahQtG4OBSKjV2iA== X-Google-Smtp-Source: AGHT+IHSq65UyvETJMNi+wM0y4QmAbm2BkqPY1mf8icCuGtOIg7TDBmDX68FyjgpsUUsZM7Z3QxmxA== X-Received: by 2002:a17:902:db05:b0:1fb:6151:f62f with SMTP id d9443c01a7336-1fed9283ec1mr15312805ad.28.1721900384142; Thu, 25 Jul 2024 02:39:44 -0700 (PDT) Received: from Ubuntu.. ([117.96.151.20]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7cf1db4sm9950895ad.87.2024.07.25.02.39.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 02:39:43 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v6 6/7] t-reftable-pq: add test for index based comparison Date: Thu, 25 Jul 2024 14:55:58 +0530 Message-ID: <20240725093855.4201-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240725093855.4201-1-chandrapratap3519@gmail.com> References: <20240723143032.4261-1-chandrapratap3519@gmail.com> <20240725093855.4201-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When comparing two entries, the priority queue as defined by reftable/pq.{c, h} first compares the entries on the basis of their ref-record's keys. If the keys turn out to be equal, the comparison is then made on the basis of their update indices (which are never equal). In the current testing setup, only the case for comparison on the basis of ref-record's keys is exercised. Add a test for index-based comparison as well. Rename the existing test to reflect its nature of only testing record-based comparison. While at it, replace 'strbuf_detach' with 'xstrfmt' to assign refnames in the existing test. This makes the test conciser. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-pq.c | 49 +++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c index 9230dd9b9e..67f3e4546c 100644 --- a/t/unit-tests/t-reftable-pq.c +++ b/t/unit-tests/t-reftable-pq.c @@ -18,7 +18,7 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq) } } -static void t_pq(void) +static void t_pq_record(void) { struct merged_iter_pqueue pq = { 0 }; struct reftable_record recs[54]; @@ -26,11 +26,8 @@ static void t_pq(void) char *last = NULL; for (i = 0; i < N; i++) { - struct strbuf refname = STRBUF_INIT; - strbuf_addf(&refname, "%02"PRIuMAX, (uintmax_t)i); - reftable_record_init(&recs[i], BLOCK_TYPE_REF); - recs[i].u.ref.refname = strbuf_detach(&refname, NULL); + recs[i].u.ref.refname = xstrfmt("%02"PRIuMAX, (uintmax_t)i); } i = 1; @@ -59,9 +56,49 @@ static void t_pq(void) merged_iter_pqueue_release(&pq); } +static void t_pq_index(void) +{ + struct merged_iter_pqueue pq = { 0 }; + struct reftable_record recs[13]; + char *last = NULL; + size_t N = ARRAY_SIZE(recs), i; + + for (i = 0; i < N; i++) { + reftable_record_init(&recs[i], BLOCK_TYPE_REF); + recs[i].u.ref.refname = (char *) "refs/heads/master"; + } + + i = 1; + do { + struct pq_entry e = { + .rec = &recs[i], + .index = i, + }; + + merged_iter_pqueue_add(&pq, &e); + merged_iter_pqueue_check(&pq); + i = (i * 7) % N; + } + while (i != 1); + + for (i = N - 1; i > 0; i--) { + struct pq_entry e = merged_iter_pqueue_remove(&pq); + merged_iter_pqueue_check(&pq); + + check(reftable_record_type(e.rec) == BLOCK_TYPE_REF); + check_int(e.index, ==, i); + if (last) + check_str(last, e.rec->u.ref.refname); + last = e.rec->u.ref.refname; + } + + merged_iter_pqueue_release(&pq); +} + int cmd_main(int argc, const char *argv[]) { - TEST(t_pq(), "pq works"); + TEST(t_pq_record(), "pq works with record-based comparison"); + TEST(t_pq_index(), "pq works with index-based comparison"); return test_done(); } From patchwork Thu Jul 25 09:25:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13741681 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11347198A1D for ; Thu, 25 Jul 2024 09:39:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900389; cv=none; b=fQHV1hLt+Ijnqnu/NMsRXhpflY391Wlf8viLD7F4vOKFnI2V5LMsxYY+QnQ5e3KXcDMj3gWxYS1HeiQKvSih3EH/z19zoQX6Wbf0yurGyG4QjAeVn+97DiuWV6hjVfgbvs/ww2a1aFLJJMnLE17Zx5LodWO3zOi3uEQyfzcnAQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721900389; c=relaxed/simple; bh=ZN/PDq+y0zYFyIOyJBSePiGywPwxMctj8LK5FKWfTiY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wv25Y9yNWMlvCVkgx34wiqSS6BDQfeOfdABz6tcME8rCMMMPGNZKPk5e9QwSIhfXrO6MHvDT6BMpoo6VsyOy6hGM1MEAWC0Psnh4Adz/Yb18HZ4SdzH3jD4jMdhMjGygajNod5lALcc+OXpFB8cWrrP7xp9ky6BOzEXRcNCSTlU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nTelMOKU; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nTelMOKU" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1fd90c2fc68so6254865ad.1 for ; Thu, 25 Jul 2024 02:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721900387; x=1722505187; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tqklXr1euhQFKvZitHjqojSzFjxl8I8DYdIbc0pX1Ek=; b=nTelMOKUluNH+BbSJx531pNbvkTSgtO7uK6Vlu0pIXr2jOXMAduN4SmUV+v8rC0wqw uEuvi69lI0YZ+PumgiXj0biI6czBMoy48Lsr8yKiJiD93K9oasVLAPzWVBoiCZsuIXei 7v9V6gGls8hj2z6oT/0vxZTcpi9Q53Gesv8jjSaqWU4IXTJUybPavQo5ddYsd0n9iiH5 Mm/8NNa/5guyouZZ60JtX+gmIGqhU4o8PHhUftm+XabtEnnjwIYB5quhO+yeyZwv/T7e Ekk2UfRu2rNelpSYFF/CaWx5E+zwdYBQXkmcfGAV9spi4GSma/T/FXjPgSo/v0NidDcH HVIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721900387; x=1722505187; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tqklXr1euhQFKvZitHjqojSzFjxl8I8DYdIbc0pX1Ek=; b=SN4VUzwIAaJ28YYlJqVFKSnxPMHmatSRE0AQMqFMS1xS2Y/Q+xrJnw6C/b1yI06KZL VHg8/JYSURGuxGQVqCfUoErLGz11LxYL3Cc5QyTib1vG6I2J6mupxTmvIDDx+vp+HuxD Yyb+SQZj14gtLMyP/qx+8zABF7kcsixZRSrDhhZYCo6SLv9N7zOw/KVCDGI8cbrrW/cs b7L65pC4anpGganEOKGujG2u21lhM2dThbrtCzs8jX7n7sAxYizeTCWKdwcqNBJH8xHd x36rVoPWn3cqcViGW+mGznvtgpOVakw2yEW9YZJWK1QpPz+aCJE+5rASpXNWU3N7yPOm AdWg== X-Gm-Message-State: AOJu0YwHVUCyoCxASnt7tSJnuIJGrQbQJPS6+edAnuQmKtGFHC/FXHoX Eop9i1qKcfgXPyNc3mgiIjiFRSD2YlhEvlBvqZXmHQaZvhxaTMkKmqZPpA== X-Google-Smtp-Source: AGHT+IHTI1pCkrLWMuFkQBGH4SqaxkaSYrfuUWaYnktankZjsQd2Rir/ajsk2zmgu3hvbPir3AGpZw== X-Received: by 2002:a17:902:d491:b0:1fc:6a13:a394 with SMTP id d9443c01a7336-1fed3846907mr23780915ad.23.1721900386965; Thu, 25 Jul 2024 02:39:46 -0700 (PDT) Received: from Ubuntu.. ([117.96.151.20]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7cf1db4sm9950895ad.87.2024.07.25.02.39.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 02:39:46 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v6 7/7] t-reftable-pq: add tests for merged_iter_pqueue_top() Date: Thu, 25 Jul 2024 14:55:59 +0530 Message-ID: <20240725093855.4201-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240725093855.4201-1-chandrapratap3519@gmail.com> References: <20240723143032.4261-1-chandrapratap3519@gmail.com> <20240725093855.4201-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 merged_iter_pqueue_top() as defined by reftable/pq.{c, h} returns the element at the top of a priority-queue's heap without removing it. Since there are no tests for this function in the existing setup, add tests for the same. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-pq.c | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c index 67f3e4546c..ce322d7255 100644 --- a/t/unit-tests/t-reftable-pq.c +++ b/t/unit-tests/t-reftable-pq.c @@ -18,6 +18,11 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq) } } +static int pq_entry_equal(struct pq_entry *a, struct pq_entry *b) +{ + return !reftable_record_cmp(a->rec, b->rec) && (a->index == b->index); +} + static void t_pq_record(void) { struct merged_iter_pqueue pq = { 0 }; @@ -42,9 +47,11 @@ static void t_pq_record(void) } while (i != 1); while (!merged_iter_pqueue_is_empty(pq)) { + struct pq_entry top = merged_iter_pqueue_top(pq); struct pq_entry e = merged_iter_pqueue_remove(&pq); merged_iter_pqueue_check(&pq); + check(pq_entry_equal(&top, &e)); check(reftable_record_type(e.rec) == BLOCK_TYPE_REF); if (last) check_int(strcmp(last, e.rec->u.ref.refname), <, 0); @@ -82,9 +89,11 @@ static void t_pq_index(void) while (i != 1); for (i = N - 1; i > 0; i--) { + struct pq_entry top = merged_iter_pqueue_top(pq); struct pq_entry e = merged_iter_pqueue_remove(&pq); merged_iter_pqueue_check(&pq); + check(pq_entry_equal(&top, &e)); check(reftable_record_type(e.rec) == BLOCK_TYPE_REF); check_int(e.index, ==, i); if (last) @@ -95,10 +104,51 @@ static void t_pq_index(void) merged_iter_pqueue_release(&pq); } +static void t_merged_iter_pqueue_top(void) +{ + struct merged_iter_pqueue pq = { 0 }; + struct reftable_record recs[13]; + size_t N = ARRAY_SIZE(recs), i; + + for (i = 0; i < N; i++) { + reftable_record_init(&recs[i], BLOCK_TYPE_REF); + recs[i].u.ref.refname = (char *) "refs/heads/master"; + } + + i = 1; + do { + struct pq_entry e = { + .rec = &recs[i], + .index = i, + }; + + merged_iter_pqueue_add(&pq, &e); + merged_iter_pqueue_check(&pq); + i = (i * 7) % N; + } + while (i != 1); + + for (i = N - 1; i > 0; i--) { + struct pq_entry top = merged_iter_pqueue_top(pq); + struct pq_entry e = merged_iter_pqueue_remove(&pq); + + merged_iter_pqueue_check(&pq); + check(pq_entry_equal(&top, &e)); + check(reftable_record_equal(top.rec, &recs[i], GIT_SHA1_RAWSZ)); + for (size_t j = 0; i < pq.len; j++) { + check(pq_less(&top, &pq.heap[j])); + check_int(top.index, >, j); + } + } + + merged_iter_pqueue_release(&pq); +} + int cmd_main(int argc, const char *argv[]) { TEST(t_pq_record(), "pq works with record-based comparison"); TEST(t_pq_index(), "pq works with index-based comparison"); + TEST(t_merged_iter_pqueue_top(), "merged_iter_pqueue_top works"); return test_done(); }