summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib
diff options
context:
space:
mode:
authorJacob Gilbert <mrjacobagilbert@gmail.com>2020-10-10 08:53:54 -0700
committerMarcus Müller <marcus@hostalia.de>2020-10-28 23:34:21 +0100
commit4905782b308d73b2cd84cb19f33492836c5284ab (patch)
treeca3ea1cebb9e321508079b4e3e5bc509b4c7f39f /gnuradio-runtime/lib
parent650c997bd75ac36b552bc3336011118fcb23302a (diff)
Replace custom undocumented string hashing algorithm with std::hash. The std implmentation is slightly faster and has been tested to have similar distribution with arbitrary input data
Diffstat (limited to 'gnuradio-runtime/lib')
-rw-r--r--gnuradio-runtime/lib/pmt/pmt.cc19
1 files changed, 2 insertions, 17 deletions
diff --git a/gnuradio-runtime/lib/pmt/pmt.cc b/gnuradio-runtime/lib/pmt/pmt.cc
index 102c8b0fa2..e3c7f36f28 100644
--- a/gnuradio-runtime/lib/pmt/pmt.cc
+++ b/gnuradio-runtime/lib/pmt/pmt.cc
@@ -18,6 +18,7 @@
#include <pmt/pmt_pool.h>
#include <stdio.h>
#include <string.h>
+#include <functional>
#include <vector>
namespace pmt {
@@ -150,27 +151,11 @@ static std::vector<pmt_t>* get_symbol_hash_table()
pmt_symbol::pmt_symbol(const std::string& name) : d_name(name) {}
-static unsigned int hash_string(const std::string& s)
-{
- unsigned int h = 0;
- unsigned int g = 0;
-
- for (std::string::const_iterator p = s.begin(); p != s.end(); ++p) {
- h = (h << 4) + (*p & 0xff);
- g = h & 0xf0000000;
- if (g) {
- h = h ^ (g >> 24);
- h = h ^ g;
- }
- }
- return h;
-}
-
bool is_symbol(const pmt_t& obj) { return obj->is_symbol(); }
pmt_t string_to_symbol(const std::string& name)
{
- unsigned hash = hash_string(name) % get_symbol_hash_table_size();
+ unsigned hash = std::hash<std::string>()(name) % get_symbol_hash_table_size();
// Does a symbol with this name already exist?
for (pmt_t sym = (*get_symbol_hash_table())[hash]; sym; sym = _symbol(sym)->next()) {