From patchwork Thu Aug 1 10:59:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13750190 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.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 1644B189505 for ; Thu, 1 Aug 2024 11:05:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722510325; cv=none; b=EgUy2/512YLMRi4s9a0gfRkOuMQwSO6CnMwWUJgzFg7ptWJajqLpVa3+G8JtXTJSJWS/HQzoRRIBmXV4zo+ojmNutAwcCRYKdT7RYMI/UAdYogwlTUtNKN/7BE5fEcnaDTSgcFANpdH3hZnjJoj6gPMT6G/WFsciAZVL8HAOcVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722510325; c=relaxed/simple; bh=hWXgMZ34iw7PGAEbfN9sMooQpaywW4W6Yp/28C6kGHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mU3x52i1gFW7TW1YpXKX40AcQLnRzm6p7M4C4WZ3GOPuDzZ0C0LqU8qMUa0QEnntog/N8N3wx/iQ0I5ohuEsnfbhg20GY2N1CFQTWHkumyZcQeggRYzbxt+tAVd39nvUhzy8qssvU3Ehv6A5RE9tf1pmEYXTwSbqLdBWYXbvpio= 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=hADuzR5B; arc=none smtp.client-ip=209.85.214.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="hADuzR5B" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1fd66cddd4dso61221725ad.2 for ; Thu, 01 Aug 2024 04:05:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722510323; x=1723115123; 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=hADuzR5B/T69z5rhD0TIKeDJoiUhShXrf4BEAyJwqe20GFtWh9cHGVGP1ifagYKkoj kd7OEhgycdH+KMkBbIhKbS46n7nKfnjsGfbMDUgSxl5SBXtaQf3vHZcqqdfEzC/tK+ZA ++SBQ4/rsh0vM95/bMJJJdwWnauwC7K3DFo/EhND8vc1SxlkTcESbkqZeB1tEywNot9A On35JibvNfgPrwjPV4QFdGN0RVD0ehyHVEuMOI8RZC0ej1Q4g4+2na0H07S+XafC6pdt GW3zdZ09sXpE7rnnEdpUe5YfIjdCWMKO+lJ1bawt7iY37uI9ImICye9Y9lmrWeN6NsCg 2a1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722510323; x=1723115123; 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=K9xL6Bgdzsrvn/4DIcAo9GhVbBy8gdSF4wup4LlQXE8umUMdpbOvRvHiR9sYYe3HPs fli8mlmUPKttvJXvMZnQvZyEU5WL5icAFnWQVoA00qvarqFFjPDg6iDLD9pX1iBgzK3w fNN6vRSJtYOVlMEJbxGaL9QCJYe5nCJI2jC6B6O6QWRZJGRikYzhNW9fKUhMggq2Zsbp j1jY/mFV7puCw9WsfS+B+zFfXrO/D74p2QV9G3e/qvTu1kki6oIpK3rrHK1355dshbTY 5Wjnm3JcrKNpW4if0m5/fd/uVq3GsTuGBPuxQSJIc1delIirf7t8YCDUg8FiHQlxNIZx Jmig== X-Gm-Message-State: AOJu0YyLViu0/2UsAj2pNzWktAoxHQzErJweb++9FgzqAWfpIHkb72yU 5HoU7ePv2yRiMEZQDD/M3A4GMElgXQ1JpBAv7+o2D3kFJI7NsN7BJD3WMQ== X-Google-Smtp-Source: AGHT+IFp4TR5wRNz+iZLXt9SXu1/UA3ifrfbPFjG2GeDxLl3UkUXPHBaI4ohaWi7i99X8RnqG7DSNg== X-Received: by 2002:a17:902:fac3:b0:1fb:5b83:48d9 with SMTP id d9443c01a7336-1ff4cfd1dc8mr20805385ad.37.1722510323014; Thu, 01 Aug 2024 04:05:23 -0700 (PDT) Received: from Ubuntu.. ([106.194.76.199]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7edd90dsm136663985ad.161.2024.08.01.04.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 04:05:22 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v7 1/7] reftable: remove unnecessary curly braces in reftable/pq.c Date: Thu, 1 Aug 2024 16:29:42 +0530 Message-ID: <20240801110453.5087-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240801110453.5087-1-chandrapratap3519@gmail.com> References: <20240725093855.4201-1-chandrapratap3519@gmail.com> <20240801110453.5087-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 Aug 1 10:59:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13750191 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 A91C918950A for ; Thu, 1 Aug 2024 11:05:27 +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=1722510329; cv=none; b=px7jV5uZ07GV5LoVwLsBZ3whj4tFS5OYuhx4NXa9KT7yuQZdmPdrcLNbUpXxLgi04Se3bipIiJ4X/AJ0EQ9uaxDwkdH3mq+UkGNvuIQ1HfXW3lPMZ+wFtKmWNkXbCjfvTHBoCdZsDQnT78wMTLM84AxUfgoiZalqyeWxDlhvqOQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722510329; c=relaxed/simple; bh=7fe8b1Q8Pk/pmk9PSJwbpwxLZnOxvrkFTJnvVqloIGo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fu0/pQKe8VDkmwmBn+QAgAMEaWiVaIOMrhfy/T/Nr9ACNjrT9sC1XdABA0QCMiBh3aV+sfyJVZqTJ6yIF9FIbUkrx0/SiaehOz5sezSkRhIjS7sscd76r0ZTJfmSXZdZDw0DFVm31ruCMd244pRL9kmMNKjtnuQHAJc07R8G5MQ= 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=I9SohPGR; 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="I9SohPGR" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1fc49c0aaffso51052195ad.3 for ; Thu, 01 Aug 2024 04:05:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722510326; x=1723115126; 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=I9SohPGRea/7BQM4x8X+TlcP2+NX6AWd3JXOwqhJH9xGpdOSol2OYqVO8afyFlfptL DN0DBpbAEB4/4RKXIrJI7T7scinWLzbKt5/bVgb6uDgoiwCvQYZEHQL9F+aMtRez5j9g jJtvImngrFvPLl/PEQJGXhDWsx6cwEs0OnX8HW9ftzo3L50KVoZRxFcaFRqxbYGjAars caWapeeXMkspA9zWVgtyaK1b5Iskiq35mhFY67K7TdUrFlnSE75Ya4np5ihtCSuby9EC xj/QYGDzsgKp65+2JLxXOozBRI0iAwmdYCIv0x7iZINMfowQFnInSaA1NtR9YwUsaSDy k/Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722510326; x=1723115126; 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=aISmSnsVh6Pd8PMLgxOiyegHa5TzwHF/LOWBKrsDEWz7dE0Fc/UiMimm2oBp6R+8K8 +pLTImZJQCoNxeImP0jbNIe8FvuZ5abBqj8p+0CdLeSxOTLhePeZlx0J/kcp5GH0eiTW cxoSnqzQ/kouZaEIo+hDNSkZtzBonhHlraIz4X4OWXFywld8TCWNHYldOP2tCAB0/u8p GFHcEGUL7FFAxV0duJJOweYsFen6GqoXHRhKOdRQvAwTNzkgE5I55gb/jprHNr2nrDer sCPnr81Fb1L3Brj+pavim+6WrWkrXdle1IKQIhIk7+ZTeL9WlUT89i/p5b3Be36j+oql MWHg== X-Gm-Message-State: AOJu0Yyt0RSBSX1Co8jHYla8J1xrpYch/ZeL6YchiRAiuMHs1ymgMnAy FRyG9tPC52CnV9xhmbbguWa2o6AzBweORb0etTQ1/ug7EFWnY+H+mWVhWA== X-Google-Smtp-Source: AGHT+IHCBWD1wn3Nu+Xw7glsT3oMmTLVuaTzk4h2VxC+V8xkJFVDVk5hyjpc9ROcxHSrz7zedztNpg== X-Received: by 2002:a17:902:d487:b0:1fd:67c2:f97f with SMTP id d9443c01a7336-1ff4cea5d79mr236995ad.28.1722510325973; Thu, 01 Aug 2024 04:05:25 -0700 (PDT) Received: from Ubuntu.. ([106.194.76.199]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7edd90dsm136663985ad.161.2024.08.01.04.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 04:05:25 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v7 2/7] reftable: change the type of array indices to 'size_t' in reftable/pq.c Date: Thu, 1 Aug 2024 16:29:43 +0530 Message-ID: <20240801110453.5087-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240801110453.5087-1-chandrapratap3519@gmail.com> References: <20240725093855.4201-1-chandrapratap3519@gmail.com> <20240801110453.5087-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 Aug 1 10:59:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13750192 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 B7657187FE5 for ; Thu, 1 Aug 2024 11:05:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722510332; cv=none; b=lL+Ys8P0/u8S3IU9GnbtKk6Kiw9nUTMVo/jGqjuWtbvV+dAtldOanZQcp6/9s90XYYytqjOhA1Cyzpc8Yth9neRxr9NCAty3be5E9TvUO3TfMlbSs8itxVntF0U8RQdqmIZSuU23e3kfc2JD4eZyu6m1fJp/zS0BdhGaoH4B+5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722510332; c=relaxed/simple; bh=3maJGZLQFy6uzTGwfimpdYlYH7mPuIRSv6/kGJ2VmP4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tyIb4clDWsfsE8vJZa9pmzFZkx03n/i7X7I3jSyo/lqtHHxDLrFj937CIUEgc7j5IBh7EWj6Ync9d93pSyodIGh2IPD7nP99WwedCn/lTSZpHD5byZF/k0/e61JhSTzNZiyhwg24HgvaYNByY3bHSK7HOsHBhyGWwTs0jsL1rxk= 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=Phne8xWz; arc=none smtp.client-ip=209.85.214.178 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="Phne8xWz" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1fc4fcbb131so60184655ad.3 for ; Thu, 01 Aug 2024 04:05:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722510329; x=1723115129; 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=Phne8xWzzEpsyad2/qWOVLl7VcUvK6vAVBBECG34HnTWYOug/ZJsGTtIc399jdl5NN lSzHt1qf3OBH6IZ3ZzHaiI80tquLhH0QfLf7ZbKoqlXd4blzo4yvvNd26Oocr4JCHyVA 9lpUFKB0fjJJtu7+ubAWFqwAqZ4UhRLOO7S56w6LAQ1h3ayChZay4vxKOHgaLGFSxPRi Vhjn1XjHScolFmXMzGMA1H+nm5uxIjJYi28/PivnhGENtKhlM7F1ztP6t14wbM940IkM PAFQkamYODQul0uIWAFSazdZVe4qsQQsX5fGr2s+1uCtQk6/A8dqY1XJeYgLFktCgpGM k92g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722510329; x=1723115129; 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=GWCX6PvPkj3+7scRv5PJkFPC6izhkNIj0sZYh/nFyygK1GYVMZJNJj+CvC7h3mlF1S 0jFqrdlacYyldi7Ueo0PvNNXTTMiOFqLGcGNuI/oE4kaggpORjQu6Bvl6f//79j1/M+d Jmhrypy4bk02oqzwXvxzCpSP8mYYi1Fxl+P9QHPReHvn1wonVpbVRYQk3iACjQofU+f9 Dc65JL2tXW7ToUe5x8T8sepEMp328jpHMnRPJzZ5aeos/TNIZ5tj6IXd+Am/a7W/84qZ x+Zmxu6kzHEbrle96smgEvg8ObWvkEy6mUAlH4y3UdKuh2xfnkoxn2kPLlMLnozm8XsZ G99w== X-Gm-Message-State: AOJu0Yw5qarC0r0uZzB1QI4q/Hc3XS/eCvjrG7twTqDF5gSStMhxDDfL B6xSFDuoIPVRciIVdynUEBOXzbSGvIFfdkRYb+8LQ4244jDdURvomzkgiQ== X-Google-Smtp-Source: AGHT+IGmI1sZunKvQ4YJc3vZYOqIsoVGz16xnT7DrjpZ52uGqUX0rkyJGdNnbeZvF+KWFNAqm/PULg== X-Received: by 2002:a17:902:e748:b0:1fb:62e8:ae98 with SMTP id d9443c01a7336-1ff4ce51dcbmr2285505ad.3.1722510329158; Thu, 01 Aug 2024 04:05:29 -0700 (PDT) Received: from Ubuntu.. ([106.194.76.199]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7edd90dsm136663985ad.161.2024.08.01.04.05.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 04:05:28 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v7 3/7] t: move reftable/pq_test.c to the unit testing framework Date: Thu, 1 Aug 2024 16:29:44 +0530 Message-ID: <20240801110453.5087-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240801110453.5087-1-chandrapratap3519@gmail.com> References: <20240725093855.4201-1-chandrapratap3519@gmail.com> <20240801110453.5087-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 Aug 1 10:59:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13750193 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 6927A18953E for ; Thu, 1 Aug 2024 11:05:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722510336; cv=none; b=sk1CqiaUXvbHSrQKp99b/fCSP7FA2fBmOSnVVfOOAEXzVTmZNjB3hEUv0bmJQxWmVkgAuYM23n8NGggHKBWV3iIOA8CniMbx+q2OKXHzb4CyJrFcs34AzMhvDB+AEQRxT+myj/xDPBZWCAHrLKY8YzHhCzZ2Gddjx/9rCJ7Boao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722510336; c=relaxed/simple; bh=/4OTsqp7/0XagHHoHG87U3Cq8P4orhehoCjdV+Ws0UE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NcAdlyHjFV5N3OdZHiVGLKZxdc4ZBx8yASTjXGnFHG7Dr6P9NjyTEV70DwCFvY6Nc7MWvQOjlChXqQHM+Z7+E3pmBB+Nid1t7Rv/JXomMBAadLaZsDvUhNXdqnuI34JNVLixslsbJetxX7XGsH7tRyUlk52xcgMjuhtD6FQ0Bts= 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=U4pm29td; arc=none smtp.client-ip=209.85.214.181 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="U4pm29td" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1fc611a0f8cso50173885ad.2 for ; Thu, 01 Aug 2024 04:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722510332; x=1723115132; 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=U4pm29tdHGMfJ6p0os/tZ6hrHJ1JhSVP6Y9fm9ZwoRWs9vyPpuRamSUcAH2uJXpML6 LRugtOSBjsj/uW56P5Zt9XxyIbznk7NumhB8YIDISBiO/sJlLPPI9J4Sh93Xi5gZxv6p Nmv6Nufg+I/8Ul8vV6rasM7ZriNNfk22TRo9WCEyn0b1ySq/JN7T2aivPidCrSjpPLcv v/yKZYLxk8r13CC3i4mEEKmS28v8JFjV3FAaFLmjN5+7+lDGmP17ZeE3uqlRkG6LynDd RhHuW5YXrUP8kAfQCbqsJyawgnYnPfuFG/f2QiUzbKIKFw96QXnd0ClMGPm5hSPe2ywY Zfdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722510332; x=1723115132; 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=pczeMwhDtw+uyOKvrA8FGmW0eBKeREGBKMyoM9OaPt5L30WQM9KQEpNFcmq+/pteh1 KussZalIe8BMF7lGYJT1pXQd7EgnqCIv602AVPHnpDaLIUMUrlgOykewj/t6/KrHJbxH oU5G88aQ4q1I67amSc7G6mi9ywYraLwyjqrTUZ8Q8qZWKUborQnX9HX25IsOFqZ2LAMQ TSFIF53w4lgq9W8cStZvd7WauSlh1Pur1qoGLt2ZCzXIrLzt01XIQbqQR1xt/uVTZoG6 slZradejrPSbGT2EJHCrDgTtVvAvgNKlD9BLAHIYzPFR6DpM5rGbd5cOiWaO9UR1qcFX uSbg== X-Gm-Message-State: AOJu0YzHQexvjadJz3aVm37stgWeMTRJ6Ge4N0kF1i0PLbTgnJjt4JHO Tyffi6wcZksSGH5ZWKCJAmTbAhHXTe+V4KtYkbTbtGm7QjUSKNig1jKtJw== X-Google-Smtp-Source: AGHT+IFduLw6dzOsz8z5nZ9sFjeCx6Bb8txeDz/XBINt5bNg/6iH0ldVocRi1Iw6AVVme4/Xkg6jIQ== X-Received: by 2002:a17:902:c942:b0:1fc:57b7:995c with SMTP id d9443c01a7336-1ff4ce58802mr25934735ad.7.1722510332188; Thu, 01 Aug 2024 04:05:32 -0700 (PDT) Received: from Ubuntu.. ([106.194.76.199]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7edd90dsm136663985ad.161.2024.08.01.04.05.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 04:05:31 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v7 4/7] t-reftable-pq: make merged_iter_pqueue_check() static Date: Thu, 1 Aug 2024 16:29:45 +0530 Message-ID: <20240801110453.5087-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240801110453.5087-1-chandrapratap3519@gmail.com> References: <20240725093855.4201-1-chandrapratap3519@gmail.com> <20240801110453.5087-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 Aug 1 10:59:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13750194 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 3387D16DC03 for ; Thu, 1 Aug 2024 11:05:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722510337; cv=none; b=bUmn8x7FK8Vw6NR84apqzoBPKDRXRxNI/i8Ptx7r7/IJr7Ft9gyLtCP/63ml/61IIXb79vw9IwK6k/xZ9XBHsrajtR3ao898NLfzmD5Xph1S7tdfOEMLSbfZki6H+AM5QRufvRmrCUtrgFnfsaG4R/TMtIZMXiiNCEPQSGf5Weo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722510337; c=relaxed/simple; bh=lJ0cXIohnlHeDOyqRbU1Afyp/eEh9NcQnt1UB/p/M8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V2pB0cshopNBdS6psCopfmtcCEC3ZnQMZQJ5pntUgr7UimQuS8pn5XVkqnJnjPfk7mTARA2YlhTBU44n9zQtVVY9x28bmUKqHyyghg766VUiac6oHOUj4A4ORgYoUFsqyYyhWXMO3JRFIEp07MMwEFTVfR75oYlnSwRvaTrfTVk= 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=SxEATg2W; arc=none smtp.client-ip=209.85.214.172 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="SxEATg2W" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1fd69e44596so14885045ad.1 for ; Thu, 01 Aug 2024 04:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722510335; x=1723115135; 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=SxEATg2WQVYYfbPe3YtQ5oF7hJQLsnp2GDCbvSEeASildBDDWWONGIpXp/I0BRQdi7 977L83efLfviMnT/N7vMU1fE0XxlAC8Yr7FqhUfNPkn80vPPz0NASxwo/rPL+YsyhCcM 1x5oRjIkCoYk2MkRo5w0smt5WIuryNCEBgcIA+wkHl4smpURM6dFrOunpDaePInPGdhA gsFxG79KMOlt/TQubVWaO4xszvQ2Ht61ZNvN9uIonVa4TSODcMpJHiyGssUsh2gRvUJt 1xUdrxbKDQjIOnmddgreiSGvyKEwcQ6wgTqaP7MFbBmcLZlxGvqBzu7U0PptXVmMIRFv gsdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722510335; x=1723115135; 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=xJxfMss3qIIIsOM2MonNI7WgheOGZwNFEkoSDDo3GNduTbGyYl+0ph+TErMmk92rhH kDPDrx8iKCeOWHf0fnnjf+S0rSWGar5u9cQ0kUZl7SxR3IMrsdmbf2kZ0MHsBva4BdNR D30PTMRSeNvwo25gRm1fkd3MrSjW9x20VdS1AGDNEuJLgc10Rs0mpKoSixUEBINNlEfJ Zg2R/R3dhtU5zBmfFB3nv0+Znquw/7iyWGrp/OI+Tkg38XOqvp/j3QN3nCrG4Sh+ccNF KXXmaTd0/i5FZCOFL3JYj8d8PQGb1/LVrxBbkv0hFYFVq8w6+HSs0iHL5li7p0ryigq4 qNAQ== X-Gm-Message-State: AOJu0Yxi732EENh1s19F+2LetlGJkbYr9gLMLwI7ge/wZLK9gruJAM+M n39XbVhaYG0eS3HpxxUVprmVsMqfc6ne+wHvPfRzF2yhts/SP0iC2cHeQw== X-Google-Smtp-Source: AGHT+IH/DcIJtpsBrtst814t4S8at3v3W3QglI5zxODQSLNO74SRxvy3wtjmKU6nj0cX6URNYpwEtw== X-Received: by 2002:a17:902:f544:b0:1fc:4680:820d with SMTP id d9443c01a7336-1ff52434027mr14588695ad.9.1722510335022; Thu, 01 Aug 2024 04:05:35 -0700 (PDT) Received: from Ubuntu.. ([106.194.76.199]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7edd90dsm136663985ad.161.2024.08.01.04.05.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 04:05:34 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v7 5/7] t-reftable-pq: make merged_iter_pqueue_check() callable by reference Date: Thu, 1 Aug 2024 16:29:46 +0530 Message-ID: <20240801110453.5087-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240801110453.5087-1-chandrapratap3519@gmail.com> References: <20240725093855.4201-1-chandrapratap3519@gmail.com> <20240801110453.5087-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 Aug 1 10:59:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13750195 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 3C8A416DC03 for ; Thu, 1 Aug 2024 11:05:39 +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=1722510340; cv=none; b=O1JmeyBfZdsPGfNuBz0qXI3+bak//oXIA6JCEujqeEQwfDDTXM4tNFf0rBjY28kX83JzIwHmR1mY8etie5ZqCZ+BO3YTqELfDJj7bMaMJ9yqTLAqo0/dISXOtFehkoiDQcNguuBAdrKry00dN+bFxfM99BdV1mS4My97kRaKhvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722510340; c=relaxed/simple; bh=pynCJ6skDk71/w8A2Q4B2tpMQReMSryfYOPuH77CNCk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nd00RsfkZCx5VtKrYBb2tgKy5LkZKRf6ZrwGdxihzucc34k0c8D6Hm2xsaSCVWXEdSyge0LT3dRM9F1NlUePACub3kuTaFna+C50Tad4z4QxsZwjjKed22jj123B8DIbIVlF/kV+rMDCYDUcKndLkqA40Q2/6iYytFzE4DAgFIM= 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=EpfW6//H; 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="EpfW6//H" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1fc66fc35f2so14507975ad.0 for ; Thu, 01 Aug 2024 04:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722510338; x=1723115138; 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=SaYsYjWQ/B9Fr4zsediOXWxGQvonmVtVMDxG1LPm0R0=; b=EpfW6//Hg/Lninhl4P4xsZ++g41x4ktpZ1glFo3QmwZ3d32e+ExgNJZOiAOUTvKcTi G3G7bv0jX2bM9rn98d9qMjathPDFFJ13C3brSsMDGgVgLL8b08hzX9pKrJBQZdn8Hoc8 1eO3ZVvWZcl7qcDzMIISCON4+YlZGwFVqatfNVSckUO+rewQo467KvuuHL9Hs9p+5EE7 Qpxj8XUAzsI0gM/4yIZ8R205CI6nNFhCETjzFw3HiXGcwvJmoM29bFAUegXcSVxCS7iN OcLcbfk2jd00MXss+N//CsFo55Q9iN65UsJxMI3DBBNQnr6muwctdw2NLFt5i7kJBCol /Pfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722510338; x=1723115138; 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=SaYsYjWQ/B9Fr4zsediOXWxGQvonmVtVMDxG1LPm0R0=; b=Vps+MW9td8nA9sT+8Jn17MkMKVqaT2yc8rPo3Y2reNzuE9j4Sj8Sk3DeWE+KpMQ4Z3 2WTZRj5ZvWYwsX2FuP7n/2qW8M9oqV5X3VASOyTvDVyL2p2EC0sIjJ+GTcc9/ZUDyN/h N7TR8QxW9SEBvNBB063uveWk7Ogx6WgtXaRrupitccN0kQxQ1ozo2xMGUEukW0bCm1LN Qx1hik1QNk3SRl++zy+Jn120q2tKn2EbdQ4hemwwEcDwbdNW2JIy5i9l2aCkjTyw5BYK www6D0Y6ep9PJ4+5u6JJq5Ak9RyVrJdVDX9IHZC+NIAgNfNtiv7g6jxrgzvbVxuqwswk jSKQ== X-Gm-Message-State: AOJu0YxvNnEhW6zOy/SmI9bWuMujqDJiI3wevM6SJD8hfEaehqBEfb2x RGTyT3jeHp47J/8jAKQKscWg9UgGhqCU/snlreDTM4vNNOPFfFZZ4yCBVA== X-Google-Smtp-Source: AGHT+IH+j7djkILUa1w3m8t/lWa/06LSmSBjNYeB7yKTfjWl50dzjCGsrS6M1mYLseCiclOACEHunw== X-Received: by 2002:a17:903:1106:b0:1fa:1be4:1e48 with SMTP id d9443c01a7336-1ff5242861emr16940975ad.11.1722510337980; Thu, 01 Aug 2024 04:05:37 -0700 (PDT) Received: from Ubuntu.. ([106.194.76.199]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7edd90dsm136663985ad.161.2024.08.01.04.05.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 04:05:37 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v7 6/7] t-reftable-pq: add test for index based comparison Date: Thu, 1 Aug 2024 16:29:47 +0530 Message-ID: <20240801110453.5087-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240801110453.5087-1-chandrapratap3519@gmail.com> References: <20240725093855.4201-1-chandrapratap3519@gmail.com> <20240801110453.5087-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 | 48 +++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c index 9230dd9b9e..70ff89507d 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,48 @@ 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 Aug 1 10:59:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13750196 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 BA97861FD7 for ; Thu, 1 Aug 2024 11:05:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722510344; cv=none; b=rLw0pn/dDqDkt8QzU0xsFAEFMakf1cda0WagTQ9prSK8kXiXMjM+bg08lo/AvBxv7aoXx2g4M6CW6IPzy5dYYzndzZOX50lFp4BRGA3bbDJktINBGhJuiTi7C1EjMibgyUpgFgTbYERVjysWLYik8CXGUzhwTVNmpEOwvTxc7kk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722510344; c=relaxed/simple; bh=5/4H8T14qF00xhOPgedV8y88tKFC4uefNxD2j1/X0fM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l/EvsaWVRzBvtNLM8ubYnckXkSLJZGEWamugAWSeJq5dE9PTxfbT8mRbnv/u0TGFqZXG3Bnr2QxyS21kbA0SDltmfdRUPk6UT8jygMxYHB4MgID3D1SeoPq8XHhj5uMYfHSP7Pd5azIh2DjaQVbmHJ+TqTrgdeQpWy+82P6cKJU= 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=Uk2aKgPb; arc=none smtp.client-ip=209.85.214.178 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="Uk2aKgPb" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1fc611a0f8cso50175025ad.2 for ; Thu, 01 Aug 2024 04:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722510342; x=1723115142; 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=k0CXY29J8zlZlC6l5RNBhTYRF6wdOz523B8Qj+iJiKc=; b=Uk2aKgPbsUhs33ot/N/kDpfMc4ryQbrdh8v4oXnkI1cyRznrAOtpirdIGEbUe5rryR 9HLFhdVvgc9ClfByoLR9REKAETqUcdyHNJKv243XiqFa0ScxmwwucW/p97kgPjyknC00 1/8bxnlNGkMAH25QfEMbSoUoBAJX9oN/wXo7uXdq06c9AvTi2Kg41jQs4t6wGx3BAfnB /ZFXoNgMxd8i8HEe5QzqvO33Ow0AwOaP61iEO+8jK27gFvP2p6OzZxT1VX3jDMCvr5BA pCAHXhRtL5uH90VaOM5sqFcxOkTQ7HJGAS/pZb1s5u/Oql/alSkjDtxKnpZ1qUv9kqBO gLBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722510342; x=1723115142; 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=k0CXY29J8zlZlC6l5RNBhTYRF6wdOz523B8Qj+iJiKc=; b=fTeR8HrgEXxlUbXaFlJc1fxYpyll1w/sxp3fW7DhfFeejd1XmgwGdhO/94tm+b4VM8 +eElDcy9J0QqMykFAN50iBxXQiKOZjQQilHt6N0MwLxm2CzuaoVko9OJhSwS7faBk2xa Ff00+t+vQwJ3KXB0jGiHnAuaoTKY5OXnAgQgu5We0XFGN/ov9i1KuUXzURPx8orn3T0c +NXXB+j7JAcq+eX5bYFQAWDyKAvtIbKmM2xe36wdEGPSHRzUu3HGO55ZSC/RV4QL7rcC AfcVaOcjCsfODMUpbZPqVtLsAXPkBn3FA6Gi5DbIfvBl33X50U1+iuSMgfG5x1TSUp1+ 2U6Q== X-Gm-Message-State: AOJu0YybX26d4GqZ39564XQfOYl9ItJwbtIx0pCBfpZ6zu2P3rugoN4Z ZtH+ZbyL+OpkT9NahZGgeDiBpDTNPAzGKm3h2NKbkhj6Ci3mUkikP7I1Rg== X-Google-Smtp-Source: AGHT+IFpIPipJPTYURs7rHvhEDTvbw/EMSHQYrRUH4aS1CX0Rv03fS+fZ1jzPwaImltFrx8y6954pQ== X-Received: by 2002:a17:903:32d1:b0:1fd:aa8d:ace5 with SMTP id d9443c01a7336-1ff4ce8b6f1mr27099305ad.23.1722510341638; Thu, 01 Aug 2024 04:05:41 -0700 (PDT) Received: from Ubuntu.. ([106.194.76.199]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fed7edd90dsm136663985ad.161.2024.08.01.04.05.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 04:05:41 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v7 7/7] t-reftable-pq: add tests for merged_iter_pqueue_top() Date: Thu, 1 Aug 2024 16:29:48 +0530 Message-ID: <20240801110453.5087-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240801110453.5087-1-chandrapratap3519@gmail.com> References: <20240725093855.4201-1-chandrapratap3519@gmail.com> <20240801110453.5087-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 | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c index 70ff89507d..039bd0f1f9 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); @@ -81,9 +88,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) @@ -94,10 +103,50 @@ 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(); }