[Groonga-commit] groonga/groonga at 7e092de [master] Add grn_geo_estimate_size_in_rectangle()

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Nov 9 14:23:03 JST 2014


Kouhei Sutou	2014-11-09 14:23:03 +0900 (Sun, 09 Nov 2014)

  New Revision: 7e092dedbb8d4a79a8e61213e62dc940944fdd86
  https://github.com/groonga/groonga/commit/7e092dedbb8d4a79a8e61213e62dc940944fdd86

  Message:
    Add grn_geo_estimate_size_in_rectangle()
    
    grn_geo_estimate_in_rectangle() is deprecated.
    
    grn_ii_estimate_size() has "_size" and
    grn_geo_estimate_size_in_rectangle() returns estimated "size". So we
    should add "_size" in function name.

  Modified files:
    include/groonga/groonga.h
    lib/geo.c
    test/unit/core/test-geo-in-rectangle.c
    test/unit/core/test-geo.c

  Modified: include/groonga/groonga.h (+5 -0)
===================================================================
--- include/groonga/groonga.h    2014-11-09 00:13:15 +0900 (8b958f7)
+++ include/groonga/groonga.h    2014-11-09 14:23:03 +0900 (613806f)
@@ -970,6 +970,11 @@ GRN_API grn_rc grn_geo_select_in_rectangle(grn_ctx *ctx,
                                            grn_obj *bottom_right_point,
                                            grn_obj *res,
                                            grn_operator op);
+GRN_API unsigned int grn_geo_estimate_size_in_rectangle(grn_ctx *ctx,
+                                                        grn_obj *index,
+                                                        grn_obj *top_left_point,
+                                                        grn_obj *bottom_right_point);
+/* Deprecated since 4.0.8. Use grn_geo_estimate_size_in_rectangle() instead. */
 GRN_API int grn_geo_estimate_in_rectangle(grn_ctx *ctx,
                                           grn_obj *index,
                                           grn_obj *top_left_point,

  Modified: lib/geo.c (+26 -10)
===================================================================
--- lib/geo.c    2014-11-09 00:13:15 +0900 (b830137)
+++ lib/geo.c    2014-11-09 14:23:03 +0900 (21b50c4)
@@ -1989,13 +1989,13 @@ exit:
   return rc;
 }
 
-int
-grn_geo_estimate_in_rectangle(grn_ctx *ctx,
-                              grn_obj *index,
-                              grn_obj *top_left_point,
-                              grn_obj *bottom_right_point)
+uint32_t
+grn_geo_estimate_size_in_rectangle(grn_ctx *ctx,
+                                   grn_obj *index,
+                                   grn_obj *top_left_point,
+                                   grn_obj *bottom_right_point)
 {
-  int n = 0;
+  uint32_t n = 0;
   int total_records;
   grn_rc rc;
   in_rectangle_data data;
@@ -2004,7 +2004,6 @@ grn_geo_estimate_in_rectangle(grn_ctx *ctx,
   GRN_VOID_INIT(&(data.bottom_right_point_buffer));
   if (in_rectangle_data_prepare(ctx, index, top_left_point, bottom_right_point,
                                 "grn_geo_estimate_in_rectangle()", &data)) {
-    n = -1;
     goto exit;
   }
 
@@ -2025,8 +2024,6 @@ grn_geo_estimate_in_rectangle(grn_ctx *ctx,
       if (rc == GRN_END_OF_DATA) {
         n = total_records;
         rc = GRN_SUCCESS;
-      } else {
-        n = -1;
       }
       goto exit;
     }
@@ -2052,7 +2049,7 @@ grn_geo_estimate_in_rectangle(grn_ctx *ctx,
                        (double)total_longitude_distance);
     }
     estimated_n_records = ceil(total_records * select_ratio);
-    n = (int)estimated_n_records;
+    n = (uint32_t)estimated_n_records;
   }
 
 exit :
@@ -2061,6 +2058,25 @@ exit :
   return n;
 }
 
+int
+grn_geo_estimate_in_rectangle(grn_ctx *ctx,
+                              grn_obj *index,
+                              grn_obj *top_left_point,
+                              grn_obj *bottom_right_point)
+{
+  uint32_t size;
+
+  size = grn_geo_estimate_size_in_rectangle(ctx,
+                                            index,
+                                            top_left_point,
+                                            bottom_right_point);
+  if (ctx->rc != GRN_SUCCESS) {
+    return -1;
+  }
+
+  return size;
+}
+
 grn_bool
 grn_geo_in_circle(grn_ctx *ctx, grn_obj *point, grn_obj *center,
                   grn_obj *radius_or_point,

  Modified: test/unit/core/test-geo-in-rectangle.c (+6 -6)
===================================================================
--- test/unit/core/test-geo-in-rectangle.c    2014-11-09 00:13:15 +0900 (4f8c222)
+++ test/unit/core/test-geo-in-rectangle.c    2014-11-09 14:23:03 +0900 (6fcdd1e)
@@ -330,11 +330,11 @@ test_cursor(gconstpointer data)
 }
 
 void
-test_estimate(void)
+test_estimate_size(void)
 {
-  cut_assert_equal_int(4,
-                       grn_geo_estimate_in_rectangle(context,
-                                                     location_index,
-                                                     sazare_wgs84,
-                                                     tokyo_wgs84));
+  cut_assert_equal_uint(4,
+                        grn_geo_estimate_size_in_rectangle(context,
+                                                           location_index,
+                                                           sazare_wgs84,
+                                                           tokyo_wgs84));
 }

  Modified: test/unit/core/test-geo.c (+6 -6)
===================================================================
--- test/unit/core/test-geo.c    2014-11-09 00:13:15 +0900 (c0ac4e3)
+++ test/unit/core/test-geo.c    2014-11-09 14:23:03 +0900 (0cf80a1)
@@ -299,7 +299,7 @@ test_distance_ellipsoid(void)
 }
 
 void
-test_estimate_in_rectangle(void)
+test_estimate_size_in_rectangle(void)
 {
   grn_obj *location_index;
 
@@ -307,9 +307,9 @@ test_estimate_in_rectangle(void)
   assert_send_command(cut_get_fixture_data_string("shops.grn", NULL));
 
   location_index = get("Locations.shop");
-  cut_assert_equal_int(4,
-                       grn_geo_estimate_in_rectangle(context,
-                                                     location_index,
-                                                     sazare_wgs84,
-                                                     tokyo_wgs84));
+  cut_assert_equal_uint(4,
+                        grn_geo_estimate_size_in_rectangle(context,
+                                                           location_index,
+                                                           sazare_wgs84,
+                                                           tokyo_wgs84));
 }
-------------- next part --------------
HTML����������������������������...
Download 



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