Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Subject: Re: [tarantool-patches] Re: [PATCH v1 1/1] lib/bitset: rename bitset structs
Date: Tue, 3 Jul 2018 16:24:36 +0300	[thread overview]
Message-ID: <da388eae-f592-006f-0cdd-72fbbc8e1039@tarantool.org> (raw)
In-Reply-To: <20180703125241.nqmufiqi56s4dqnv@esperanza>

> I don't think you should rename any structures or functions defined in
> memtx_bitset.c - they don't conflict and they are not related to struct
> bitset.

Changes in memtx_bitset.{c, h} with my patch now.

========================================

diff --git a/src/box/memtx_bitset.c b/src/box/memtx_bitset.c
index 9216ed8..75406f9 100644
--- a/src/box/memtx_bitset.c
+++ b/src/box/memtx_bitset.c
@@ -154,7 +154,7 @@ value_to_tuple(size_t value)
 
 struct bitset_index_iterator {
 	struct iterator base; /* Must be the first member. */
-	struct bitset_iterator bitset_it;
+	struct tt_bitset_iterator bitset_it;
 #ifndef OLD_GOOD_BITSET
 	struct memtx_bitset_index *bitset_index;
 #endif /* #ifndef OLD_GOOD_BITSET */
@@ -174,7 +174,7 @@ bitset_index_iterator_free(struct iterator *iterator)
 	assert(iterator->free == bitset_index_iterator_free);
 	struct bitset_index_iterator *it = bitset_index_iterator(iterator);
 
-	bitset_iterator_destroy(&it->bitset_it);
+	tt_bitset_iterator_destroy(&it->bitset_it);
 	mempool_free(it->pool, it);
 }
 
@@ -184,7 +184,7 @@ bitset_index_iterator_next(struct iterator *iterator, struct tuple **ret)
 	assert(iterator->free == bitset_index_iterator_free);
 	struct bitset_index_iterator *it = bitset_index_iterator(iterator);
 
