Name: Added function breadthFirstLess to use in sort, and function object BreadthFirstLess to use in map.
diff --git a/src/name.cpp b/src/name.cpp
index 5012ca2..68005e6 100644
--- a/src/name.cpp
+++ b/src/name.cpp
@@ -422,4 +422,21 @@
return result.str();
}
+bool
+Name::breadthFirstLess(const Name& name1, const Name& name2)
+{
+ for (size_t i = 0; i < name1.size() && i < name2.size(); ++i) {
+ if (name1[i] == name2[i])
+ // The components at this index are equal, so check the next components.
+ continue;
+
+ // Otherwise, the result is based on the components at this index.
+ return name1[i] < name2[i];
+ }
+
+ // The components up to min(name1.size(), name2.size()) are equal, so sort on the shorter name.
+ return name1.size() < name2.size();
+}
+
+
}