From 8a7ac432c00b9e13a4503e3b12eb9882b4e69fa9 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Mon, 24 Apr 2017 09:26:35 +1000 Subject: [PATCH] ue2_literal: add hash_value() --- src/util/hash.h | 12 +++++++++++- src/util/ue2string.h | 10 +++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/util/hash.h b/src/util/hash.h index 0b571772..6f76e43d 100644 --- a/src/util/hash.h +++ b/src/util/hash.h @@ -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 #include 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 +size_t hash_range(const Range &r) { + return boost::hash_range(std::begin(r), std::end(r)); +} + } // namespace ue2 #endif // UTIL_HASH_H diff --git a/src/util/ue2string.h b/src/util/ue2string.h index 08b6a544..a90d47a3 100644 --- a/src/util/ue2string.h +++ b/src/util/ue2string.h @@ -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 #include @@ -206,6 +207,13 @@ private: std::vector 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);