[Groonga-commit] groonga/groonga at fba905e [master] Add grn_vector_get_element_#{numeric_type}

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Apr 2 17:57:07 JST 2018


Kouhei Sutou	2018-04-02 17:57:07 +0900 (Mon, 02 Apr 2018)

  New Revision: fba905ef5e646878ae0ec84230b41bfac2ae4a15
  https://github.com/groonga/groonga/commit/fba905ef5e646878ae0ec84230b41bfac2ae4a15

  Message:
    Add grn_vector_get_element_#{numeric_type}

  Added files:
    include/groonga/vector.h
    lib/vector.cpp
  Modified files:
    include/groonga.h
    include/groonga/groonga.h
    lib/cpp_sources.am

  Modified: include/groonga.h (+2 -1)
===================================================================
--- include/groonga.h    2018-04-02 15:22:56 +0900 (6e1be29d2)
+++ include/groonga.h    2018-04-02 17:57:07 +0900 (689010d75)
@@ -1,5 +1,5 @@
 /*
-  Copyright(C) 2014-2017 Brazil
+  Copyright(C) 2014-2018 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -51,3 +51,4 @@
 #include "groonga/window_function.h"
 #include "groonga/windows.h"
 #include "groonga/windows_event_logger.h"
+#include "groonga/vector.h"

  Modified: include/groonga/groonga.h (+2 -19)
===================================================================
--- include/groonga/groonga.h    2018-04-02 15:22:56 +0900 (24a449de3)
+++ include/groonga/groonga.h    2018-04-02 17:57:07 +0900 (26b443088)
@@ -837,24 +837,6 @@ GRN_API grn_rc grn_proc_set_is_stable(grn_ctx *ctx,
 GRN_API grn_bool grn_proc_is_stable(grn_ctx *ctx, grn_obj *proc);
 
 /*-------------------------------------------------------------
- * grn_vector
-*/
-
-GRN_API unsigned int grn_vector_size(grn_ctx *ctx, grn_obj *vector);
-
-GRN_API grn_rc grn_vector_add_element(grn_ctx *ctx, grn_obj *vector,
-                                      const char *str, unsigned int str_len,
-                                      unsigned int weight, grn_id domain);
-
-GRN_API unsigned int grn_vector_get_element(grn_ctx *ctx, grn_obj *vector,
-                                            unsigned int offset, const char **str,
-                                            unsigned int *weight, grn_id *domain);
-GRN_API unsigned int grn_vector_pop_element(grn_ctx *ctx, grn_obj *vector,
-                                            const char **str,
-                                            unsigned int *weight,
-                                            grn_id *domain);
-
-/*-------------------------------------------------------------
  * grn_uvector
 */
 
@@ -1610,7 +1592,8 @@ typedef enum {
   GRN_CHAR_HIRAGANA,
   GRN_CHAR_KATAKANA,
   GRN_CHAR_KANJI,
-  GRN_CHAR_OTHERS
+  GRN_CHAR_OTHERS,
+  GRN_CHAR_EMOJI
 } grn_char_type;
 
 GRN_API grn_obj *grn_string_open(grn_ctx *ctx,

  Added: include/groonga/vector.h (+76 -0) 100644
===================================================================
--- /dev/null
+++ include/groonga/vector.h    2018-04-02 17:57:07 +0900 (ec9a61455)
@@ -0,0 +1,76 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2009-2018 Brazil
+
+  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
+*/
+
+#pragma once
+
+#include <groonga.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+GRN_API unsigned int grn_vector_size(grn_ctx *ctx, grn_obj *vector);
+
+GRN_API grn_rc grn_vector_add_element(grn_ctx *ctx, grn_obj *vector,
+                                      const char *str, unsigned int str_len,
+                                      unsigned int weight, grn_id domain);
+
+GRN_API unsigned int grn_vector_get_element(grn_ctx *ctx, grn_obj *vector,
+                                            unsigned int offset, const char **str,
+                                            unsigned int *weight, grn_id *domain);
+GRN_API int8_t grn_vector_get_element_int8(grn_ctx *ctx,
+                                           grn_obj *vector,
+                                           unsigned int offset,
+                                           int8_t default_value);
+GRN_API uint8_t grn_vector_get_element_uint8(grn_ctx *ctx,
+                                             grn_obj *vector,
+                                             unsigned int offset,
+                                             uint8_t default_value);
+GRN_API int16_t grn_vector_get_element_int16(grn_ctx *ctx,
+                                             grn_obj *vector,
+                                             unsigned int offset,
+                                             int16_t default_value);
+GRN_API uint16_t grn_vector_get_element_uint16(grn_ctx *ctx,
+                                               grn_obj *vector,
+                                               unsigned int offset,
+                                               uint16_t default_value);
+GRN_API int32_t grn_vector_get_element_int32(grn_ctx *ctx,
+                                             grn_obj *vector,
+                                             unsigned int offset,
+                                             int32_t default_value);
+GRN_API uint32_t grn_vector_get_element_uint32(grn_ctx *ctx,
+                                               grn_obj *vector,
+                                               unsigned int offset,
+                                               uint32_t default_value);
+GRN_API int64_t grn_vector_get_element_int64(grn_ctx *ctx,
+                                             grn_obj *vector,
+                                             unsigned int offset,
+                                             int64_t default_value);
+GRN_API uint64_t grn_vector_get_element_uint64(grn_ctx *ctx,
+                                               grn_obj *vector,
+                                               unsigned int offset,
+                                               uint64_t default_value);
+
+GRN_API unsigned int grn_vector_pop_element(grn_ctx *ctx, grn_obj *vector,
+                                            const char **str,
+                                            unsigned int *weight,
+                                            grn_id *domain);
+
+#ifdef __cplusplus
+}
+#endif

  Modified: lib/cpp_sources.am (+2 -1)
