From 9e34855bf287b8c31865797dbba707c0cd845530 Mon Sep 17 00:00:00 2001 From: Roman Tsisyk <roman@tsisyk.com> Date: Wed, 19 Dec 2012 16:17:42 +0400 Subject: [PATCH] Revert "Remove index::findByTuple method" This reverts commit cf093c0b7c25891e2bb2df415e1da7899276a6f2. Conflicts: src/box/index.h src/box/index.m --- src/box/hash_index.m | 11 +++++++++++ src/box/index.h | 1 + src/box/index.m | 7 +++++++ src/box/tree_index.m | 17 +++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/src/box/hash_index.m b/src/box/hash_index.m index 7136c120a6..69710651a5 100644 --- a/src/box/hash_index.m +++ b/src/box/hash_index.m @@ -242,6 +242,17 @@ hash_iterator_lstr_eq(struct iterator *it) return NULL; } +- (struct tuple *) findByTuple: (struct tuple *) tuple +{ + assert(key_def->is_unique); + if (tuple->field_count < key_def->max_fieldno) + tnt_raise(IllegalParams, :"tuple must have all indexed fields"); + + /* Hash index currently is always single-part. */ + void *field = tuple_field(tuple, key_def->parts[0].fieldno); + return [self findByKey :field :1]; +} + @end /* }}} */ diff --git a/src/box/index.h b/src/box/index.h index e83876e755..7d394fb1b2 100644 --- a/src/box/index.h +++ b/src/box/index.h @@ -203,6 +203,7 @@ enum dup_replace_mode { - (struct tuple *) min; - (struct tuple *) max; - (struct tuple *) findByKey: (const void *) key :(int) part_count; +- (struct tuple *) findByTuple: (struct tuple *) tuple; - (struct tuple *) replace: (struct tuple *) old_tuple :(struct tuple *) new_tuple :(enum dup_replace_mode) mode; diff --git a/src/box/index.m b/src/box/index.m index 87a83da9fb..c872c72e9f 100644 --- a/src/box/index.m +++ b/src/box/index.m @@ -182,6 +182,13 @@ replace_check_dup(struct tuple *old_tuple, return NULL; } +- (struct tuple *) findByTuple: (struct tuple *) pattern +{ + (void) pattern; + [self subclassResponsibility: _cmd]; + return NULL; +} + - (struct tuple *) replace: (struct tuple *) old_tuple : (struct tuple *) new_tuple : (enum dup_replace_mode) mode diff --git a/src/box/tree_index.m b/src/box/tree_index.m index 419f2bcf17..69b8ded312 100644 --- a/src/box/tree_index.m +++ b/src/box/tree_index.m @@ -944,6 +944,23 @@ tree_iterator_gt(struct iterator *iterator) return [self unfold: node]; } +- (struct tuple *) findByTuple: (struct tuple *) tuple +{ + assert(key_def->is_unique); + if (tuple->field_count < key_def->max_fieldno) + tnt_raise(IllegalParams, :"tuple must have all indexed fields"); + + struct key_data *key_data + = alloca(sizeof(struct key_data) + _SIZEOF_SPARSE_PARTS(tuple->field_count)); + + key_data->data = tuple->data; + key_data->part_count = tuple->field_count; + fold_with_sparse_parts(key_def, tuple, key_data->parts); + + void *node = sptree_index_find(&tree, key_data); + return [self unfold: node]; +} + - (struct tuple *) replace: (struct tuple *) old_tuple :(struct tuple *) new_tuple :(enum dup_replace_mode) mode -- GitLab