Skip to content

v0.2.54..v0.2.55 changeset ElementComparer.h

Garret Voltz edited this page Aug 14, 2020 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/elements/ElementComparer.h b/hoot-core/src/main/cpp/hoot/core/elements/ElementComparer.h
index 30e5c32..693ee7f 100644
--- a/hoot-core/src/main/cpp/hoot/core/elements/ElementComparer.h
+++ b/hoot-core/src/main/cpp/hoot/core/elements/ElementComparer.h
@@ -35,9 +35,14 @@ namespace hoot
 {
 
 /**
- * Compares two elements of the same type for similarity
+ * This class compares two elements to determine if they are identical.
  *
- * Note that if element IDs are ignore, the comparison may be a little more expensive
+ * It can be configured to be ID agnostic. When element IDs are ignored, a map is required and
+ * way/relation comparisons could potentially be slower than when they are not ignored as each child
+ * element must be accessed.
+ *
+ * The node distance comparison tolerance threshold is controlled via the
+ * node.comparison.coordinate.sensitivity configuration option.
  */
 class ElementComparer : public OsmMapConsumer
 {
@@ -46,13 +51,13 @@ public:
 
   static const long DEBUG_ID = 0;
 
-  explicit ElementComparer(Meters threshold = 0.05);
+  ElementComparer();
 
   /**
    * Determines if two elements are the same
    *
-   * The only reason the inputs are const is b/c we auto update nodes with a hash if they don't
-   * already have one.
+   * The inputs aren't const b/c we auto update elements with a hash if they don't already have one
+   * in order to avoid computing the hash more than once.
    *
    * @param e1 the first element to compare
    * @param e2 the second element to compare
@@ -60,8 +65,6 @@ public:
    */
   bool isSame(ElementPtr e1, ElementPtr e2) const;
 
-  void setIgnoreElementId(bool ignore) { _ignoreElementId = ignore; }
-
   /**
    * @see OsmMapConsumer
    *
@@ -70,25 +73,30 @@ public:
    */
   virtual void setOsmMap(OsmMap* map) { _map = map->shared_from_this(); }
 
+  /**
+   * Wrapper around ElementHashVisitor::toHashString
+   */
+  QString toHashString(const ConstElementPtr& e) const;
+
+  void setIgnoreElementId(bool ignore) { _ignoreElementId = ignore; }
+  void setIgnoreVersion(bool ignore) { _ignoreVersion = ignore; }
+
 private:
 
-  //currently, this threshold applies only to non-node circular error checks and the var would
-  //eventually go away completely if all element types were converted over to uses hashes for
-  //comparisons
-  Meters _threshold;
-  // enabling this allows for element comparisons to ignore the element ID
+  // enabling this allows for element comparisons to ignore the element ID; requires a map, so
+  // default it to false to support callers that don't have a map
   bool _ignoreElementId;
+  // allows for ignoring element versions during comparison
+  bool _ignoreVersion;
   // a map is needed when comparing child elements if ignoring element IDs
   OsmMapPtr _map;
 
-  bool _compareNode(const std::shared_ptr<const Element>& re,
-                    const std::shared_ptr<const Element>& e) const;
-  bool _compareWay(const std::shared_ptr<const Element>& re,
-                   const std::shared_ptr<const Element>& e) const;
-  bool _compareRelation(const std::shared_ptr<const Element>& re,
-                        const std::shared_ptr<const Element>& e) const;
+  void _setHash(ElementPtr element) const;
+  bool _haveSameHash(ElementPtr re, ElementPtr e) const;
 
-  void _removeTagsNotImportantForComparison(Tags& tags) const;
+  bool _compareNode(ElementPtr re, ElementPtr e) const;
+  bool _compareWay(ElementPtr re, ElementPtr e) const;
+  bool _compareRelation(ElementPtr re, ElementPtr e) const;
 };
 
 }
Clone this wiki locally