Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org,
	Vladimir Davydov <vdavydov.dev@gmail.com>
Subject: Re: [tarantool-patches] Re: [PATCH v1 3/4] box: introduce bitmap_majority_test routine
Date: Sat, 29 Dec 2018 16:57:00 +0300	[thread overview]
Message-ID: <25613688-02dd-7fa8-c200-1b3a9be20972@tarantool.org> (raw)
In-Reply-To: <20181229131953.z6mkaif2p5zwou2g@esperanza>

Hi! Ok... Also changed the only place in following patch.

===============================
A new bitmap_size routine returns size of bitmap allocation
aligned by sizeof(unsigned long) words by count of bits to work
with. Memory chunk must be aligned as bit_set/bit_clear
functions use unsigned long words to setup bits.
We need bitmap_size to make an allocation for format:fields to
test compatibility of required fields bitmap with another one
that is built for parsed tuple on tuple_init_field_map.

Needed for #1012
---
 src/lib/bit/bit.h        | 13 +++++++++++++
 test/unit/CMakeLists.txt |  2 +-
 test/unit/bit.c          | 27 +++++++++++++++++++++++++++
 test/unit/bit.result     |  8 ++++++++
 4 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/src/lib/bit/bit.h b/src/lib/bit/bit.h
index 370a0cc5d..04be818b2 100644
--- a/src/lib/bit/bit.h
+++ b/src/lib/bit/bit.h
@@ -238,6 +238,19 @@ bit_clear(void *data, size_t pos)
 	return prev;
 }
 
+/**
+ * Return sizeof(unsigned long)-words aligned size of bitmap by
+ * bit_count - count of bits to set. Size must be aligned, as
+ * bit_sit/bit_clear operations use unsigned long words to setup
+ * bit.
+ */
+static inline size_t
+bitmap_size(size_t bit_count)
+{
+	size_t word_count = DIV_ROUND_UP(bit_count, CHAR_BIT * sizeof(long));
+	return word_count * sizeof(long);
+}
+
 /**
  * @cond false
  * @brief Naive implementation of ctz.
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index 0025d3611..5b2f152e3 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -36,7 +36,7 @@ add_executable(rope.test rope.c)
 target_link_libraries(rope.test salad)
 add_executable(int96.test int96.cc)
 add_executable(bit.test bit.c bit.c)
-target_link_libraries(bit.test bit)
+target_link_libraries(bit.test bit unit)
 add_executable(bitset_basic.test bitset_basic.c)
 target_link_libraries(bitset_basic.test bitset)
 add_executable(bitset_iterator.test bitset_iterator.c)
diff --git a/test/unit/bit.c b/test/unit/bit.c
index beb89a7e4..67a7ccd63 100644
--- a/test/unit/bit.c
+++ b/test/unit/bit.c
@@ -206,6 +206,32 @@ test_bit_iter_empty(void)
 	footer();
 }
 
+static void
+test_bitmap(void)
+{
+	header();
+	plan(5);
+
+	size_t rc = bitmap_size(0);
+	is(rc, 0, "empty bitmap: have %zu expected %d", rc, 0);
+	rc = bitmap_size(1);
+	is(rc, sizeof(unsigned long), "1-item bitmap: have %zu expected %lu",
+	   rc, sizeof(unsigned long));
+	rc = bitmap_size(4);
+	is(rc, sizeof(unsigned long), "4-items bitmap: have %zu expected %lu",
+	   rc, sizeof(unsigned long));
+	rc = bitmap_size(CHAR_BIT * sizeof(unsigned long));
+	is(rc, sizeof(unsigned long), "%lu-items bitmap: have %zu expected %lu",
+	   CHAR_BIT * sizeof(unsigned long), rc, sizeof(unsigned long));
+	rc = bitmap_size(CHAR_BIT * sizeof(unsigned long) + 1);
+	is(rc, 2 * sizeof(unsigned long),
+	   "%lu-items bitmap: have %zu expected %lu",
+	   CHAR_BIT * sizeof(unsigned long) + 1, rc, 2 * sizeof(unsigned long));
+
+	check_plan();
+	footer();
+}
+
 int
 main(void)
 {
@@ -216,4 +242,5 @@ main(void)
 	test_index();
 	test_bit_iter();
 	test_bit_iter_empty();
+	test_bitmap();
 }
diff --git a/test/unit/bit.result b/test/unit/bit.result
index e2c5601f3..d99cfbf01 100644
--- a/test/unit/bit.result
+++ b/test/unit/bit.result
@@ -891,3 +891,11 @@ Clear: 0, 1, 2, 4, 5, 6, 7, 8, 10, 12, 13, 14, 15, 19, 20, 21, 23, 26, 28, 30, 3
 	*** test_bit_iter: done ***
 	*** test_bit_iter_empty ***
 	*** test_bit_iter_empty: done ***
+	*** test_bitmap ***
+1..5
+ok 1 - empty bitmap: have 0 expected 0
+ok 2 - 1-item bitmap: have 8 expected 8
+ok 3 - 4-items bitmap: have 8 expected 8
+ok 4 - 64-items bitmap: have 8 expected 8
+ok 5 - 65-items bitmap: have 16 expected 16
+	*** test_bitmap: done ***
-- 
2.19.2

  reply	other threads:[~2018-12-29 13:57 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-27 11:15 [PATCH v1 0/4] box: JSON preparatory patchset Kirill Shcherbatov
2018-12-27 11:15 ` [PATCH v1 1/4] lib: introduce json_tree_snprint_path Kirill Shcherbatov
2018-12-27 18:51   ` Vladimir Davydov
2018-12-27 11:15 ` [PATCH v1 2/4] lib: introduce json_token_is_leaf helper Kirill Shcherbatov
2018-12-27 18:52   ` Vladimir Davydov
2018-12-27 11:15 ` [PATCH v1 3/4] box: introduce bitmap_majority_test routine Kirill Shcherbatov
2018-12-27 18:59   ` Vladimir Davydov
2018-12-29 12:58     ` [tarantool-patches] " Kirill Shcherbatov
2018-12-29 13:19       ` Vladimir Davydov
2018-12-29 13:57         ` Kirill Shcherbatov [this message]
2018-12-29 16:16           ` Vladimir Davydov
2018-12-27 11:15 ` [PATCH v1 4/4] box: refactor tuple_init_field_map to use bitmap Kirill Shcherbatov
2018-12-27 11:48   ` [tarantool-patches] " Konstantin Osipov
2018-12-27 19:12   ` Vladimir Davydov
2018-12-29 12:58     ` [tarantool-patches] " Kirill Shcherbatov
2018-12-29 13:22       ` Vladimir Davydov
2018-12-29 16:25       ` Vladimir Davydov
2018-12-27 19:13 ` [PATCH v1 0/4] box: JSON preparatory patchset Vladimir Davydov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25613688-02dd-7fa8-c200-1b3a9be20972@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [tarantool-patches] Re: [PATCH v1 3/4] box: introduce bitmap_majority_test routine' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox