From b69feb3e4f466d96d320ab34dfe18029a07b9c0b Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Tue, 18 Nov 2014 20:14:54 +0300 Subject: [PATCH] Review fixes (rtree-v4). --- src/lib/salad/bps_tree.h | 32 ++++++++++++++++++++++ src/lib/salad/mhash.h | 4 +++ src/lib/salad/rtree.c | 32 ++++++++++++---------- src/lib/salad/rtree.h | 25 ++++++++++------- test/{box => wal}/rtree_benchmark.result | 0 test/{box => wal}/rtree_benchmark.test.lua | 0 6 files changed, 69 insertions(+), 24 deletions(-) rename test/{box => wal}/rtree_benchmark.result (100%) rename test/{box => wal}/rtree_benchmark.test.lua (100%) diff --git a/src/lib/salad/bps_tree.h b/src/lib/salad/bps_tree.h index 29600dcf48..887de62bd1 100644 --- a/src/lib/salad/bps_tree.h +++ b/src/lib/salad/bps_tree.h @@ -1,3 +1,35 @@ +/* + * *No header guard*: the header is allowed to be included twice + * with different sets of defines. + */ +/* + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ #include <string.h> /* memmove, memset */ #include <stdint.h> #include <assert.h> diff --git a/src/lib/salad/mhash.h b/src/lib/salad/mhash.h index 1d8c080811..c04adfafa1 100644 --- a/src/lib/salad/mhash.h +++ b/src/lib/salad/mhash.h @@ -1,3 +1,7 @@ +/* + * *No header guard*: the header is allowed to be included twice + * with different sets of defines. + */ /* * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following diff --git a/src/lib/salad/rtree.c b/src/lib/salad/rtree.c index 113f8a96e8..1ad73cd886 100644 --- a/src/lib/salad/rtree.c +++ b/src/lib/salad/rtree.c @@ -26,7 +26,6 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - #include "rtree.h" #include <string.h> #include <assert.h> @@ -131,8 +130,10 @@ static area_t rtree_rect_area(const struct rtree_rect *rect) { area_t area = 1; - for (int i = RTREE_DIMENSION; --i >= 0; ) - area *= rect->upper_point.coords[i] - rect->lower_point.coords[i]; + for (int i = RTREE_DIMENSION; --i >= 0; ) { + area *= rect->upper_point.coords[i] - + rect->lower_point.coords[i]; + } return area; } @@ -160,7 +161,8 @@ rtree_max(coord_t a, coord_t b) } static struct rtree_rect -rtree_rect_cover(const struct rtree_rect *item1, const struct rtree_rect *item2) +rtree_rect_cover(const struct rtree_rect *item1, + const struct rtree_rect *item2) { struct rtree_rect res; for (int i = RTREE_DIMENSION; --i >= 0; ) { @@ -293,7 +295,7 @@ rtree_page_init_record(struct rtree_page *page, /* Create root page by branch */ static void rtree_page_init_branch(struct rtree_page *page, - const struct rtree_page_branch *br) + const struct rtree_page_branch *br) { page->n = 1; page->b[0] = *br; @@ -322,8 +324,9 @@ rtree_split_page(struct rtree *tree, struct rtree_page *page, rect_area[i + 1] = rtree_rect_area(&page->b[i].rect); /* - * As the seeds for the two groups, find two rectangles which waste - * the most area if covered by a single rectangle. + * As the seeds for the two groups, find two rectangles + * which waste the most area if covered by a single + * rectangle. */ int seed[2] = {-1, -1}; coord_t worst_waste = 0; @@ -417,8 +420,9 @@ rtree_split_page(struct rtree *tree, struct rtree_page *page, p->b[group_card[0] - 1] = page->b[chosen]; } /* - * If one group gets too full, then remaining rectangle are - * split between two groups in such way to balance CARDs of two groups. + * If one group gets too full, then remaining rectangle + * are split between two groups in such way to balance + * CARDs of two groups. */ if (group_card[0] + group_card[1] < RTREE_MAX_FILL + 1) { for (int i = 0; i < RTREE_MAX_FILL; i++) { @@ -459,7 +463,7 @@ rtree_page_remove_branch(struct rtree_page *page, int i) { page->n -= 1; memmove(page->b + i, page->b + i + 1, - (page->n - i) * sizeof(struct rtree_page_branch)); + (page->n - i) * sizeof(struct rtree_page_branch)); } static struct rtree_page * @@ -577,7 +581,7 @@ rtree_iterator_goto_first(struct rtree_iterator *itr, int sp, struct rtree_page* for (int i = 0, n = pg->n; i < n; i++) { if (itr->intr_cmp(&itr->rect, &pg->b[i].rect) && rtree_iterator_goto_first(itr, sp + 1, - pg->b[i].data.page)) + pg->b[i].data.page)) { itr->stack[sp].page = pg; itr->stack[sp].pos = i; @@ -640,7 +644,7 @@ rtree_iterator_reset(struct rtree_iterator *itr) } } -static struct rtree_neighbor* +static struct rtree_neighbor * rtree_iterator_allocate_neighbour(struct rtree_iterator *itr) { if (itr->page_pos >= RTREE_NEIGHBORS_IN_PAGE) { @@ -655,7 +659,7 @@ rtree_iterator_allocate_neighbour(struct rtree_iterator *itr) static struct rtree_neighbor * rtree_iterator_new_neighbor(struct rtree_iterator *itr, - void* child, sq_coord_t distance, int level) + void *child, sq_coord_t distance, int level) { struct rtree_neighbor *n = itr->neigh_free_list; if (n == NULL) @@ -724,7 +728,7 @@ rtree_iterator_next(struct rtree_iterator *itr) * current element * otherwise (R-Tree page) get siblings of this R-Tree * page and insert them in sorted list - */ + */ while (true) { struct rtree_neighbor *neighbor = itr->neigh_list; if (neighbor == NULL) diff --git a/src/lib/salad/rtree.h b/src/lib/salad/rtree.h index 61561198e5..6eb8a3eb1f 100644 --- a/src/lib/salad/rtree.h +++ b/src/lib/salad/rtree.h @@ -1,5 +1,5 @@ -#ifndef TARANTOOL_RTREE_H_INCLUDED -#define TARANTOOL_RTREE_H_INCLUDED +#ifndef INCLUDES_TARANTOOL_SALAD_RTREE_H +#define INCLUDES_TARANTOOL_SALAD_RTREE_H /* * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following @@ -28,10 +28,13 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - #include <stddef.h> #include <stdbool.h> +/** + * In-memory Guttman's R-tree + */ + /* Type of payload data */ typedef void *record_t; /* Type of coordinate */ @@ -46,12 +49,14 @@ extern "C" { #endif /* defined(__cplusplus) */ enum { - /* Number of dimensions of R-tree geometry */ + /** Number of dimensions of R-tree geometry */ RTREE_DIMENSION = 2, - /* Maximal possible R-tree height */ + /** Maximal possible R-tree height */ RTREE_MAX_HEIGHT = 16, - /* R-Tree use linear search within element on the page, - so larger page cause worse performance */ + /** + * R-Tree uses linear search for elements on a page, + * so a larger page size can hurt performance. + */ RTREE_PAGE_SIZE = 1024 }; @@ -68,8 +73,8 @@ enum spatial_search_op }; /* pointers to page allocation and deallocations functions */ -typedef void* (*rtree_page_alloc_t)(); -typedef void (*rtree_page_free_t)(void*); +typedef void *(*rtree_page_alloc_t)(); +typedef void (*rtree_page_free_t)(void *); /* A point in RTREE_DIMENSION space */ struct rtree_point @@ -197,4 +202,4 @@ rtree_iterator_next(struct rtree_iterator *itr); } #endif /* defined(__cplusplus) */ -#endif /* #ifndef TARANTOOL_RTREE_H_INCLUDED */ +#endif /* #ifndef INCLUDES_TARANTOOL_SALAD_RTREE_H */ diff --git a/test/box/rtree_benchmark.result b/test/wal/rtree_benchmark.result similarity index 100% rename from test/box/rtree_benchmark.result rename to test/wal/rtree_benchmark.result diff --git a/test/box/rtree_benchmark.test.lua b/test/wal/rtree_benchmark.test.lua similarity index 100% rename from test/box/rtree_benchmark.test.lua rename to test/wal/rtree_benchmark.test.lua -- GitLab