[geos-commits] [SCM] GEOS branch master updated. 891707f3348fd968c344b61b456546936976a8c8

git at osgeo.org git at osgeo.org
Wed Sep 26 12:19:52 PDT 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, master has been updated
       via  891707f3348fd968c344b61b456546936976a8c8 (commit)
       via  eecc2ce4ac33aaaffe64ff0034a7074ff53f7a60 (commit)
      from  1c51df2bce96fb801d4c75cfdd99d4ee34fa7aa8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 891707f3348fd968c344b61b456546936976a8c8
Author: Daniel Baston <dbaston at gmail.com>
Date:   Tue Sep 25 22:30:25 2018 -0400

    Remove empty file

diff --git a/src/Makefile.vc b/src/Makefile.vc
index 7fa376d..97152ca 100644
--- a/src/Makefile.vc
+++ b/src/Makefile.vc
@@ -143,7 +143,6 @@ OBJ = \
 	index\chain\MonotoneChainSelectAction.$(EXT) \
 	index\intervalrtree\IntervalRTreeBranchNode.$(EXT) \
 	index\intervalrtree\IntervalRTreeLeafNode.$(EXT) \
-	index\intervalrtree\IntervalRTreeNode.$(EXT) \
 	index\intervalrtree\SortedPackedIntervalRTree.$(EXT) \
 	index\quadtree\DoubleBits.$(EXT) \
 	index\quadtree\IntervalSize.$(EXT) \
diff --git a/src/index/intervalrtree/IntervalRTreeNode.cpp b/src/index/intervalrtree/IntervalRTreeNode.cpp
deleted file mode 100644
index c0560b1..0000000
--- a/src/index/intervalrtree/IntervalRTreeNode.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-/**********************************************************************
- *
- * GEOS - Geometry Engine Open Source
- * http://geos.osgeo.org
- *
- * Copyright (C) 2001-2002 Vivid Solutions Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU Lesser General Public Licence as published
- * by the Free Software Foundation.
- * See the COPYING file for more information.
- *
- **********************************************************************/
-
-#include <geos/index/intervalrtree/IntervalRTreeNode.h>
-
-
-namespace geos {
-namespace index {
-namespace intervalrtree {
-//
-// private:
-//
-
-//
-// protected:
-//
-
-//
-// public:
-//
-
-} // geos::intervalrtree
-} // geos::index
-} // geos
diff --git a/src/index/intervalrtree/Makefile.am b/src/index/intervalrtree/Makefile.am
index 7aeaf11..4437fbd 100644
--- a/src/index/intervalrtree/Makefile.am
+++ b/src/index/intervalrtree/Makefile.am
@@ -1,12 +1,11 @@
 #
-# This file is part of project GEOS (http://trac.osgeo.org/geos/) 
+# This file is part of project GEOS (http://trac.osgeo.org/geos/)
 #
 noinst_LTLIBRARIES = libintervalrtree.la
 
-AM_CPPFLAGS = -I$(top_srcdir)/include 
+AM_CPPFLAGS = -I$(top_srcdir)/include
 
 libintervalrtree_la_SOURCES = \
 	IntervalRTreeBranchNode.cpp \
 	IntervalRTreeLeafNode.cpp \
-	IntervalRTreeNode.cpp \
 	SortedPackedIntervalRTree.cpp

commit eecc2ce4ac33aaaffe64ff0034a7074ff53f7a60
Author: Daniel Baston <dbaston at gmail.com>
Date:   Tue Sep 18 14:03:24 2018 -0400

    Store SortedPackedIntervalRTree leaf and branch nodes in vectors
    
    This minimizes the number of individual memory allocations.

diff --git a/include/geos/index/intervalrtree/IntervalRTreeBranchNode.h b/include/geos/index/intervalrtree/IntervalRTreeBranchNode.h
index 97347aa..ef7677f 100644
--- a/include/geos/index/intervalrtree/IntervalRTreeBranchNode.h
+++ b/include/geos/index/intervalrtree/IntervalRTreeBranchNode.h
@@ -38,12 +38,6 @@ private:
 	const IntervalRTreeNode * node1;
 	const IntervalRTreeNode * node2;
 
-	//void buildExtent( IntervalRTreeNode * n1, IntervalRTreeNode * n2)
-	//{
-	//	min = std::min( n1->min, n2->min);
-	//	max = std::max( n1->max, n2->max);
-	//}
-
 protected:
 public:
 	IntervalRTreeBranchNode( const IntervalRTreeNode * n1, const IntervalRTreeNode * n2)
@@ -52,13 +46,6 @@ public:
 		node2( n2)
 	{ }
 
-	~IntervalRTreeBranchNode() override
-	{
-		delete node1;
-		delete node2;
-	}
-
-
 	void query(double queryMin, double queryMax, index::ItemVisitor * visitor) const override;
 };
 
diff --git a/include/geos/index/intervalrtree/IntervalRTreeNode.h b/include/geos/index/intervalrtree/IntervalRTreeNode.h
index 0d4870e..3f49615 100644
--- a/include/geos/index/intervalrtree/IntervalRTreeNode.h
+++ b/include/geos/index/intervalrtree/IntervalRTreeNode.h
@@ -86,15 +86,8 @@ public:
 	//public:
 		static bool compare( const IntervalRTreeNode * n1, const IntervalRTreeNode * n2)
 		{
-			//IntervalRTreeNode * n1 = dynamic_cast<IntervalRTreeNode *>( o1);
-			//IntervalRTreeNode * n2 = dynamic_cast<IntervalRTreeNode *>( o2);
-
-			double mid1 = (n1->getMin() + n1->getMax()) / 2;
-			double mid2 = (n2->getMin() + n2->getMax()) / 2;
-
-			//if (mid1 < mid2) return -1;
-			//if (mid1 > mid2) return 1;
-			//return 0;
+			double mid1 = n1->getMin() + n1->getMax();
+			double mid2 = n2->getMin() + n2->getMax();
 
 			return mid1 > mid2;
 		}
diff --git a/include/geos/index/intervalrtree/SortedPackedIntervalRTree.h b/include/geos/index/intervalrtree/SortedPackedIntervalRTree.h
index 6046aad..ea8b3f4 100644
--- a/include/geos/index/intervalrtree/SortedPackedIntervalRTree.h
+++ b/include/geos/index/intervalrtree/SortedPackedIntervalRTree.h
@@ -17,6 +17,8 @@
 #define GEOS_INDEX_INTERVALRTREE_SORTEDPACKEDINTERVALRTREE_H
 
 #include <geos/index/intervalrtree/IntervalRTreeNode.h>
+#include <geos/index/intervalrtree/IntervalRTreeBranchNode.h>
+#include <geos/index/intervalrtree/IntervalRTreeLeafNode.h>
 
 // forward declarations
 namespace geos {
@@ -49,19 +51,20 @@ namespace intervalrtree {
 class SortedPackedIntervalRTree
 {
 private:
-	IntervalRTreeNode::ConstVect * leaves;
-	const IntervalRTreeNode * root;
-	int level;
+	std::vector<IntervalRTreeLeafNode> leaves;
+	std::vector<IntervalRTreeBranchNode> branches;
+	const IntervalRTreeNode * root = nullptr;
+	int level = 0;
 
 	void init();
-	void buildLevel( IntervalRTreeNode::ConstVect * src, IntervalRTreeNode::ConstVect * dest);
+	void buildLevel( IntervalRTreeNode::ConstVect & src, IntervalRTreeNode::ConstVect & dest);
 	const IntervalRTreeNode * buildTree();
 
 protected:
 public:
-	SortedPackedIntervalRTree();
+	SortedPackedIntervalRTree() {}
 
-	~SortedPackedIntervalRTree();
+	SortedPackedIntervalRTree(std::size_t initialCapacity) { leaves.reserve(initialCapacity); }
 
 	/**
 	 * Adds an item to the index which is associated with the given interval
diff --git a/src/index/intervalrtree/SortedPackedIntervalRTree.cpp b/src/index/intervalrtree/SortedPackedIntervalRTree.cpp
index 7df33de..dedc661 100644
--- a/src/index/intervalrtree/SortedPackedIntervalRTree.cpp
+++ b/src/index/intervalrtree/SortedPackedIntervalRTree.cpp
@@ -42,54 +42,50 @@ SortedPackedIntervalRTree::init()
 const IntervalRTreeNode *
 SortedPackedIntervalRTree::buildTree()
 {
-	// sort the leaf nodes
-	std::sort( leaves->begin(), leaves->end(), IntervalRTreeNode::compare );
+	branches.reserve(leaves.size() - 1);
 
 	// now group nodes into blocks of two and build tree up recursively
-	IntervalRTreeNode::ConstVect * src = leaves;
-	IntervalRTreeNode::ConstVect * dest = new IntervalRTreeNode::ConstVect();
+	std::vector<const IntervalRTreeNode*> src{leaves.size()};
+	std::vector<const IntervalRTreeNode*> dest;
+	std::transform(leaves.begin(), leaves.end(), src.begin(), [](const IntervalRTreeLeafNode & n) { return &n; });
+
+	// sort the leaf nodes
+	std::sort( src.begin(), src.end(), IntervalRTreeNode::compare );
 
 	while (true)
 	{
-		buildLevel( src, dest);
+		buildLevel(src, dest);
 
-		if (dest->size() == 1)
+		if (dest.size() == 1)
 		{
-			const IntervalRTreeNode * r = (*dest)[ 0 ];
-			delete src;
-			delete dest;
-			//delete leaves; // don't need anymore
-			return r;
+		    return dest[0];
 		}
 
-		IntervalRTreeNode::ConstVect * temp = src;
-		src = dest;
-		dest = temp;
+		std::swap(src, dest);
 	}
 }
 
 void
-SortedPackedIntervalRTree::buildLevel( IntervalRTreeNode::ConstVect * src, IntervalRTreeNode::ConstVect * dest)
+SortedPackedIntervalRTree::buildLevel(IntervalRTreeNode::ConstVect & src, IntervalRTreeNode::ConstVect & dest)
 {
 	level++;
 
-	dest->clear();
+	dest.clear();
 
-	for (size_t i = 0, ni = src->size(); i < ni; i += 2)
+	for (size_t i = 0, ni = src.size(); i < ni; i += 2)
 	{
-		const IntervalRTreeNode * n1 = (*src)[ i ];
+		const IntervalRTreeNode * n1 = src[i];
 
 		if ( i + 1 < ni )
 		{
-			const IntervalRTreeNode * n2 = (*src)[ i + 1 ];
+			const IntervalRTreeNode * n2 = src[i + 1];
 
-			const IntervalRTreeNode * node = new IntervalRTreeBranchNode( n1, n2 );
-
-			dest->push_back( node);
+			branches.emplace_back(n1, n2);
+			dest.push_back(&branches.back());
 		}
 		else
 		{
-			dest->push_back( n1);
+			dest.push_back( n1);
 		}
 	}
 }
@@ -101,29 +97,6 @@ SortedPackedIntervalRTree::buildLevel( IntervalRTreeNode::ConstVect * src, Inter
 //
 // public:
 //
-SortedPackedIntervalRTree::SortedPackedIntervalRTree()
-	:
-	leaves( new IntervalRTreeNode::ConstVect()),
-	root( nullptr),
-	level( 0)
-{ }
-
-SortedPackedIntervalRTree::~SortedPackedIntervalRTree()
-{
-	if ( root != nullptr )
-	{
-		// deleting root cascades to all IntervalRTreeNode's
-		delete root;
-	}
-	else // possibly IntervalRTreeNode's in leaves to delete
-	{
-		for ( size_t i = 0, ni = leaves->size(); i < ni; i++ )
-			delete (*leaves)[i];
-
-		delete leaves;
-	}
-}
-
 
 void
 SortedPackedIntervalRTree::insert( double min, double max, void * item)
@@ -131,7 +104,7 @@ SortedPackedIntervalRTree::insert( double min, double max, void * item)
 	if (root != nullptr)
 		throw util::UnsupportedOperationException( "Index cannot be added to once it has been queried");
 
-	leaves->push_back( new IntervalRTreeLeafNode( min, max, item));
+	leaves.emplace_back(min, max, item);
 }
 
 void

-----------------------------------------------------------------------

Summary of changes:
 .../index/intervalrtree/IntervalRTreeBranchNode.h  | 13 -----
 .../geos/index/intervalrtree/IntervalRTreeNode.h   | 11 +---
 .../intervalrtree/SortedPackedIntervalRTree.h      | 15 +++--
 src/Makefile.vc                                    |  1 -
 src/index/intervalrtree/IntervalRTreeNode.cpp      | 35 -----------
 src/index/intervalrtree/Makefile.am                |  5 +-
 .../intervalrtree/SortedPackedIntervalRTree.cpp    | 67 +++++++---------------
 7 files changed, 33 insertions(+), 114 deletions(-)
 delete mode 100644 src/index/intervalrtree/IntervalRTreeNode.cpp


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list