Kouhei Sutou
null+****@clear*****
Mon Dec 15 23:21:43 JST 2014
Kouhei Sutou 2014-12-15 23:21:43 +0900 (Mon, 15 Dec 2014) New Revision: f774110dae5a952342ec5a430f654aa9fe7e5ae3 https://github.com/groonga/groonga/commit/f774110dae5a952342ec5a430f654aa9fe7e5ae3 Message: Add grn_uvector_element_size() Added files: test/unit/core/test-uvector.c Modified files: include/groonga/groonga.h lib/db.c test/unit/core/Makefile.am Modified: include/groonga/groonga.h (+1 -0) =================================================================== --- include/groonga/groonga.h 2014-12-15 23:01:06 +0900 (e1bbbf9) +++ include/groonga/groonga.h 2014-12-15 23:21:43 +0900 (82c26f6) @@ -919,6 +919,7 @@ GRN_API unsigned int grn_vector_get_element(grn_ctx *ctx, grn_obj *vector, */ GRN_API unsigned int grn_uvector_size(grn_ctx *ctx, grn_obj *uvector); +GRN_API unsigned int grn_uvector_element_size(grn_ctx *ctx, grn_obj *uvector); GRN_API grn_rc grn_uvector_add_element(grn_ctx *ctx, grn_obj *vector, grn_id id, unsigned int weight); Modified: lib/db.c (+79 -0) =================================================================== --- lib/db.c 2014-12-15 23:01:06 +0900 (8bc008d) +++ lib/db.c 2014-12-15 23:21:43 +0900 (dabfbda) @@ -4097,6 +4097,61 @@ grn_vector_delimit(grn_ctx *ctx, grn_obj *vector) */ static unsigned int +grn_uvector_element_size_internal(grn_ctx *ctx, grn_obj *uvector) +{ + unsigned int element_size; + + if (IS_WEIGHT_UVECTOR(uvector)) { + element_size = sizeof(weight_uvector_entry); + } else { + switch (uvector->header.domain) { + case GRN_DB_BOOL : + element_size = sizeof(grn_bool); + break; + case GRN_DB_INT8 : + element_size = sizeof(int8_t); + break; + case GRN_DB_UINT8 : + element_size = sizeof(uint8_t); + break; + case GRN_DB_INT16 : + element_size = sizeof(int16_t); + break; + case GRN_DB_UINT16 : + element_size = sizeof(uint16_t); + break; + case GRN_DB_INT32 : + element_size = sizeof(int32_t); + break; + case GRN_DB_UINT32 : + element_size = sizeof(uint32_t); + break; + case GRN_DB_INT64 : + element_size = sizeof(int64_t); + break; + case GRN_DB_UINT64 : + element_size = sizeof(uint64_t); + break; + case GRN_DB_FLOAT : + element_size = sizeof(double); + break; + case GRN_DB_TIME : + element_size = sizeof(int64_t); + break; + case GRN_DB_TOKYO_GEO_POINT : + case GRN_DB_WGS84_GEO_POINT : + element_size = sizeof(grn_geo_point); + break; + default : + element_size = sizeof(grn_id); + break; + } + } + + return element_size; +} + +static unsigned int grn_uvector_size_internal(grn_ctx *ctx, grn_obj *uvector) { unsigned int size; @@ -4379,6 +4434,30 @@ grn_uvector_size(grn_ctx *ctx, grn_obj *uvector) GRN_API_RETURN(size); } +unsigned int +grn_uvector_element_size(grn_ctx *ctx, grn_obj *uvector) +{ + unsigned int element_size; + + if (!uvector) { + ERR(GRN_INVALID_ARGUMENT, "uvector must not be NULL"); + return 0; + } + + if (uvector->header.type != GRN_UVECTOR) { + grn_obj type_name; + GRN_TEXT_INIT(&type_name, 0); + grn_inspect_type(ctx, &type_name, uvector->header.type); + ERR(GRN_INVALID_ARGUMENT, "must be GRN_UVECTOR: %.*s", + (int)GRN_TEXT_LEN(&type_name), GRN_TEXT_VALUE(&type_name)); + GRN_OBJ_FIN(ctx, &type_name); + return 0; + } + + GRN_API_ENTER; + element_size = grn_uvector_element_size_internal(ctx, uvector); + GRN_API_RETURN(element_size); +} grn_rc grn_uvector_add_element(grn_ctx *ctx, grn_obj *uvector, Modified: test/unit/core/Makefile.am (+3 -1) =================================================================== --- test/unit/core/Makefile.am 2014-12-15 23:01:06 +0900 (0f1b89a) +++ test/unit/core/Makefile.am 2014-12-15 23:21:43 +0900 (1bd6e09) @@ -62,7 +62,8 @@ noinst_LTLIBRARIES = \ test-object.la \ test-rename.la \ test-tokenizer.la \ - test-proc.la + test-proc.la \ + test-uvector.la endif AM_CPPFLAGS = \ @@ -150,3 +151,4 @@ test_object_la_SOURCES = test-object.c test_rename_la_SOURCES = test-rename.c test_tokenizer_la_SOURCES = test-tokenizer.c test_proc_la_SOURCES = test-proc.c +test_uvector_la_SOURCES = test-uvector.c Added: test/unit/core/test-uvector.c (+151 -0) 100644 =================================================================== --- /dev/null +++ test/unit/core/test-uvector.c 2014-12-15 23:21:43 +0900 (cde9eb2) @@ -0,0 +1,151 @@ +/* -*- c-basic-offset: 2; coding: utf-8 -*- */ +/* + Copyright (C) 2014 Kouhei Sutou <kou �� clear-code.com> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include <gcutter.h> +#include <glib/gstdio.h> + +#include "../lib/grn-assertions.h" + +#include <groonga.h> + +void test_size_bool(void); +void test_size_int8(void); +void test_size_uint8(void); +void test_size_int16(void); +void test_size_uint16(void); +void test_size_int32(void); +void test_size_uint32(void); +void test_size_int64(void); +void test_size_uint64(void); +void test_size_float(void); +void test_size_time(void); +void test_size_tokyo_geo_point(void); +void test_size_wgs84_geo_point(void); + +static grn_ctx *context; +static grn_obj *uvector; + +void +cut_setup(void) +{ + context = g_new0(grn_ctx, 1); + grn_ctx_init(context, 0); + + uvector = g_new0(grn_obj, 1); +} + +void +cut_teardown(void) +{ + grn_obj_close(context, uvector); + g_free(uvector); + + grn_ctx_fin(context); + g_free(context); +} + +void +test_size_bool(void) +{ + GRN_BOOL_INIT(uvector, GRN_OBJ_VECTOR); + cut_assert_equal_uint(1, grn_uvector_element_size(context, uvector)); +} + +void +test_size_int8(void) +{ + GRN_INT8_INIT(uvector, GRN_OBJ_VECTOR); + cut_assert_equal_uint(1, grn_uvector_element_size(context, uvector)); +} + +void +test_size_uint8(void) +{ + GRN_UINT8_INIT(uvector, GRN_OBJ_VECTOR); + cut_assert_equal_uint(1, grn_uvector_element_size(context, uvector)); +} + +void +test_size_int16(void) +{ + GRN_INT16_INIT(uvector, GRN_OBJ_VECTOR); + cut_assert_equal_uint(2, grn_uvector_element_size(context, uvector)); +} + +void +test_size_uint16(void) +{ + GRN_UINT16_INIT(uvector, GRN_OBJ_VECTOR); + cut_assert_equal_uint(2, grn_uvector_element_size(context, uvector)); +} + +void +test_size_int32(void) +{ + GRN_INT32_INIT(uvector, GRN_OBJ_VECTOR); + cut_assert_equal_uint(4, grn_uvector_element_size(context, uvector)); +} + +void +test_size_uint32(void) +{ + GRN_UINT32_INIT(uvector, GRN_OBJ_VECTOR); + cut_assert_equal_uint(4, grn_uvector_element_size(context, uvector)); +} + +void +test_size_int64(void) +{ + GRN_INT64_INIT(uvector, GRN_OBJ_VECTOR); + cut_assert_equal_uint(8, grn_uvector_element_size(context, uvector)); +} + +void +test_size_uint64(void) +{ + GRN_UINT64_INIT(uvector, GRN_OBJ_VECTOR); + cut_assert_equal_uint(8, grn_uvector_element_size(context, uvector)); +} + +void +test_size_float(void) +{ + GRN_FLOAT_INIT(uvector, GRN_OBJ_VECTOR); + cut_assert_equal_uint(8, grn_uvector_element_size(context, uvector)); +} + +void +test_size_time(void) +{ + GRN_TIME_INIT(uvector, GRN_OBJ_VECTOR); + cut_assert_equal_uint(8, grn_uvector_element_size(context, uvector)); +} + +void +test_size_tokyo_geo_point(void) +{ + GRN_TOKYO_GEO_POINT_INIT(uvector, GRN_OBJ_VECTOR); + cut_assert_equal_uint(8, grn_uvector_element_size(context, uvector)); +} + +void +test_size_wgs84_geo_point(void) +{ + GRN_WGS84_GEO_POINT_INIT(uvector, GRN_OBJ_VECTOR); + cut_assert_equal_uint(8, grn_uvector_element_size(context, uvector)); +} -------------- next part -------------- HTML����������������������������... Descargar