From 2028842d8c858231ad1120a26f33c0aa0e19514b Mon Sep 17 00:00:00 2001 From: Roman Tsisyk <roman@tsisyk.com> Date: Thu, 13 Dec 2012 15:10:41 +0400 Subject: [PATCH] Remove index::findUnsafe method --- src/box/index.h | 4 ---- src/box/index.m | 25 ++++++++++++------------- src/box/tree.h | 2 ++ src/box/tree.m | 14 +++++++++++++- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/box/index.h b/src/box/index.h index f38c49c90d..89d9575d11 100644 --- a/src/box/index.h +++ b/src/box/index.h @@ -206,10 +206,6 @@ enum dup_replace_mode { :(enum iterator_type) type :(void *) key :(int) part_count; -/** - * Unsafe search methods that do not check key part count. - */ -- (struct tuple *) findUnsafe: (void *) key :(int) part_count; @end struct iterator { diff --git a/src/box/index.m b/src/box/index.m index 125e7700ce..8d02ed5238 100644 --- a/src/box/index.m +++ b/src/box/index.m @@ -37,7 +37,7 @@ #include "errinj.h" static struct index_traits index_traits = { - .allows_partial_key = true, + .allows_partial_key = false, }; static struct index_traits hash_index_traits = { @@ -216,12 +216,6 @@ replace_check_dup(struct tuple *old_tuple, } - (struct tuple *) findByKey: (void *) key :(int) part_count -{ - check_key_parts(key_def, part_count, false); - return [self findUnsafe: key :part_count]; -} - -- (struct tuple *) findUnsafe: (void *) key :(int) part_count { (void) key; (void) part_count; @@ -473,8 +467,11 @@ int32_tuple_to_node(struct tuple *tuple, struct key_def *key_def) return mh_size(int_hash); } -- (struct tuple *) findUnsafe: (void *) key :(int) part_count +- (struct tuple *) findByKey: (void *) key :(int) part_count { + assert(key_def->is_unique); + check_key_parts(key_def, part_count, false); + (void) part_count; struct tuple *ret = NULL; @@ -551,7 +548,6 @@ int32_tuple_to_node(struct tuple *tuple, struct key_def *key_def) - (void) initIterator: (struct iterator *) ptr: (enum iterator_type) type :(void *) key :(int) part_count { - (void) part_count; assert(ptr->free == hash_iterator_free); struct hash_i32_iterator *it = (struct hash_i32_iterator *) ptr; struct mh_i32ptr_node_t node; @@ -635,9 +631,10 @@ int64_tuple_to_node(struct tuple *tuple, struct key_def *key_def) return mh_size(int64_hash); } -- (struct tuple *) findUnsafe: (void *) key :(int) part_count +- (struct tuple *) findByKey: (void *) key :(int) part_count { - (void) part_count; + assert(key_def->is_unique); + check_key_parts(key_def, part_count, false); struct tuple *ret = NULL; struct mh_i64ptr_node_t node = int64_key_to_node(key); @@ -791,9 +788,11 @@ lstrptr_tuple_to_node(struct tuple *tuple, struct key_def *key_def) return mh_size(str_hash); } -- (struct tuple *) findUnsafe: (void *) key :(int) part_count +- (struct tuple *) findByKey: (void *) key :(int) part_count { - (void) part_count; + assert(key_def->is_unique); + check_key_parts(key_def, part_count, false); + struct tuple *ret = NULL; const struct mh_lstrptr_node_t node = { .key = key }; mh_int_t k = mh_lstrptr_get(str_hash, &node, NULL, NULL); diff --git a/src/box/tree.h b/src/box/tree.h index d6b4276fa9..6cacb96a19 100644 --- a/src/box/tree.h +++ b/src/box/tree.h @@ -45,6 +45,8 @@ typedef int (*tree_cmp_t)(const void *, const void *, void *); sptree_index tree; }; ++ (struct index_traits *) traits; + + (Index *) alloc: (struct key_def *) key_def :(struct space *) space; - (void) buildNext: (struct tuple *) tuple; diff --git a/src/box/tree.m b/src/box/tree.m index 069cf5636f..b437e987f1 100644 --- a/src/box/tree.m +++ b/src/box/tree.m @@ -35,6 +35,10 @@ /* {{{ Utilities. *************************************************/ +static struct index_traits tree_index_traits = { + .allows_partial_key = true, +}; + /** * Unsigned 32-bit int comparison. */ @@ -868,6 +872,11 @@ tree_iterator_gt(struct iterator *iterator) @implementation TreeIndex ++ (struct index_traits *) traits +{ + return &tree_index_traits; +} + + (Index *) alloc: (struct key_def *) key_def :(struct space *) space { enum tree_type type = find_tree_type(space, key_def); @@ -916,8 +925,11 @@ tree_iterator_gt(struct iterator *iterator) return [self unfold: node]; } -- (struct tuple *) findUnsafe: (void *) key : (int) part_count +- (struct tuple *) findByKey: (void *) key : (int) part_count { + assert(key_def->is_unique); + check_key_parts(key_def, part_count, false); + struct key_data *key_data = alloca(sizeof(struct key_data) + _SIZEOF_SPARSE_PARTS(part_count)); -- GitLab