-	size_t value = bitset_iterator_next(&it->bitset_it);
+	size_t value = tt_bitset_iterator_next(&it->bitset_it);
 	if (value == SIZE_MAX) {
 		*ret = NULL;
 		return 0;
@@ -202,7 +202,7 @@ static void
 memtx_bitset_index_destroy(struct index *base)
 {
 	struct memtx_bitset_index *index = (struct memtx_bitset_index *)base;
-	bitset_index_destroy(&index->index);
+	tt_bitset_index_destroy(&index->index);
 #ifndef OLD_GOOD_BITSET
 	mh_bitset_index_delete(index->tuple_to_id);
 	matras_destroy(index->id_to_tuple);
@@ -215,7 +215,7 @@ static ssize_t
 memtx_bitset_index_size(struct index *base)
 {
 	struct memtx_bitset_index *index = (struct memtx_bitset_index *)base;
-	return bitset_index_size(&index->index);
+	return tt_bitset_index_size(&index->index);
 }
 
 static ssize_t
@@ -223,7 +223,7 @@ memtx_bitset_index_bsize(struct index *base)
 {
 	struct memtx_bitset_index *index = (struct memtx_bitset_index *)base;
 	size_t result = 0;
-	result += bitset_index_bsize(&index->index);
+	result += tt_bitset_index_bsize(&index->index);
 #ifndef OLD_GOOD_BITSET
 	result += matras_extent_count(index->id_to_tuple) * MEMTX_EXTENT_SIZE;
 	result += mh_bitset_index_memsize(index->tuple_to_id);
@@ -270,11 +270,12 @@ memtx_bitset_index_replace(struct index *base, struct tuple *old_tuple,
 #else /* #ifndef OLD_GOOD_BITSET */
 		size_t value = tuple_to_value(old_tuple);
 #endif /* #ifndef OLD_GOOD_BITSET */
-		if (bitset_index_contains_value(&index->index, (size_t)value)) {
+		if (tt_bitset_index_contains_value(&index->index,
+						   (size_t) value)) {
 			*result = old_tuple;
 
 			assert(old_tuple != new_tuple);
-			bitset_index_remove_value(&index->index, value);
+			tt_bitset_index_remove_value(&index->index, value);
 #ifndef OLD_GOOD_BITSET
 			memtx_bitset_index_unregister_tuple(index, old_tuple);
 #endif /* #ifndef OLD_GOOD_BITSET */
@@ -293,7 +294,8 @@ memtx_bitset_index_replace(struct index *base, struct tuple *old_tuple,
 #else /* #ifndef OLD_GOOD_BITSET */
 		uint32_t value = tuple_to_value(new_tuple);
 #endif /* #ifndef OLD_GOOD_BITSET */
-		if (bitset_index_insert(&index->index, key, key_len, value) < 0) {
+		if (tt_bitset_index_insert(&index->index, key, key_len,
+					   value) < 0) {
 #ifndef OLD_GOOD_BITSET
 			memtx_bitset_index_unregister_tuple(index, new_tuple);
 #endif /* #ifndef OLD_GOOD_BITSET */
@@ -327,7 +329,7 @@ memtx_bitset_index_create_iterator(struct index *base, enum iterator_type type,
 	it->base.next = bitset_index_iterator_next;
 	it->base.free = bitset_index_iterator_free;
 
-	bitset_iterator_create(&it->bitset_it, realloc);
+	tt_bitset_iterator_create(&it->bitset_it, realloc);
 #ifndef OLD_GOOD_BITSET
 	it->bitset_index = index;
 #endif
@@ -339,29 +341,29 @@ memtx_bitset_index_create_iterator(struct index *base, enum iterator_type type,
 		bitset_key = make_key(key, &bitset_key_size);
 	}
 
-	struct bitset_expr expr;
-	bitset_expr_create(&expr, realloc);
+	struct tt_bitset_expr expr;
+	tt_bitset_expr_create(&expr, realloc);
 
 	int rc = 0;
 	switch (type) {
 	case ITER_ALL:
-		rc = bitset_index_expr_all(&expr);
+		rc = tt_bitset_index_expr_all(&expr);
 		break;
 	case ITER_EQ:
-		rc = bitset_index_expr_equals(&expr, bitset_key,
-					      bitset_key_size);
+		rc = tt_bitset_index_expr_equals(&expr, bitset_key,
+						 bitset_key_size);
 		break;
 	case ITER_BITS_ALL_SET:
-		rc = bitset_index_expr_all_set(&expr, bitset_key,
-					       bitset_key_size);
+		rc = tt_bitset_index_expr_all_set(&expr, bitset_key,
+						  bitset_key_size);
 		break;
 	case ITER_BITS_ALL_NOT_SET:
-		rc = bitset_index_expr_all_not_set(&expr, bitset_key,
-						   bitset_key_size);
+		rc = tt_bitset_index_expr_all_not_set(&expr, bitset_key,
+						      bitset_key_size);
 		break;
 	case ITER_BITS_ANY_SET:
-		rc = bitset_index_expr_any_set(&expr, bitset_key,
-					       bitset_key_size);
+		rc = tt_bitset_index_expr_any_set(&expr, bitset_key,
+						  bitset_key_size);
 		break;
 	default:
 		diag_set(UnsupportedIndexFeature, base->def,
@@ -375,17 +377,17 @@ memtx_bitset_index_create_iterator(struct index *base, enum iterator_type type,
 		goto fail;
 	}
 
-	if (bitset_index_init_iterator(&index->index, &it->bitset_it,
-				       &expr) != 0) {
+	if (tt_bitset_index_init_iterator(&index->index, &it->bitset_it,
+					  &expr) != 0) {
 		diag_set(OutOfMemory, 0, "memtx_bitset_index",
 			 "iterator state");
 		goto fail;
 	}
 
-	bitset_expr_destroy(&expr);
+	tt_bitset_expr_destroy(&expr);
 	return (struct iterator *)it;
 fail:
-	bitset_expr_destroy(&expr);
+	tt_bitset_expr_destroy(&expr);
 	mempool_free(&memtx->bitset_iterator_pool, it);
 	return NULL;
 }
@@ -397,7 +399,7 @@ memtx_bitset_index_count(struct index *base, enum iterator_type type,
 	struct memtx_bitset_index *index = (struct memtx_bitset_index *)base;
 
 	if (type == ITER_ALL)
-		return bitset_index_size(&index->index);
+		return tt_bitset_index_size(&index->index);
 
 	assert(part_count == 1); /* checked by key_validate() */
 	uint32_t bitset_key_size = 0;
@@ -417,7 +419,7 @@ memtx_bitset_index_count(struct index *base, enum iterator_type type,
 		 * bitset_index_count().
 		 */
 		if (bit_iterator_next(&bit_it) == SIZE_MAX)
-			return bitset_index_count(&index->index, bit);
+			return tt_bitset_index_count(&index->index, bit);
 	} else if (type == ITER_BITS_ALL_SET) {
 		/**
 		 * Optimization: for an empty key return 0.
@@ -431,7 +433,7 @@ memtx_bitset_index_count(struct index *base, enum iterator_type type,
 		 * bitset_index_count().
 		 */
 		if (bit_iterator_next(&bit_it) == SIZE_MAX)
-			return bitset_index_count(&index->index, bit);
+			return tt_bitset_index_count(&index->index, bit);
 	} else if (type == ITER_BITS_ALL_NOT_SET) {
 		/**
 		 * Optimization: for an empty key return the number of items
@@ -440,14 +442,14 @@ memtx_bitset_index_count(struct index *base, enum iterator_type type,
 		bit_iterator_init(&bit_it, bitset_key, bitset_key_size, true);
 		bit = bit_iterator_next(&bit_it);
 		if (bit == SIZE_MAX)
-			return bitset_index_size(&index->index);
+			return tt_bitset_index_size(&index->index);
 		/**
 		 * Optimiation: for the single bit key use
 		 * bitset_index_count().
 		 */
 		if (bit_iterator_next(&bit_it) == SIZE_MAX)
-			return bitset_index_size(&index->index) -
-				bitset_index_count(&index->index, bit);
+			return tt_bitset_index_size(&index->index) -
+				tt_bitset_index_count(&index->index, bit);
 	}
 
 	/* Call generic method */
@@ -515,6 +517,6 @@ memtx_bitset_index_new(struct memtx_engine *memtx, struct index_def *def)
 		panic("failed to allocate memtx bitset index");
 #endif /* #ifndef OLD_GOOD_BITSET */
 
-	bitset_index_create(&index->index, realloc);
+	tt_bitset_index_create(&index->index, realloc);
 	return index;
 }
diff --git a/src/box/memtx_bitset.h b/src/box/memtx_bitset.h
index 0b8f48a..62971dd 100644
--- a/src/box/memtx_bitset.h
+++ b/src/box/memtx_bitset.h
@@ -51,7 +51,7 @@ struct mh_bitset_index_t;
 
 struct memtx_bitset_index {
 	struct index base;
-	struct bitset_index index;
+	struct tt_bitset_index index;
 #ifndef OLD_GOOD_BITSET
 	struct matras *id_to_tuple;
 	struct mh_bitset_index_t *tuple_to_id;
diff --git a/src/lib/bitset/bitset.c b/src/lib/bitset/bitset.c
index ae2a033..f785adf 100644
--- a/src/lib/bitset/bitset.c
+++ b/src/lib/bitset/bitset.c
@@ -37,73 +37,78 @@
 #include <assert.h>
 
 void
-bitset_create(struct bitset *bitset, void *(*realloc)(void *ptr, size_t size))
+tt_bitset_create(struct tt_bitset *bitset,
+		 void *(*realloc)(void *ptr, size_t size))
 {
 	memset(bitset, 0, sizeof(*bitset));
 	bitset->realloc = realloc;
 
 	/* Initialize pages tree */
-	bitset_pages_new(&bitset->pages);
+	tt_bitset_pages_new(&bitset->pages);
 }
 
-static struct bitset_page *
-bitset_destroy_iter_cb(bitset_pages_t *t, struct bitset_page *page, void *arg)
+static struct tt_bitset_page *
+tt_bitset_destroy_iter_cb(tt_bitset_pages_t *t, struct tt_bitset_page *page,
+			  void *arg)
 {
 	(void) t;
-	struct bitset *bitset = (struct bitset *) arg;
-	bitset_page_destroy(page);
+	struct tt_bitset *bitset = (struct tt_bitset *) arg;
+	tt_bitset_page_destroy(page);
 	bitset->realloc(page, 0);
 	return NULL;
 }
 
 void
-bitset_destroy(struct bitset *bitset)
+tt_bitset_destroy(struct tt_bitset *bitset)
 {
-	bitset_pages_iter(&bitset->pages, NULL, bitset_destroy_iter_cb, bitset);
+	tt_bitset_pages_iter(&bitset->pages, NULL, tt_bitset_destroy_iter_cb,
+			     bitset);
 	memset(&bitset->pages, 0, sizeof(bitset->pages));
 }
 
 bool
-bitset_test(struct bitset *bitset, size_t pos)
+tt_bitset_test(struct tt_bitset *bitset, size_t pos)
 {
-	struct bitset_page key;
-	key.first_pos = bitset_page_first_pos(pos);
+	struct tt_bitset_page key;
+	key.first_pos = tt_bitset_page_first_pos(pos);
 
 	/* Find a page in pages tree */
-	struct bitset_page *page = bitset_pages_search(&bitset->pages, &key);
+	struct tt_bitset_page *page =
+		tt_bitset_pages_search(&bitset->pages, &key);
 	if (page == NULL)
 		return false;
 
 	assert(page->first_pos <= pos && pos < page->first_pos +
 	       BITSET_PAGE_DATA_SIZE * CHAR_BIT);
-	return bit_test(bitset_page_data(page), pos - page->first_pos);
+	return bit_test(tt_bitset_page_data(page), pos - page->first_pos);
 }
 
 int
-bitset_set(struct bitset *bitset, size_t pos)
+tt_bitset_set(struct tt_bitset *bitset, size_t pos)
 {
-	struct bitset_page key;
-	key.first_pos = bitset_page_first_pos(pos);
+	struct tt_bitset_page key;
+	key.first_pos = tt_bitset_page_first_pos(pos);
 
 	/* Find a page in pages tree */
-	struct bitset_page *page = bitset_pages_search(&bitset->pages, &key);
+	struct tt_bitset_page *page =
+		tt_bitset_pages_search(&bitset->pages, &key);
 	if (page == NULL) {
 		/* Allocate a new page */
-		size_t size = bitset_page_alloc_size(bitset->realloc);
+		size_t size = tt_bitset_page_alloc_size(bitset->realloc);
 		page = bitset->realloc(NULL, size);
 		if (page == NULL)
 			return -1;
 
-		bitset_page_create(page);
+		tt_bitset_page_create(page);
 		page->first_pos = key.first_pos;
 
 		/* Insert the page into pages tree */
-		bitset_pages_insert(&bitset->pages, page);
+		tt_bitset_pages_insert(&bitset->pages, page);
 	}
 
 	assert(page->first_pos <= pos && pos < page->first_pos +
 	       BITSET_PAGE_DATA_SIZE * CHAR_BIT);
-	bool prev = bit_set(bitset_page_data(page), pos - page->first_pos);
+	bool prev = bit_set(tt_bitset_page_data(page), pos - page->first_pos);
 	if (prev) {
 		/* Value has not changed */
 		return 1;
@@ -116,19 +121,20 @@ bitset_set(struct bitset *bitset, size_t pos)
 }
 
 int
-bitset_clear(struct bitset *bitset, size_t pos)
+tt_bitset_clear(struct tt_bitset *bitset, size_t pos)
 {
-	struct bitset_page key;
-	key.first_pos = bitset_page_first_pos(pos);
+	struct tt_bitset_page key;
+	key.first_pos = tt_bitset_page_first_pos(pos);
 
 	/* Find a page in the pages tree */
-	struct bitset_page *page = bitset_pages_search(&bitset->pages, &key);
+	struct tt_bitset_page *page =
+		tt_bitset_pages_search(&bitset->pages, &key);
 	if (page == NULL)
 		return 0;
 
 	assert(page->first_pos <= pos && pos < page->first_pos +
 	       BITSET_PAGE_DATA_SIZE * CHAR_BIT);
-	bool prev = bit_clear(bitset_page_data(page), pos - page->first_pos);
+	bool prev = bit_clear(tt_bitset_page_data(page), pos - page->first_pos);
 	if (!prev) {
 		return 0;
 	}
@@ -140,9 +146,9 @@ bitset_clear(struct bitset *bitset, size_t pos)
 
 	if (page->cardinality == 0) {
 		/* Remove the page from the pages tree */
-		bitset_pages_remove(&bitset->pages, page);
+		tt_bitset_pages_remove(&bitset->pages, page);
 		/* Free the page */
-		bitset_page_destroy(page);
+		tt_bitset_page_destroy(page);
 		bitset->realloc(page, 0);
 	}
 
@@ -150,33 +156,33 @@ bitset_clear(struct bitset *bitset, size_t pos)
 }
 
 extern inline size_t
-bitset_cardinality(const struct bitset *bitset);
+tt_bitset_cardinality(const struct tt_bitset *bitset);
 
 void
-bitset_info(struct bitset *bitset, struct bitset_info *info)
+tt_bitset_info(struct tt_bitset *bitset, struct tt_bitset_info *info)
 {
 	memset(info, 0, sizeof(*info));
 	info->page_data_size = BITSET_PAGE_DATA_SIZE;
-	info->page_total_size = bitset_page_alloc_size(bitset->realloc);
+	info->page_total_size = tt_bitset_page_alloc_size(bitset->realloc);
 	info->page_data_alignment = BITSET_PAGE_DATA_ALIGNMENT;
 
 	size_t cardinality_check = 0;
-	struct bitset_page *page = bitset_pages_first(&bitset->pages);
+	struct tt_bitset_page *page = tt_bitset_pages_first(&bitset->pages);
 	while (page != NULL) {
 		info->pages++;
 		cardinality_check += page->cardinality;
-		page = bitset_pages_next(&bitset->pages, page);
+		page = tt_bitset_pages_next(&bitset->pages, page);
 	}
 
-	assert(bitset_cardinality(bitset) == cardinality_check);
+	assert(tt_bitset_cardinality(bitset) == cardinality_check);
 }
 
 #if defined(DEBUG)
 void
-bitset_dump(struct bitset *bitset, int verbose, FILE *stream)
+tt_bitset_dump(struct tt_bitset *bitset, int verbose, FILE *stream)
 {
-	struct bitset_info info;
-	bitset_info(bitset, &info);
+	struct tt_bitset_info info;
+	tt_bitset_info(bitset, &info);
 
 	size_t PAGE_BIT = (info.page_data_size * CHAR_BIT);
 
@@ -225,8 +231,8 @@ bitset_dump(struct bitset *bitset, int verbose, FILE *stream)
 
 	fprintf(stream, "    " "pages = {\n");
 
-	for (struct bitset_page *page = bitset_pages_first(&bitset->pages);
-	     page != NULL; page = bitset_pages_next(&bitset->pages, page)) {
+	for (struct tt_bitset_page *page = tt_bitset_pages_first(&bitset->pages);
+	     page != NULL; page = tt_bitset_pages_next(&bitset->pages, page)) {
 
 		size_t page_last_pos = page->first_pos
 				+ BITSET_PAGE_DATA_SIZE * CHAR_BIT;

  reply	other threads:[~2018-07-03 13:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-03 10:29 Kirill Shcherbatov
2018-07-03 10:37 ` Vladimir Davydov
2018-07-03 12:24   ` [tarantool-patches] " Kirill Shcherbatov
2018-07-03 12:52     ` Vladimir Davydov
2018-07-03 13:24       ` Kirill Shcherbatov [this message]
2018-07-03 16:25         ` Vladimir Davydov
2018-07-03 17:10           ` Konstantin Osipov

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=da388eae-f592-006f-0cdd-72fbbc8e1039@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [tarantool-patches] Re: [PATCH v1 1/1] lib/bitset: rename bitset structs' \
    /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