szaszm commented on code in PR #1367:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1367#discussion_r945896725


##########
libminifi/include/utils/Hash.h:
##########
@@ -0,0 +1,31 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <cstddef>
+
+namespace org::apache::nifi::minifi::utils {
+
+// boost::hash_combine

Review Comment:
   Please clarify that this is coming from the docs, not the sources. Copying 
the source would require appropriate LICENSE/NOTICE changes, while 
reimplementing what the docs document is a new work from a copyright 
perspective.



##########
libminifi/src/utils/TimeUtil.cpp:
##########
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/TimeUtil.h"
+
+namespace org::apache::nifi::minifi::utils::timeutils {
+
+static std::mutex global_clock_mtx;
+static std::shared_ptr<Clock> global_clock{std::make_shared<SteadyClock>()};
+
+std::shared_ptr<Clock> getClock() {
+  std::lock_guard lock(global_clock_mtx);
+  return global_clock;
+}
+
+// test-only utility to specify what clock to use
+void setClock(std::shared_ptr<Clock> clock) {
+  std::lock_guard lock(global_clock_mtx);
+  global_clock = std::move(clock);
+}

Review Comment:
   These globals can be avoided. Please use dependency injection.



##########
libminifi/include/utils/Hash.h:
##########
@@ -0,0 +1,31 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <cstddef>
+
+namespace org::apache::nifi::minifi::utils {
+
+// boost::hash_combine
+inline size_t hash_combine(size_t seed, size_t h) noexcept {
+  seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
+  return seed;
+}

Review Comment:
   If we want to follow the boost interface:
   ```suggestion
   inline void hash_combine(size_t& seed, size_t new_hash) noexcept {
     seed ^= new_hash + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
   }
   ```
   
   or simplify if not:
   ```suggestion
   inline size_t hash_combine(size_t seed, size_t new_hash) noexcept {
     return seed ^ new_hash + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
   }
   ```
   
   I changed the second parameter name in both suggestions to be more 
descriptive.
   
   I would go for the first version, but I'm fine with either one.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to