[tarantool-patches] [PATCH v1 1/4] box: introduce new helpers in column_mask.h

Kirill Shcherbatov kshcherbatov at tarantool.org
Fri Feb 8 15:52:25 MSK 2019


Refactored column_mask.h definitions: introduced a new routine
column_mask_is_overflowed, column_mask_is_set and macro
COLUMN_MASK_BIT, COLUMN_MASK_SIZE.
We need this helpers in further refactoring.

Needed for #3571
---
 src/box/column_mask.h | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/src/box/column_mask.h b/src/box/column_mask.h
index d71911d46..6e9c0f81a 100644
--- a/src/box/column_mask.h
+++ b/src/box/column_mask.h
@@ -50,7 +50,9 @@
  * in such case we set not one bit, but a range of bits.
  */
 
-#define COLUMN_MASK_FULL UINT64_MAX
+#define COLUMN_MASK_FULL	UINT64_MAX
+#define COLUMN_MASK_BIT(n)	(((uint64_t)1)<<(n))
+#define COLUMN_MASK_SIZE	((int)(sizeof(uint64_t)*8))
 
 /**
  * Set a bit in the bitmask corresponding to a
@@ -61,14 +63,14 @@
 static inline void
 column_mask_set_fieldno(uint64_t *column_mask, uint32_t fieldno)
 {
-	if (fieldno >= 63)
+	if (fieldno >= COLUMN_MASK_SIZE - 1)
 		/*
 		 * @sa column_mask key_def declaration for
 		 * details.
 		 */
-		*column_mask |= ((uint64_t) 1) << 63;
+		*column_mask |= COLUMN_MASK_BIT(COLUMN_MASK_SIZE - 1);
 	else
-		*column_mask |= ((uint64_t) 1) << fieldno;
+		*column_mask |= COLUMN_MASK_BIT(fieldno);
 }
 
 /**
@@ -80,7 +82,7 @@ column_mask_set_fieldno(uint64_t *column_mask, uint32_t fieldno)
 static inline void
 column_mask_set_range(uint64_t *column_mask, uint32_t first_fieldno_in_range)
 {
-	if (first_fieldno_in_range < 63) {
+	if (first_fieldno_in_range < COLUMN_MASK_SIZE - 1) {
 		/*
 		 * Set all bits by default via COLUMN_MASK_FULL
 		 * and then unset bits preceding the operation
@@ -90,10 +92,35 @@ column_mask_set_range(uint64_t *column_mask, uint32_t first_fieldno_in_range)
 		*column_mask |= COLUMN_MASK_FULL << first_fieldno_in_range;
 	} else {
 		/* A range outside "short" range. */
-		*column_mask |= ((uint64_t) 1) << 63;
+		*column_mask |= COLUMN_MASK_BIT(COLUMN_MASK_SIZE - 1);
 	}
 }
 
+/**
+ * Test if overflow flag set in mask.
+ * @param column_mask Mask to test.
+ * @retval true If mask overflowed, false otherwise.
+ */
+static inline bool
+column_mask_is_overflowed(uint64_t column_mask)
+{
+	return column_mask & COLUMN_MASK_BIT(COLUMN_MASK_SIZE - 1);
+}
+
+/**
+ * Test a bit in the bitmask corresponding to a column fieldno.
+ * @param column_mask Mask to test.
+ * @param fieldno Fieldno number to test (index base must be 0).
+ * @retval true If bit corresponding to a column fieldno.
+ * @retval false if bit is not set or fieldno > COLUMN_MASK_SIZE.
+ */
+static inline bool
+column_mask_fieldno_is_set(uint64_t column_mask, uint32_t fieldno)
+{
+	return fieldno < COLUMN_MASK_SIZE &&
+	       (column_mask & COLUMN_MASK_BIT(fieldno)) != 0;
+}
+
 /**
  * True if the update operation does not change the key.
  * @param key_mask Key mask.
-- 
2.20.1





More information about the Tarantool-patches mailing list