]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
ue2_literal: add hash_value()
authorJustin Viiret <justin.viiret@intel.com>
Sun, 23 Apr 2017 23:26:35 +0000 (09:26 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 30 May 2017 03:58:59 +0000 (13:58 +1000)
src/util/hash.h
src/util/ue2string.h

index 0b571772985054c4c1e12ce1825dbfc84b6d358f..6f76e43de9f39506a7859b899f2d9120873b3ebd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Intel Corporation
+ * Copyright (c) 2016-2017, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -34,6 +34,7 @@
 #ifndef UTIL_HASH_H
 #define UTIL_HASH_H
 
+#include <iterator>
 #include <boost/functional/hash/hash_fwd.hpp>
 
 namespace ue2 {
@@ -69,6 +70,15 @@ size_t hash_all(Args&&... args) {
     return v;
 }
 
+/**
+ * \brief Compute the hash of all the elements of any range on which we can
+ * call std::begin() and std::end().
+ */
+template<typename Range>
+size_t hash_range(const Range &r) {
+    return boost::hash_range(std::begin(r), std::end(r));
+}
+
 } // namespace ue2
 
 #endif // UTIL_HASH_H
index 08b6a5442a68d25bb0259e9157c4ce25bbe57f2e..a90d47a3540905ab468893f6ac17da35c8ca7ea7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2016, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -35,6 +35,7 @@
 
 #include "ue2common.h"
 #include "util/charreach.h"
+#include "util/hash.h"
 
 #include <iterator>
 #include <string>
@@ -206,6 +207,13 @@ private:
     std::vector<bool> nocase; /* for trolling value */
 };
 
+inline
+size_t hash_value(const ue2_literal::elem &elem) {
+    return hash_all(elem.c, elem.nocase);
+}
+
+inline
+size_t hash_value(const ue2_literal &lit) { return hash_range(lit); }
 
 /// Return a reversed copy of this literal.
 ue2_literal reverse_literal(const ue2_literal &in);