[PATCH 04/12] key_def: move cmp and hash functions declarations to key_def.h

Vladimir Davydov vdavydov.dev at gmail.com
Thu Feb 21 13:26:04 MSK 2019


Most of them are already there - for instance see see tuple_extract_key
and tuple_compare. Let's move the rest there too for consistency.
---
 src/box/key_def.c       |  1 +
 src/box/key_def.h       | 64 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/box/memtx_hash.c    |  1 -
 src/box/sql/analyze.c   |  1 -
 src/box/tuple_bloom.c   |  1 -
 src/box/tuple_compare.h | 14 -----------
 src/box/tuple_hash.cc   |  1 +
 src/box/tuple_hash.h    | 58 ++------------------------------------------
 src/box/vy_run.c        |  1 -
 9 files changed, 68 insertions(+), 74 deletions(-)

diff --git a/src/box/key_def.c b/src/box/key_def.c
index 75e3a0be..92b2586d 100644
--- a/src/box/key_def.c
+++ b/src/box/key_def.c
@@ -30,6 +30,7 @@
  */
 #include "json/json.h"
 #include "key_def.h"
+#include "tuple_format.h"
 #include "tuple_compare.h"
 #include "tuple_extract_key.h"
 #include "tuple_hash.h"
diff --git a/src/box/key_def.h b/src/box/key_def.h
index bf3e63b6..788a200d 100644
--- a/src/box/key_def.h
+++ b/src/box/key_def.h
@@ -503,6 +503,17 @@ tuple_extract_key_raw(const char *data, const char *data_end,
 }
 
 /**
+ * Return the length of the longest common prefix of two tuples.
+ * @param tuple_a first tuple
+ * @param tuple_b second tuple
+ * @param key_def key defintion
+ * @return number of key parts the two tuples have in common
+ */
+uint32_t
+tuple_common_key_parts(const struct tuple *tuple_a, const struct tuple *tuple_b,
+		       struct key_def *key_def);
+
+/**
  * Compare keys using the key definition.
  * @param key_a key parts with MessagePack array header
  * @param part_count_a the number of parts in the key_a
@@ -551,6 +562,59 @@ tuple_compare_with_key(const struct tuple *tuple, const char *key,
 	return key_def->tuple_compare_with_key(tuple, key, part_count, key_def);
 }
 
+/**
+ * Compute hash of a tuple field.
+ * @param ph1 - pointer to running hash
+ * @param pcarry - pointer to carry
+ * @param field - pointer to field data
+ * @param coll - collation to use for hashing strings or NULL
+ * @return size of processed data
+ *
+ * This function updates @ph1 and @pcarry and advances @field
+ * by the number of processed bytes.
+ */
+uint32_t
+tuple_hash_field(uint32_t *ph1, uint32_t *pcarry, const char **field,
+		 struct coll *coll);
+
+/**
+ * Compute hash of a key part.
+ * @param ph1 - pointer to running hash
+ * @param pcarry - pointer to carry
+ * @param tuple - tuple to hash
+ * @param part - key part
+ * @return size of processed data
+ *
+ * This function updates @ph1 and @pcarry.
+ */
+uint32_t
+tuple_hash_key_part(uint32_t *ph1, uint32_t *pcarry, const struct tuple *tuple,
+		    struct key_part *part);
+
+/**
+ * Calculates a common hash value for a tuple
+ * @param tuple - a tuple
+ * @param key_def - key_def for field description
+ * @return - hash value
+ */
+static inline uint32_t
+tuple_hash(const struct tuple *tuple, struct key_def *key_def)
+{
+	return key_def->tuple_hash(tuple, key_def);
+}
+
+/**
+ * Calculate a common hash value for a key
+ * @param key - full key (msgpack fields w/o array marker)
+ * @param key_def - key_def for field description
+ * @return - hash value
+ */
+static inline uint32_t
+key_hash(const char *key, struct key_def *key_def)
+{
+	return key_def->key_hash(key, key_def);
+}
+
 #if defined(__cplusplus)
 } /* extern "C" */
 #endif /* defined(__cplusplus) */
diff --git a/src/box/memtx_hash.c b/src/box/memtx_hash.c
index eae07e8a..511d0e51 100644
--- a/src/box/memtx_hash.c
+++ b/src/box/memtx_hash.c
@@ -32,7 +32,6 @@
 #include "say.h"
 #include "fiber.h"
 #include "tuple.h"
-#include "tuple_hash.h"
 #include "memtx_engine.h"
 #include "space.h"
 #include "schema.h" /* space_cache_find() */
diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c
index e0f2724a..8c83288e 100644
--- a/src/box/sql/analyze.c
+++ b/src/box/sql/analyze.c
@@ -108,7 +108,6 @@
 #include "box/box.h"
 #include "box/index.h"
 #include "box/key_def.h"