===================================================================
--- lib/cpp_sources.am    2018-04-02 15:22:56 +0900 (c1d09a97a)
+++ lib/cpp_sources.am    2018-04-02 17:57:07 +0900 (963db602c)
@@ -1,3 +1,4 @@
 libgroonga_cpp_source =				\
 	arrow.cpp				\
-	dat.cpp
+	dat.cpp					\
+	vector.cpp

  Added: lib/vector.cpp (+153 -0) 100644
===================================================================
--- /dev/null
+++ lib/vector.cpp    2018-04-02 17:57:07 +0900 (fcf123813)
@@ -0,0 +1,153 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2018 Brazil
+
+  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 "grn.h"
+#include "grn_ctx.h"
+
+namespace grn {
+  template <typename NUMERIC>
+  NUMERIC
+  vector_get_element(grn_ctx *ctx,
+                     grn_obj *vector,
+                     unsigned int offset,
+                     NUMERIC default_value)
+  {
+    const char *raw_value = NULL;
+    grn_id domain;
+    unsigned int length;
+    NUMERIC value = default_value;
+
+    GRN_API_ENTER;
+
+    length = grn_vector_get_element(ctx,
+                                    vector,
+                                    offset,
+                                    &raw_value,
+                                    NULL,
+                                    &domain);
+    if (length > 0) {
+      switch (domain) {
+      case GRN_DB_INT8 :
+        value = *reinterpret_cast<const int8_t *>(raw_value);
+        break;
+      case GRN_DB_UINT8 :
+        value = *reinterpret_cast<const uint8_t *>(raw_value);
+        break;
+      case GRN_DB_INT16 :
+        value = *reinterpret_cast<const int16_t *>(raw_value);
+        break;
+      case GRN_DB_UINT16 :
+        value = *reinterpret_cast<const uint16_t *>(raw_value);
+        break;
+      case GRN_DB_INT32 :
+        value = *reinterpret_cast<const int32_t *>(raw_value);
+        break;
+      case GRN_DB_UINT32 :
+        value = *reinterpret_cast<const uint32_t *>(raw_value);
+        break;
+      case GRN_DB_INT64 :
+        value = *reinterpret_cast<const int64_t *>(raw_value);
+        break;
+      case GRN_DB_UINT64 :
+        value = *reinterpret_cast<const uint64_t *>(raw_value);
+        break;
+      case GRN_DB_FLOAT :
+        value = *reinterpret_cast<const double *>(raw_value);
+        break;
+      default :
+        break;
+      }
+    }
+
+    GRN_API_RETURN(value);
+  }
+}
+
+extern "C" {
+  int8_t
+  grn_vector_get_element_int8(grn_ctx *ctx,
+                              grn_obj *vector,
+                              unsigned int offset,
+                              int8_t default_value)
+  {
+    return grn::vector_get_element<int8_t>(ctx, vector, offset, default_value);
+  }
+
+  uint8_t
+  grn_vector_get_element_uint8(grn_ctx *ctx,
+                               grn_obj *vector,
+                               unsigned int offset,
+                               uint8_t default_value)
+  {
+    return grn::vector_get_element<uint8_t>(ctx, vector, offset, default_value);
+  }
+
+  int16_t
+  grn_vector_get_element_int16(grn_ctx *ctx,
+                               grn_obj *vector,
+                               unsigned int offset,
+                               int16_t default_value)
+  {
+    return grn::vector_get_element<int16_t>(ctx, vector, offset, default_value);
+  }
+
+  uint16_t
+  grn_vector_get_element_uint16(grn_ctx *ctx,
+                                grn_obj *vector,
+                                unsigned int offset,
+                                uint16_t default_value)
+  {
+    return grn::vector_get_element<uint16_t>(ctx, vector, offset, default_value);
+  }
+
+  int32_t
+  grn_vector_get_element_int32(grn_ctx *ctx,
+                               grn_obj *vector,
+                               unsigned int offset,
+                               int32_t default_value)
+  {
+    return grn::vector_get_element<int32_t>(ctx, vector, offset, default_value);
+  }
+
+  uint32_t
+  grn_vector_get_element_uint32(grn_ctx *ctx,
+                                grn_obj *vector,
+                                unsigned int offset,
+                                uint32_t default_value)
+  {
+    return grn::vector_get_element<uint32_t>(ctx, vector, offset, default_value);
+  }
+
+  int64_t
+  grn_vector_get_element_int64(grn_ctx *ctx,
+                               grn_obj *vector,
+                               unsigned int offset,
+                               int64_t default_value)
+  {
+    return grn::vector_get_element<int64_t>(ctx, vector, offset, default_value);
+  }
+
+  uint64_t
+  grn_vector_get_element_uint64(grn_ctx *ctx,
+                                grn_obj *vector,
+                                unsigned int offset,
+                                uint64_t default_value)
+  {
+    return grn::vector_get_element<uint64_t>(ctx, vector, offset, default_value);
+  }
+}
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180402/64414978/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index