-#include "box/tuple_compare.h"
 #include "box/schema.h"
 #include "third_party/qsort_arg.h"
 
diff --git a/src/box/tuple_bloom.c b/src/box/tuple_bloom.c
index 0ea552aa..cf887c7b 100644
--- a/src/box/tuple_bloom.c
+++ b/src/box/tuple_bloom.c
@@ -41,7 +41,6 @@
 #include "errcode.h"
 #include "key_def.h"
 #include "tuple.h"
-#include "tuple_hash.h"
 #include "salad/bloom.h"
 #include "trivia/util.h"
 #include "third_party/PMurHash.h"
diff --git a/src/box/tuple_compare.h b/src/box/tuple_compare.h
index baecbafe..2193335f 100644
--- a/src/box/tuple_compare.h
+++ b/src/box/tuple_compare.h
@@ -30,27 +30,13 @@
  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#include <stdint.h>
-
 #if defined(__cplusplus)
 extern "C" {
 #endif /* defined(__cplusplus) */
 
-struct tuple;
 struct key_def;
 
 /**
- * Return the length of the longest common prefix of two tuples.
- * @param tuple_a first tuple
- * @param tuple_b second tuple
- * @param key_def key defintion
- * @return number of key parts the two tuples have in common
- */
-uint32_t
-tuple_common_key_parts(const struct tuple *tuple_a, const struct tuple *tuple_b,
-		       struct key_def *key_def);
-
-/**
  * Initialize comparator functions for the key_def.
  * @param key_def key definition
  */
diff --git a/src/box/tuple_hash.cc b/src/box/tuple_hash.cc
index 5bfd40cf..82d145ab 100644
--- a/src/box/tuple_hash.cc
+++ b/src/box/tuple_hash.cc
@@ -30,6 +30,7 @@
  */
 
 #include "tuple_hash.h"
+#include "tuple.h"
 #include "third_party/PMurHash.h"
 #include "coll.h"
 #include <math.h>
diff --git a/src/box/tuple_hash.h b/src/box/tuple_hash.h
index abc961bf..431613b5 100644
--- a/src/box/tuple_hash.h
+++ b/src/box/tuple_hash.h
@@ -30,13 +30,12 @@
  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#include "key_def.h"
-#include "tuple.h"
-
 #if defined(__cplusplus)
 extern "C" {
 #endif /* defined(__cplusplus) */
 
+struct key_def;
+
 /**
  * Initialize tuple_hash() and key_hash() function for the key_def
  * @param key_def key definition
@@ -44,59 +43,6 @@ extern "C" {
 void
 tuple_hash_func_set(struct key_def *def);
 
-/**
- * Compute hash of a tuple field.
- * @param ph1 - pointer to running hash
- * @param pcarry - pointer to carry
- * @param field - pointer to field data
- * @param coll - collation to use for hashing strings or NULL
- * @return size of processed data
- *
- * This function updates @ph1 and @pcarry and advances @field
- * by the number of processed bytes.
- */
-uint32_t
-tuple_hash_field(uint32_t *ph1, uint32_t *pcarry, const char **field,
-		 struct coll *coll);
-
-/**
- * Compute hash of a key part.
- * @param ph1 - pointer to running hash
- * @param pcarry - pointer to carry
- * @param tuple - tuple to hash
- * @param part - key part
- * @return size of processed data
- *
- * This function updates @ph1 and @pcarry.
- */
-uint32_t
-tuple_hash_key_part(uint32_t *ph1, uint32_t *pcarry, const struct tuple *tuple,
-		    struct key_part *part);
-
-/**
- * Calculates a common hash value for a tuple
- * @param tuple - a tuple
- * @param key_def - key_def for field description
- * @return - hash value
- */
-static inline uint32_t
-tuple_hash(const struct tuple *tuple, struct key_def *key_def)
-{
-	return key_def->tuple_hash(tuple, key_def);
-}
-
-/**
- * Calculate a common hash value for a key
- * @param key - full key (msgpack fields w/o array marker)
- * @param key_def - key_def for field description
- * @return - hash value
- */
-static inline uint32_t
-key_hash(const char *key, struct key_def *key_def)
-{
-	return key_def->key_hash(key, key_def);
-}
-
 #if defined(__cplusplus)
 } /* extern "C" */
 #endif /* defined(__cplusplus) */
diff --git a/src/box/vy_run.c b/src/box/vy_run.c
index 7b15603e..14975bdf 100644
--- a/src/box/vy_run.c
+++ b/src/box/vy_run.c
@@ -41,7 +41,6 @@
 
 #include "replication.h"
 #include "tuple_bloom.h"
-#include "tuple_compare.h"
 #include "xlog.h"
 #include "xrow.h"
 #include "vy_history.h"
-- 
2.11.0




More information about the Tarantool-patches mailing list